I am trying to use a cursor for the following block of code, but it is not compiling and giving error saying the following:
PL/SQL: SQL Statement ignored
PL/SQL: ORA-00947: not enough values
All the trxn table values are being fetched, Does anyone have faced similar error before? Any way this can be fixed or am I missing something?
I am trying to use a cursor for the following block of code, but it is not compiling and giving error saying the following:
PL/SQL: SQL Statement ignored
PL/SQL: ORA-00947: not enough values
All the trxn table values are being fetched, Does anyone have faced similar error before? Any way this can be fixed or am I missing something?
cursor bulk_select is
with trxn as (
select --+ materialize
-- Wire info
wt.id
,wt.fl
,wt.abc
,wt.xyz
from
wt_temp_t wt
where
<condition>
)
select a
,b
,c
from
(
select
w.aa
,w.bb
,w.cc
trxn w
where
<condition>
)included_trxn
-- Left joins in case the acct is null or external
left outer join table
acct a_cp,
cust c_cp
where
<condition>
type tab_bulk_select is table of bulk_select%rowtype;
cur_bulk_select tab_bulk_select;
BEGIN
EXECUTE IMMEDIATE 'truncate table AML_CAMBRS6_HUB_SPOKE_TMP';
commit;
open bulk_select;
LOOP
fetch bulk_select bulk collect into cur_bulk_select limit 50000;
FORALL i IN 1..cur_bulk_select.COUNT
insert /*+ append */ into AML_CAMBRS6_HUB_SPOKE_TMP (a,b,c)
values cur_bulk_select(i);
commit;
EXIT When bulk_select%NOTFOUND;
END LOOP;
CLOSE bulk_select;
Its because in trxn you are fetching only 2 values wt.fo_trxn_seq_id ,wt.pass_thru_fl.
But in select clause select w.aa ,w.bb, w.cc trxn w where <condition> you are using aa, bb, cc and also missing from in statement.
Related
I have to create an SQR that generates a list of EEIDs, if there were any changes to the Pension data in the past day. The SQR compiles and works perfectly when I hardcode in the table names.
However, when I tried using variables for the table names, I get a compile error
I've pasted the portion of SQR that I'm trying to fix
When I start using $tableName and $auditTableName as table variables, that's when I get the error and I'm not sure what is going wrong
Can anyone help?
Please and Thank You
!***************************
begin-procedure Process-Main
!***************************
let $tableName = 'PS_PENSION_PLAN'
let $auditTableName = 'PS_AUDIT_PENSION_PLN'
let $dummy-dyn-variable = ''
begin-SELECT DISTINCT
L.EMPLID
L.EMPL_RCD
do someProcName(&L.EMPLID, &L.EMPL_RCD)
FROM [$dummy-dyn-variable]
(
SELECT DISTINCT
PP.EMPLID,
PP.EMPL_RCD,
PP.EFFDT,
'1901-01-01 12:00:00' AS AUDIT_STAMP
FROM [$dummy-dyn-variable] [$tableName] PP
UNION
SELECT DISTINCT
A.EMPLID,
A.EMPL_RCD,
A.EFFDT,
A.AUDIT_STAMP
FROM [$dummy-dyn-variable] [$auditTableName] A
)L
WHERE DATEDIFF(DAY,CAST(L.AUDIT_STAMP AS DATE),SYSDATE) = 1
ORDER BY 1,2
end-SELECT
end-procedure
Edit:
does the UNION have anything to do with this?
I keep receiving is this error:
(SQR 5528) ODBC SQL dbdesc: SQLNumResultCols error 102 in cursor 1:
[Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near 'FROM'.
(SQR 5528) ODBC SQL dbdesc: SQLNumResultCols error 8180 in cursor 1:
[Microsoft][ODBC SQL Server Driver][SQL Server]Statement(s) could not be prepared.
Edit2:
Ok, initial problem solved with [$dummy-dyn-variable], which led to the next problem with the DO command. I've updated the code above with DO someProcName(param_a, param_b)
I am now getting an error saying:
(SQR 2002) DO arguments do not match procedure's
Weird part, if I remove the dynamic table variables and hardcode the table names in the FROM section, then it compiles properly without errors. This makes me believe that the error is not related to my someProcName (maybe?)
am I missing something here?
I want to move data from one table to a table.
I wrote one plsql code for this process.
Column sizes sometimes do not fit when I move data from table 'TABLE_1' to table 'TABLE_2'.
oracle is sending an error as follows.
I have identified one exception to get rid of this error.
but this exception is in a static state.
I want to make this exception part dynamic.
that is, if this error occurs in other columns, I want to automatically increase the size of the column in those columns.
the following is the plsql code I wrote.
for example, an oracle insert operation may give the same error in the 'explanation' column.
I want to modify the size of the 'explanation' column.
if this error occurs,
I want to perform these operations automatically for each column.
DECLARE
SAYAC INTEGER;
SAYAC_2 INTEGER;
extension_already_exists EXCEPTION;
PRAGMA EXCEPTION_INIT(extension_already_exists, -12899);
BEGIN
SAYAC:=0;
FOR XX IN (SELECT
FILE_NO,
NAME,
EV_ADRESI,
explanation
FROM TABLE_1
WHERE NOT EXISTS (SELECT *
FROM TABLE_2
WHERE TABLE_2.FILE_NO = TABLE_1.FILE_NO )
)LOOP
BEGIN
SAYAC:=SAYAC+1;
EXECUTE IMMEDIATE 'INSERT INTO
TABLE_2(
FILE_NO,
NAME,
EV_ADRESI,
explanation
)
VALUES
(
:A,
:B,
:C,
:D
) '
using XX.FILE_NO,XX.NAME,XX.EV_ADRESI,xx.explanation
;
IF MOD(SAYAC,1000)=0 THEN
COMMIT;
END IF;
EXCEPTION WHEN extension_already_exists THEN
dbms_output.put_line('seviye cok buyuk = '||sqlcode||' FILE_NO = '||XX.FILE_NO||','||xx.EV_ADRESI);--this error may occur in other columns
EXECUTE IMMEDIATE 'ALTER TABLE TABLE_2 MODIFY EV_ADRESI,explanation VARCHAR2(100)'; --forexample xx.explanation
NULL; --I want to make this place dynamic
end;
END LOOP;
COMMIT;
END;
ORA-12899: value too large for column "HOSPITAL"."table_2"."EV_ADRESI" (actual: 34, maximum: 20)
ORA-06512: at line 20
That won't work anyway. Even if you capture the error and enlarge the column, you'd miss the offending row as you should repeat the previous insert (which failed).
From my point of view, you should first match columns' datatpyes and then move data from here to there in a simple manner.
By the way, why did you use dynamic SQL for insert? There's nothing dynamic there.
I'm trying to insert multiple rows into an Oracle 11g table by running the following in Aqua Data Studio (version 15.0.11), using this:
BEGIN
FOR i IN 1..700 LOOP
INSERT INTO lims.stock_template (
stock_template_id,
name,
group_id,
version,
version_status,
workflow_id,
amount,
stock_type_id,
aliquot_template_id,
auto_authorise,
reorder_amount
)
VALUES (
lims.sq_stock_template.nextval,
lims.sq_stock_template.currval,
21,
1,
'A',
51881,
0,
103,
2362,
'F',
0
);
END LOOP;
END;
/
but I get the following error:
>[Error] Script lines: 30-30 ------------------------
ORA-00900: invalid SQL statement
Script line 30, statement line 1, column 0
If I run just the INSERT statement by itself, it works just fine, but I want to be able to insert multiple rows in one operation.
I'm sure that I've run something similar in the past, but I can't see what the problem is.
Any help much appreciated.
Thanks
In your example, you included a BEGIN and END clause, which turns this into a "Anonymous PL/SQL Block"
http://docstore.mik.ua/orelly/oracle/prog2/ch15_03.htm
Within a PL/SQL block you can't execute a SQL statement directly. You have to use only PL/SQL. See attached example.
Now you can create a stored procedure to execute your insert and use Script Object to Window As -> Execute or Execute Bind. See below screenshot.
In a stored procedure or a stored procedure within a package you can do whatever you like!
create or replace procedure testMe as
begin
FOR i IN 1..700 LOOP
INSERT INTO lims.stock_template (
stock_template_id,
name,
group_id,
version,
version_status,
workflow_id,
amount,
stock_type_id,
aliquot_template_id,
auto_authorise,
reorder_amount
)
VALUES (
lims.sq_stock_template.nextval,
lims.sq_stock_template.currval,
21,
1,
'A',
51881,
0,
103,
2362,
'F',
0
);
END LOOP;
end;
This is EXACTLY analogous to typing every line in at the SQL prompt form the word begin to the word end;.
What is more then likely tripping you up is the slash at the bottom. In the CLI sqlPlus the end of the line with the semicolon ( ; ) causes it to run the process, hence :
select 'A' from dual;
The semicolon tells it to execute.
IF on the other hand you type in the word begin then it shifts mode and will accept semicolons anywhere and just keep adding your strings to the buffer. ON A BLANK LINE the type the / and return and it will try and execute your code.
I think if you remove the slash it will execute quite nicely.
sales_heads will compile with no errors but when I try to compile sales_lines it comes up with 2 errors which are:
Error(3,1): PL/SQL: SQL Statement ignored
Error(3,111): PL/SQL: ORA-02289: sequence does not exist
could someone tell me where I am going wrong.
drop sequence nsale_seq;
CREATE SEQUENCE nsale_seq
START WITH 1000000000
INCREMENT BY 1
NOCACHE
NOCYCLE;
create or replace PROCEDURE sale_heads (staffID_new number, customerID_new number)
is begin
insert into SALE_HEAD (sale_num, sale_date, status, staff_id, customer_id) values (nsale_seq.NEXTVAL, sysdate, 'P', staffID_new, customerID_new);
end sale_heads;
/
create or replace PROCEDURE sales_lines (productCode_new number, quantity_new number, actualPrice_new number) is
begin
insert into SALE_LINE (actual_price, quantity, sale_num, product_code) values (actualPrice_new, quantity_new, nsale_seg.CURRVAL, productCode_new);
end sales_lines;
/
You have placed / this after your first procedure as well as after second procedure. / is used to show the end of the file or the statements to be executed!Hence, it's unable to find second procedure!!!
That's why your second procedure is getting ignored.
Please remove the / first slash after first procedure sale_heads.
I believe it'll work perfectly!
I'm beginner of pl/sql and I'm learning.
This is my table.
select * from s;
SLNO ENAME SAL
------ -------------------- ----------
1 Shiv 8000
2 Pankaj 9000
3 Prasath 10000
This is my procedure:
set serveroutput on
create or replace procedure p1(n number)
is wname varchar(20);
begin
select ename into wname from s where eid=n;
dbms_output.put_line('------');
dbms_output.put_line('employee name:='||wname);
dbms_output.put_line('------');
end;
I'm getting a warning:
Procedure created with compilation errors.
If I execute the above query. Can anyone please suggest where I'm going wrong please..
You can use the following command.
show errors procedure procedure_name;
to get the list of errors and check that.
There is no column named EID on your table S.
put parameter type IN.
Give procedure like create or replace procedure p1(n IN s.eid%TYPE)
It will work.
I think there's a typo in your program,
try
SET SETVEROUTPUT ON
all in capitals.