PRAGMA EXCEPTION_INIT (bulk_errors, -24381);
PRAGMA EXCEPTION_INIT (bulk_errors, -24381);
Can u plz explain me what is use of this statement if I declare like this. And also tell me use of the PRAGMA
In PL/SQL, sometimes it becomes necessary to raise a predefined Oracle error
as an exception. Depending on the error number, there are some predefined
EXCEPTIONs that can be raised. These EXCEPTIONs are defined in package
STANDARD and are globally available. Other errors do not have predefined
EXCEPTIONs declared. In order to associate a predefined error number to an
EXCEPTION, use the PRAGMA EXCEPTION_INIT. When using PRAGMA EXCEPTION_INIT,
remember that all Oracle error numbers with exception of 1403 and 100 are
negative.
Once the EXCEPTION has been aliased, the EXCEPTION can then be raised.
Similar Messages
-
How attend error in forms menu like pragma exception_init ?
hello,
I have problem with error in my menu. I created menu and I put code to my buttons in menu:for example execute_trigger('test');
I have some forms and if I am in another forms and call my button with execute_trigger('test');
I get error FRM-40700: No such trigger: test
Its ok because I have trigger in another block. But how to attend this error. I put pragma execption_init but not work
declare
text exception;
pragme exception_init(text,-40700);
begin
execute_trigger('test');
exception
when text then
message('its work');
end;
I create code like this in menu;
execute_trigger('test');
if form_failure then
message('its work');
end if;
end;
and this work but I get error FRM-40700: No such trigger: test and next message is 'its work'. How to turn off message from forms?? or like this message make like pragma...
regardsthanks for reply.
trigger exist but in another block.
I check system.message-level
thanks
I find another solution
I put procedure which verificate current_block and current_form and then call execute_trigger(). It's work
Edited by: user515960 on 2010-07-18 02:43 -
Priority of pragma exception_init..
Hi All,
Suppose I am using pragma exception_init for NO_DATA_FOUND error,
and the variable I am using is "test_excp" in my stored procedure, in the exception section if I am using both the user defined exception and the system defined exception (i.e. when test_excp then and when NO_DATA_FOUND then ) then which exception will the engine pick?
This is not a business requirement but its a doubt on my part.
Please help me understanding this concept..
Thanks in advance!!
BitsConfused yet?
Note that there is also a -100 no data found error in Oracle but it appears to be treated as an entirely separate exception (albeit with the same message), e.g.
Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
SQL> DECLARE
2 e_no_data_found EXCEPTION;
3 PRAGMA EXCEPTION_INIT (e_no_data_found, -100);
4 BEGIN
5 RAISE e_no_data_found;
6 EXCEPTION
7 WHEN NO_DATA_FOUND THEN
8 RAISE_APPLICATION_ERROR (-20000, 'encountered NO_DATA_FOUND exception.', TRUE);
9 WHEN e_no_data_found THEN
10 RAISE_APPLICATION_ERROR (-20000, 'encountered e_no_data_found exception.', TRUE);
11 END;
12 /
DECLARE
ERROR at line 1:
ORA-20000: encountered e_no_data_found exception.
ORA-06512: at line 10
ORA-00100: no data found
SQL> -
Pragma Exception_INIT- Doubt
Hi All
Why we are using Pragma Exception_INIT what is the purpose ?
Declare
e_MissingNull EXCEPTION;
PRAGMA EXCEPTION_INIT(e_MissingNull, -1400);
BEGIN
INSERT INTO Employees (employee_id) VALUES (NULL);
EXCEPTION
WHEN e_MissingNull then
DBMS_OUTPUT.put_line('ORA-1400 occurred');
END;when i give the above code i get
PL/SQL procedure successfully completed. ORA-1400 occurred
The same code when i try to give error message is ORA-1500 occurred
I get
ORA-01400: cannot insert NULL into ("XXI"."EMPLOYEES"."EMPLOYEE_ID")
ORA-06512: at line 6
why it happens?
And when i use try to get the error messgae to display Not valid instead of Zero_divide
Declare
I Number;
e_sample EXCEPTION;
PRAGMA EXCEPTION_INIT(e_sample, -5737);
BEGIN
select 1/0 Into I From Dual ; -- I know Zero_Divide Error i thought the changing this error in my style
EXCEPTION
WHEN e_smple then
DBMS_OUTPUT.put_line('ORA-5737 Not valid');
END;But the Result is
ORA-01476: divisor is equal to zero
Please let me know the purpose of and usage for Pragma Exception_INIT
Thank in advance
SureshYou must to issue:
SET SERVEROUTPUT ONto tell SQL*PLus to display DBMS_OUTPUT buffer:
SQL> Declare
2 e_MissingNull EXCEPTION;
3 PRAGMA EXCEPTION_INIT(e_MissingNull, -1400);
4 BEGIN
5 INSERT INTO Employees (employee_id) VALUES (NULL);
6 EXCEPTION
7 WHEN e_MissingNull then
8 DBMS_OUTPUT.put_line('ORA-1400 occurred');
9 END;
10 /
PL/SQL procedure successfully completed.
SQL> SET SERVEROUTPUT ON
SQL> Declare
2 e_MissingNull EXCEPTION;
3 PRAGMA EXCEPTION_INIT(e_MissingNull, -1400);
4 BEGIN
5 INSERT INTO Employees (employee_id) VALUES (NULL);
6 EXCEPTION
7 WHEN e_MissingNull then
8 DBMS_OUTPUT.put_line('ORA-1400 occurred');
9 END;
10 /
ORA-1400 occurred
PL/SQL procedure successfully completed.
SQL> Now about zero_divide. You are initializing exception e_sample with -5737, while zero_divide is -1476:
SQL> Declare
2 I Number;
3 e_sample EXCEPTION;
4 PRAGMA EXCEPTION_INIT(e_sample, -1476);
5 BEGIN
6 select 1/0 Into I From Dual ; -- I know Zero_Divide Error i thought the changing this error in my style
7 EXCEPTION
8 WHEN e_sample then
9 DBMS_OUTPUT.put_line('ORA-5737 Not valid');
10 END;
11 /
ORA-5737 Not valid
PL/SQL procedure successfully completed.
SQL> SY. -
HI,
I want log the ORA-00942 error through exception.
declare
v_no number;
v_error exception;
pragma exception_init(v_error,-942);
begin
select empno into v_no from notable;
exception
when v_error then
insert into log values('no table');
end;
when ever i execute the program ,instead of logging error in log table ..it is raising error that ' ORA-942 TABLE OR VIEW DOESN'T EXIST'. i want log this message in logtable instead of raising error
ThanksHi,
only a short addition/illustration to/of the idea provided by SY
-- Create Log-Table
drop table log;
Create table log ( msg varchar2(4000 char));
drop table notable;
-- P compiles without table "NOTABLE" because of the use of dynamic sql see
-- Solomon Yakobsons post above
create or replace
procedure p
as
v_no number;
v_stmt varchar2(2000) := 'select empno from notable';
v_error exception;
pragma exception_init(v_error,-942);
begin
EXECUTE IMMEDIATE v_stmt into v_no;
insert into log values('j = '|| (nvl(to_char(v_no), '<<NULL>>')));
exception
when v_error then
insert into log values('no table');
-- you somehow need the following commit to make the changes in the log-table permanent;
-- other way could be combining this method with autonomous transactions
commit;
when others then
insert into log values(substr(dbms_utility.format_error_stack,1,4000));
-- commit; /*????*/
end;
-- 1. table "NOTABLE" doesn't exist => "no table" in log-table
truncate table log;
exec p;
select * from log;
-- 2. table "NOTABLE" exists but is empty => "ORA-01403: no data found"
create table notable (empno Number);
truncate table log;
-- writes log-message "ORA-01403: no data found" into log-table
exec p;
select * from log;
-- 3. one row in "NOTABLE"; "all is well"; here "j = 1"
-- insert first row into notable
insert into notable (empno) values (1);
commit; -- not needed because of the following truncate
-- writes value of the selection into the log-table
truncate table log;
exec p;
select * from log;
-- 4. two rows in notable => "ORA-01422: exact fetch returns more than requested number of rows"
-- insert second row
insert into notable (empno) values (2);
commit;
truncate table log;
-- writes error
exec p;
select * from log;So the "COMMIT" in the exception-handler may cause some trouble, if you just write without commiting here,
a calling stored procedure might rollback your changes, which will be very misleading. The use of AUTONOMOUS TRANSACTIONS
could get complicated too, please be careful here.
See [url http://tkyte.blogspot.de/search?q=autonomous+transactions] Tom Kyte Blog about AUTONOMOUS TRANSACTIONS, EXCEPTION WHEN OTHERS, ... why and when autonomous transactions can help you and if you should rethink your strategy about not reraising the error. Your business logic is broken in this case, isn't it? So why carry on?
Regards
stratmo
PS: User Profile for 920033 Handle: 920033
Status Level: Newbie
Registered: Mar 10, 2012
Total Posts: 52
Total Questions: 20 (20 unresolved)
>
Uuuups, seems that there is some work to do for you;-) -
Srw package throwing PRAGMA exception_init(SPECIFY_PROTOCOL, -20002)
I've added srw.ADD_PARAMETER ( plRepParam, 'server_protocol', 'HTTP/1.1' ); to no avail. Any ideas?
Twas muppetry on my part, I had missed http:// from my gateway param setting.
-
ORA-06502: PL/SQL: numeric or value error: Bulk Bind: Truncated Bind
Hi
I am getting this run time error ORA-06502: PL/SQL: numeric or value error: Bulk Bind: Truncated Bind in my pl/sql . I tried evrything , changing datatypes ,etc but still this error is coming .What can be the cause , please help.
declare
svid xxpor_utility.p_svid@sppmig1%type;
p_sv_id xxpor_utility.p_svid@sppmig1%type;
tab xxpor_utility.xxpor_indextab@sppmig1;
svid1 xxpor_utility.p_svid@sppmig1%type;
p_sv_id1 xxpor_utility.p_svid@sppmig1%type;
tab1 xxpor_utility.xxpor_indextab@sppmig1;
svid2 xxpor_utility.p_svid@sppmig1%type;
p_sv_id2 xxpor_utility.p_svid@sppmig1%type;
tab2 xxpor_utility.xxpor_indextab@sppmig1;
svid3 xxpor_utility.p_svid@sppmig1%type;
p_sv_id3 xxpor_utility.p_svid@sppmig1%type;
tab3 xxpor_utility.xxpor_indextab@sppmig1;
v_index t2_error_table.id_value%type;
v_code t2_error_table.error_code%type;
p_error varchar2(600);
k number(20):=0;
v_msg varchar2(2000);
v_commit_count number(10);
v_at_gpid varchar2(512);
v_at_oper varchar2(512);
v_sch varchar2(512);
v_vat varchar2(512);
exp exception;
exp1 exception;
exp2 exception;
exp3 exception;
exp4 exception;
v_pay varchar2(512);
v_res varchar2(512);
v_digit varchar2(512);
v_agree varchar2(512);
v_driver_licence PERSON_HISTORY.drivers_licence%TYPE;
v_cus_gen1 number(10);
v_cus_gen2 number(10);
v_cus_gen3 number(10);
svid_sr number(10);
v_social PERSON_HISTORY.social_security_number%TYPE;
CURSOR person_cur (p_person_id person_history.person_id%TYPE)
IS
SELECT drivers_licence ,social_security_number
FROM PERSON_HISTORY@SPPMIG1
WHERE PERSON_ID=p_person_id --p2(p).person_id
AND EFFECTIVE_START_DATE = (SELECT MAX(EFFECTIVE_START_DATE)
FROM PERSON_HISTORY@sppmig1
WHERE PERSON_ID=p_person_id);--p2(p).person_id) ;
--p number(20):=1;
--j number(20);
cursor c1 is
select * from cus_node_his ;
type temp_c1 is table of customer_node_history%rowtype
index by binary_integer;
t2 temp_c1;
type temp_c2 is table of customer_node_history@slpmig1%rowtype
index by binary_integer;
p2 temp_c2;
/*cursor c2(p_id customer_query.customer_node_id%type) is
select general_1,general_2,general_3
from customer_query@sppmig1 c where c.customer_query_type_id=10003 and
c.customer_node_id(+) =p_id
and c.open_date = (select
max(open_date) from customer_query@sppmig1 where customer_node_id=p_id
and customer_query_type_id=10003 and c.customer_query_id =(select max(customer_query_id) from customer_query@sppmig1
where customer_node_id=p_id and customer_query_type_id=10003));*/
procedure do_bulk_insert is
bulk_errors EXCEPTION;
PRAGMA EXCEPTION_INIT(bulk_errors, -24381);
begin
forall j in 1..t2.count SAVE EXCEPTIONS
insert into aaa values t2(j);
commit;
--t2.delete;
k:=0;
v_msg:=sqlerrm;
EXCEPTION WHEN bulk_errors THEN
FOR L IN 1..SQL%bulk_exceptions.count
LOOP
v_index := SQL%bulk_exceptions(L).ERROR_INDEX;
v_code := sqlerrm(-1 * SQL%bulk_exceptions(L).ERROR_CODE);
--v_index := SQL%bulk_exceptions(j).ERROR_INDEX;
--v_code := sqlerrm(-1 * SQL%bulk_exceptions(j).ERROR_CODE);
INSERT INTO t2_error_table
VALUES('CUSTOMER_NODE_HISTORY',
'CUSTOMER_NODE_ID',
v_msg,
t2(v_index).customer_node_id,
null,
'DO_BULK_INSERT',
v_code
commit;
END LOOP;
end do_bulk_insert;
begin
select value into v_at_gpid from t2_system_parameter@sppmig1 where name='atlanta_group_id';
select value into v_commit_count from t2_system_parameter@sppmig1 where name='batch_size';
select value into v_sch from t2_system_parameter@sppmig1 where name='schedule_id';
select value into v_pay from t2_system_parameter@sppmig1 where name='payment_location_code';
select value into v_at_oper from t2_system_parameter@sppmig1 where name='atlanta_operator_id';
select value into v_digit from t2_system_parameter@sppmig1 where name='digits_to_be_screened';
select value into v_res from t2_system_parameter@sppmig1 where name='responsible_agent';
select value into v_vat from t2_system_parameter@sppmig1 where name='vat_rate';
select value into v_agree from t2_system_parameter@sppmig1 where name='bank_agreement_status';
xxpor_utility.xxpor_loadmemory@sppmig1('CUSTOMER_NODE_HISTORY','CUSTOMER_NODE_TYPE_ID',tab);
xxpor_utility.xxpor_loadmemory@sppmig1('CUSTOMER_NODE_HISTORY','CREDIT_RATING_CODE',tab2);
xxpor_utility.xxpor_loadmemory@sppmig1('CUSTOMER_NODE_HISTORY','PAYMENT_METHOD_CODE',tab3);
xxpor_utility.xxpor_loadmemory@sppmig1('CUSTOMER_NODE_HISTORY','CUSTOMER_NODE_STATUS_CODE',tab1);
open c1;
loop
fetch c1 bulk collect into p2 limit v_commit_count;
for p in 1..p2.count loop
k:=K+1;
begin
xxpor_utility.xxpor_getsvid@sppmig1(p2(p).CUSTOMER_NODE_TYPE_ID,tab,svid);
p_sv_id:=svid;
xxpor_utility.xxpor_getsvid@sppmig1(p2(p).CUSTOMER_NODE_STATUS_CODE,tab1,svid1);
p_sv_id1 :=svid1;
xxpor_utility.xxpor_getsvid@sppmig1(p2(p).CREDIT_RATING_CODE,tab2,svid2);
p_sv_id2:=svid2;
xxpor_utility.xxpor_getsvid@sppmig1(p2(p).PAYMENT_METHOD_CODE,tab3,svid3);
p_sv_id3:=svid3;
OPEN person_cur (p2(p).person_id);
FETCH person_cur INTO v_driver_licence, v_social;
CLOSE person_cur;
--select social_security_number into v_social from person_history@sppmig1 where
--PERSON_ID=p2(p).person_id AND EFFECTIVE_START_DATE = (SELECT MAX(EFFECTIVE_START_DATE) FROM
--PERSON_HISTORY@sppmig1 WHERE PERSON_ID=p2(p).person_id) ;
/*open c2(p2(p).customer_node_id);
fetch c2 into v_cus_gen1, v_cus_gen2, v_cus_gen3;
close c2;
xxpor_utility.get_status_code@sppmig1(v_cus_gen1,v_cus_gen2,v_cus_gen3,svid_sr);*/
svid_sr:=2600000;
t2(k).CUSTOMER_NODE_ID := p2(p).CUSTOMER_NODE_ID;
t2(k).LAST_MODIFIED := p2(p).LAST_MODIFIED;
t2(k).EFFECTIVE_START_DATE := p2(p).EFFECTIVE_START_DATE;
t2(k).EFFECTIVE_END_DATE := p2(p).EFFECTIVE_END_DATE;
t2(k).CUSTOMER_NODE_TYPE_ID := p_sv_id;
if p_sv_id is null then
raise exp1;
end if;
t2(k).PRIMARY_IDENTIFIER := p2(p).PRIMARY_IDENTIFIER;
t2(k).PRIMARY_IDENTIFIER2 := p2(p).PRIMARY_IDENTIFIER2;
t2(k).NODE_NAME := p2(p).NODE_NAME ;
t2(k).NODE_NAME_UPPERCASE := p2(p).NODE_NAME_UPPERCASE ;
t2(k).NODE_NAME_SOUNDEX := p2(p).NODE_NAME_SOUNDEX;
t2(k).ATLANTA_GROUP_ID := v_at_gpid ;
t2(k).ATLANTA_OPERATOR_ID := p2(p).ATLANTA_OPERATOR_ID;
t2(k).GL_CODE_ID := p2(p).GL_CODE_ID;
t2(k).PARENT_CUSTOMER_NODE_ID := p2(p).PARENT_CUSTOMER_NODE_ID ;
t2(k).HIERARCHY_LEVEL := p2(p).HIERARCHY_LEVEL ;
t2(k).ROOT_CUSTOMER_NODE_ID := p2(p).ROOT_CUSTOMER_NODE_ID ;
t2(k).CUSTOMER_NODE_STATUS_CODE := p_sv_id1 ;
if p_sv_id1 is null then
raise exp2;
end if;
t2(k).CREATED_DATE := p2(p).CREATED_DATE;
t2(k).ACTIVE_DATE := p2(p).ACTIVE_DATE ;
t2(k).PERSON_ID := p2(p).PERSON_ID ;
t2(k).PRIME_ACCOUNT_ID := p2(p).PRIME_ACCOUNT_ID;
t2(k).REPORT_LEVEL_CODE := p2(p).REPORT_LEVEL_CODE;
t2(k).POSTAL_ADDRESS_ID := p2(p).POSTAL_ADDRESS_ID;
t2(k).SITE_ADDRESS_ID := p2(p).SITE_ADDRESS_ID ;
t2(k).CURRENCY_ID := p2(p).CURRENCY_ID;
t2(k).SCHEDULE_ID := v_sch;
t2(k).BILLING_PRIORITY := p2(p).BILLING_PRIORITY ;
t2(k).BILLING_COMPLEXITY:= p2(p).BILLING_COMPLEXITY ;
t2(k).BILLING_CONFIGURATION_CODE := p2(p).BILLING_CONFIGURATION_CODE;
t2(k).SUPPRESS_IND_CODE := p2(p).SUPPRESS_IND_CODE ;
t2(k).SUPPRESS_BILL_CYCLE_COUNT := p2(p).SUPPRESS_BILL_CYCLE_COUNT;
t2(k).SUPPRESS_UNTIL_ISSUE_DATE := p2(p).SUPPRESS_UNTIL_ISSUE_DATE;
t2(k).TURNOVER := p2(p).TURNOVER;
t2(k).TURNOVER_CURRENCY_ID := p2(p).TURNOVER_CURRENCY_ID ;
t2(k).CREDIT_LIMIT := p2(p).CREDIT_LIMIT ;
t2(k).CREDIT_LIMIT_CURRENCY_ID := p2(p).CREDIT_LIMIT_CURRENCY_ID;
t2(k).EXPECTED_REVENUE := p2(p).EXPECTED_REVENUE ;
t2(k).EXPECTED_REVENUE_CURRENCY_ID := p2(p).EXPECTED_REVENUE_CURRENCY_ID ;
t2(k).CREDIT_RATING_CODE := p_sv_id2 ;
-- if p_sv_id2 is null then
--raise exp3;
-- end if;
t2(k).CREDIT_COMMENTS := p2(p).CREDIT_COMMENTS ;
t2(k).TAX_CLASS_CODE := 1 ;
t2(k).PAYMENT_METHOD_CODE := p_sv_id3;
--if p_sv_id3 is null then
--raise exp4;
--end if;
t2(k).PAYMENT_LOCATION_CODE := v_pay ;
t2(k).BANK_CODE := NULL;
t2(k).BRANCH_CODE := NULL ;
t2(k).BANK_ACCOUNT_NAME := p2(p).NODE_NAME ;
t2(k).BANK_ACCOUNT_NUMBER := '1000000';
t2(k).BANK_ACCOUNT_REF := v_agree;
t2(k).CARD_TYPE_CODE := p2(p).CARD_TYPE_CODE ;
t2(k).CARD_NUMBER := p2(p).CARD_NUMBER ;
t2(k).CARD_EXPIRY_DATE := NULL ;
t2(k).ASSIGNED_OPERATOR_ID := NULL ;
t2(k).SALES_CHANNEL_CODE := 0;
t2(k).COMPANY_NUMBER := NULL;
t2(k).INDUSTRY_CODE := NULL;
t2(k).REGION_CODE := NULL;
t2(k).GENERAL_1 := v_vat ;
t2(k).GENERAL_2 := svid_sr ;
if svid_sr is null then
raise exp;
end if;
t2(k).GENERAL_3 := v_social ;
t2(k).GENERAL_4 := v_driver_licence ;
t2(k).GENERAL_5 := v_vat;
t2(k).GENERAL_6 := v_res;
t2(k).GENERAL_7 := null||':'||null||':'||'1000000'||':'||null||':'||null||':'||null||':';
t2(k).GENERAL_8 := '2' ;
t2(k).GENERAL_9 := v_digit;
t2(k).GENERAL_10 := p2(p).CUSTOMER_NODE_ID;
exception when exp then
p_error:= sqlerrm;
insert into t2_error_table values ( 'CUSTOMER_NODE_HISTORY','CUSTOMER_NODE_ID',p_error,p2(p).customer_node_id
,null,null,null);
commit;
when exp1 then
p_error:= sqlerrm;
insert into t2_error_table values ( 'CUSTOMER_NODE_HISTORY','CUSTOMER_NODE_ID',p_error,p2(p).customer_node_id
,null,null,'customer_node_type_id is null');
commit;
when exp2 then
p_error:= sqlerrm;
insert into t2_error_table values ( 'CUSTOMER_NODE_HISTORY','CUSTOMER_NODE_ID',p_error,p2(p).customer_node_id
,null,null,'customer_node_status_code is null');
commit;
/*when exp3 then
p_error:= sqlerrm;
insert into t2_error_table values ( 'CUSTOMER_NODE_HISTORY','CUSTOMER_NODE_ID',p_error,p2(p).customer_node_id
,null,null,'credit_rating_code is null');
commit;
when exp4 then
p_error:= sqlerrm;
insert into t2_error_table values ( 'CUSTOMER_NODE_HISTORY','CUSTOMER_NODE_ID',p_error,p2(p).customer_node_id
,null,null,null);
commit;*/
when others then
p_error:= sqlerrm;
insert into t2_error_table values ( 'CUSTOMER_NODE_HISTORY','CUSTOMER_NODE_ID',p_error,p2(p).customer_node_id
,null,null,null);
commit;
end;
if mod(k,v_commit_count)=0 then
do_bulk_insert;
t2.delete;
end if;
end loop;
do_bulk_insert;
exit when c1%notfound;
end loop;
t2.delete;
exception when others then
p_error:= sqlerrm;
insert into t2_error_table values ( 'CUSTOMER_NODE_HISTORY','CUSTOMER_NODE_ID',p_error,null
,null,null,null);
commit;
RAISE;
end;
/Hi there,
Following is the description of the error, you are getting.
ORA-06502:VALUE_ERROR
An arithmetic, conversion, truncation, or size-constraint error occurs. For example, when your program selects a column value into a character variable, if the value is longer than the declared length of the variable, PL/SQL aborts the assignment and raises VALUE_ERROR. In procedural statements, VALUE_ERROR is raised if the conversion of a character string into a number fails. (In SQL statements, INVALID_NUMBER is raised.)
Hopefully this will help. -
Error Message in Bulk Exception.
Hi
When i use a normal Exception, the SQLERRM gives me the complete error along with the column name.
Ex :
ORA-01400: cannot insert NULL into ("BENCHMARK"."T6"."X")
But
When i Use Bulk_Exception, SQLERRM does not give me the complete error along with column name.
Ex:
ORA-01400: cannot insert NULL into ()
Is it that Bulk_exception error messages are less informative. These error messages, does not help me in finding out which column is violation the NOT NULL constraint and hence they actually make no sense.
Is there any way, through which i can get the complete error message as i get in the normal exception.
I am using 9i version.
Regards
NikhilI couldn't find exact solution to your problem, but one idea that came to mind, is resubmit statement with problematic rows (without using bulk processing) and save error messages.
SQL> declare
2 bulk_errors exception;
3 pragma exception_init ( bulk_errors, -24381 );
4
5 j number;
6
7 type numbers is table of number;
8 ids numbers;
9 begin
10 select case when mod(abs(dbms_random.random),3)=0 then null else 1 end id bulk collect into ids
11 from dual
12 connect by level < 10;
13
14 forall i in ids.first .. ids.last save exceptions
15 insert into test01 values ( ids(i) );
16 exception when bulk_errors then
17 for i in 1..sql%bulk_exceptions.count loop
18 j := sql%bulk_exceptions(i).error_index;
19 begin
20 insert into test01 values ( ids(j) );
21 exception when others then
22 dbms_output.put_line( 'Row #'||j||'. '||substr(sqlerrm,1,instr(sqlerrm,chr(10))-1) );
-- substr to get only the first line
23 end;
24 end loop;
25 end;
26 /
Row #1. ORA-01400: cannot insert NULL into ("SCOTT"."TEST01"."ID")
Row #3. ORA-01400: cannot insert NULL into ("SCOTT"."TEST01"."ID")
Row #6. ORA-01400: cannot insert NULL into ("SCOTT"."TEST01"."ID")
Row #7. ORA-01400: cannot insert NULL into ("SCOTT"."TEST01"."ID")
Row #8. ORA-01400: cannot insert NULL into ("SCOTT"."TEST01"."ID")
Row #9. ORA-01400: cannot insert NULL into ("SCOTT"."TEST01"."ID") -
How to handle multiple save exceptions (Bulk Collect)
Hi
How to handle Multiple Save exceptions? Is it possible to rollback to first deletion(of child table) took place in the procedure.
There are 3 tables
txn_header_interface(Grand Parent)
orders(parent)
order_items (Child)
One transaction can have one or multiple orders in it.
and one orders can have one or multiple order_items in it.
We need to delete the data from child table first then its parent and then from the grand parent table.if some error occurs anywhere I need to rollback to child record deletion. Since there is flag in child table which tells us when to delete data from database.
Is it possible to give name to Save exceptions?
e.g.
FORALL i IN ABC.FIRST..ABC.LAST SAVE EXCEPTIONS A
FORALL i IN abc.FIRST..ABC.LAST SAVE EXCEPTIONS B
if some error occurs then
ROLLBACK A; OR ROLLBACK B;
Please find the procedure attached
How to handle the errors with Save exception and rollback upto child table deletion.
CREATE OR REPLACE
PROCEDURE DELETE_CONFIRMED_DATA IS
TYPE TXN_HDR_INFC_ID IS TABLE OF TXN_HEADER_INTERFACE.ID%TYPE;
TXN_HDR_INFC_ID_ARRAY TXN_HDR_INFC_ID;
ERROR_COUNT NUMBER;
BULK_ERRORS EXCEPTION;
PRAGMA exception_init(bulk_errors, -24381);
BEGIN
SELECT THI.ID BULK COLLECT
INTO TXN_HDR_INFC_ID_ARRAY
FROM TXN_HEADER_INTERFACE THI,ORDERS OS,ORDER_ITEMS OI
WHERE THI.ID = OS.TXN_HDR_INFC_ID
AND OS.ID = OI.ORDERS_ID
AND OI.POSTING_ITEM_ID = VPI.ID
OI.DW_STATUS_FLAG =4 --data is moved to Datawarehouse
MINUS
(SELECT THI.ID FROM TXN_HEADER_INTERFACE THI,ORDERS OS,ORDER_ITEMS OI
WHERE THI.ID = OS.TXN_HDR_INFC_ID
AND OS.ID = OI.ORDERS_ID
OI.DW_STATUS_FLAG !=4);
IF SQL%NOTFOUND
THEN
EXIT;
END IF;
FORALL i IN TXN_HDR_INFC_ID_ARRAY.FIRST..TXN_HDR_INFC_ID_ARRAY.LAST SAVE
EXCEPTIONS
DELETE FROM ORDER_ITEMS OI
WHERE OI.ID IN (SELECT OI.ID FROM ORDER_ITEMS OI,ORDERS
OS,TXN_HEADER_INTERFACE THI
WHERE OS.ID = OI.ORDERS_ID
AND OS.TXN_HDR_INFC_ID = THI.ID
AND THI.ID = TXN_HDR_INFC_ID_ARRAY(i));
FORALL i IN TXN_HDR_INFC_ID_ARRAY.FIRST..TXN_HDR_INFC_ID_ARRAY.LAST SAVE
EXCEPTIONS
DELETE FROM ORDERS OS
WHERE OS.ID IN (SELECT OS.ID FROM ORDERS OS,TXN_HEADER_INTERFACE THI
WHERE OS.TXN_HDR_INFC_ID = THI.ID
AND THI.ID = TXN_HDR_INFC_ID_ARRAY(i));
FORALL i IN TXN_HDR_INFC_ID_ARRAY.FIRST..TXN_HDR_INFC_ID_ARRAY.LAST SAVE
EXCEPTIONS
DELETE FROM TXN_HEADER_INTERFACE THI
WHERE THI.ID = TXN_HDR_INFC_ID_ARRAY(i);
COMMIT;
DBMS_OUTPUT.PUT_LINE(TO_CHAR(SYSDATE, 'DD-MON-YY HH:MIPM')||':
DELETE_CONFIRMED_DATA: INFO:DELETION SUCCESSFUL');
EXCEPTION
WHEN OTHERS THEN
ERROR_COUNT := SQL%BULK_EXCEPTIONS.COUNT;
DBMS_OUTPUT.PUT_LINE(TO_CHAR(SYSDATE, 'DD-MON-YY HH:MIPM')||':
DELETE_CONFIRMED_DATA: ERROR:Number of errors is ' ||ERROR_COUNT);
FOR indx IN 1..ERROR_COUNT LOOP
DBMS_OUTPUT.PUT_LINE('Error ' || indx || 'occurred during
'||'iteration'||SQL%BULK_EXCEPTIONS(indx).ERROR_INDEX);
DBMS_OUTPUT.PUT_LINE('Error is '
||SQLERRM(-SQL%BULK_EXCEPTIONS(indx).ERROR_CODE));
END LOOP;
END DELETE_CONFIRMED_DATA;
Any suggestion would be of great help.
Thanks in advance
AnuIf you have one or two places in your code that need multiple exceptions, just do it with multiple catch statements. Unless you are trying to write the most compact Programming 101 homework program, inventing tricks to remove two lines of code is not good use of your time.
If you have multiple catches all over your code it could be a code smell. You may have too much stuff happening inside one try statement. It becomes hard to know what method call throws one of those exceptions, and you end up handling an exception from some else piece of code than what you intended. E.g. you mention NumberFormatException -- only process one user input inside that try/catch so it is easy to see what error message is given if that particular input is gunk. The next step of processing goes inside its own try/catch.
In my case, the ArrayIndexOutOfBoundsException and
NumberFormatException should be handled by the same way.Why?
I don't think I have ever seen an ArrayIndexOutOfBoundsException that didn't indicate a bug in the code. Instead of an AIOOBE perhaps there should be an if statement somewhere that prevents it, or the algorithm logic should prevent it automatically. -
TDE Issue with UPDATE/SELECT statement
We just implemented TDE on a table and now our import script is getting errors. The import script has not changed and has been running fine for over a year. The script failed right after applying TDE on the table.
Oracle 10g Release 2 on Solaris.
Here are the encrypted colums:
COLUMN_NAME ENCRYPTION_ALG SALT
PERSON_ID AES 192 bits key NO
PERSON_KEY AES 192 bits key NO
USERNAME AES 192 bits key NO
FIRST_NAME AES 192 bits key NO
MIDDLE_NAME AES 192 bits key NO
LAST_NAME AES 192 bits key NO
NICKNAME AES 192 bits key NO
EMAIL_ADDRESS AES 192 bits key NO
AKO_EMAIL AES 192 bits key NO
CREATION_DATE AES 192 bits key NO
Here is the UPDATE/SELECT statement that is failing:
UPDATE cslmo_framework.users a
SET ( person_id
, username
, first_name
, middle_name
, last_name
, suffix
, user_status_seq
= (
SELECT person_id
, username
, first_name
, middle_name
, last_name
, suffix
, user_status_seq
FROM cslmo.vw_import_employee i
WHERE i.person_key = a.person_key
WHERE EXISTS
SELECT 1
FROM cslmo.vw_import_employee i
WHERE i.person_key = a.person_key
AND ( NVL(a.person_id,0) <> NVL(i.person_id,0)
OR NVL(a.username,' ') <> NVL(i.username,' ')
OR NVL(a.first_name,' ') <> NVL(i.first_name,' ')
OR NVL(a.middle_name,' ') <> NVL(i.middle_name,' ')
OR NVL(a.last_name,' ') <> NVL(i.last_name,' ')
OR NVL(a.suffix,' ') <> NVL(i.suffix,' ')
OR NVL(a.user_status_seq,99) <> NVL(i.user_status_seq,99)
cslmo@awpswebj-dev> exec cslmo.pkg_acpers_import.p_users
Error importing USERS table.START p_users UPDATE
Error Message: ORA-01483: invalid length for DATE or NUMBER bind variableI rewrote the procedure using BULK COLLECT and a FORALL statement and that seems to work fine. Here is the new code:
declare
bulk_errors EXCEPTION ;
PRAGMA EXCEPTION_INIT(bulk_errors,-24381) ;
l_idx NUMBER ;
l_err_msg VARCHAR2(2000) ;
l_err_code NUMBER ;
l_update NUMBER := 0 ;
l_count NUMBER := 0 ;
TYPE person_key_tt
IS
TABLE OF cslmo_framework.users.person_key%TYPE
INDEX BY BINARY_INTEGER ;
arr_person_key person_key_tt ;
TYPE person_id_tt
IS
TABLE OF cslmo_framework.users.person_id%TYPE
INDEX BY BINARY_INTEGER ;
arr_person_id person_id_tt ;
TYPE username_tt
IS
TABLE OF cslmo_framework.users.username%TYPE
INDEX BY BINARY_INTEGER ;
arr_username username_tt ;
TYPE first_name_tt
IS
TABLE OF cslmo_framework.users.first_name%TYPE
INDEX BY BINARY_INTEGER ;
arr_first_name first_name_tt ;
TYPE middle_name_tt
IS
TABLE OF cslmo_framework.users.middle_name%TYPE
INDEX BY BINARY_INTEGER ;
arr_middle_name middle_name_tt ;
TYPE last_name_tt
IS
TABLE OF cslmo_framework.users.last_name%TYPE
INDEX BY BINARY_INTEGER ;
arr_last_name last_name_tt ;
TYPE suffix_tt
IS
TABLE OF cslmo_framework.users.suffix%TYPE
INDEX BY BINARY_INTEGER ;
arr_suffix suffix_tt ;
TYPE user_status_seq_tt
IS
TABLE OF cslmo_framework.users.user_status_seq%TYPE
INDEX BY BINARY_INTEGER ;
arr_user_status_seq user_status_seq_tt ;
CURSOR users_upd IS
SELECT i.person_key
,i.person_id
,i.username
,i.first_name
,i.middle_name
,i.last_name
,i.suffix
,i.user_status_seq
FROM cslmo.vw_import_employee i ,
cslmo_framework.users u
WHERE i.person_key = u.person_key ;
begin
OPEN users_upd ;
LOOP
FETCH users_upd
BULK
COLLECT
INTO arr_person_key
, arr_person_id
, arr_username
, arr_first_name
, arr_middle_name
, arr_last_name
, arr_suffix
, arr_user_status_seq
LIMIT 100 ;
FORALL idx IN 1 .. arr_person_key.COUNT
SAVE EXCEPTIONS
UPDATE cslmo_framework.users u
SET
person_id = arr_person_id(idx)
, username = arr_username(idx)
, first_name = arr_first_name(idx)
, middle_name = arr_middle_name(idx)
, last_name = arr_last_name(idx)
, suffix = arr_suffix(idx)
, user_status_seq = arr_user_status_seq(idx)
WHERE u.person_key = arr_person_key(idx)
AND
( NVL(u.person_id,0) != NVL(arr_person_id(idx),0)
OR
NVL(u.username,' ') != NVL(arr_username(idx),' ')
OR
NVL(u.first_name,' ') != NVL(arr_first_name(idx),' ')
OR
NVL(u.middle_name, ' ') != NVL(arr_middle_name(idx), ' ')
OR
NVL(u.last_name,' ') != NVL(arr_last_name(idx),' ')
OR
NVL(u.suffix,' ') != NVL(arr_suffix(idx),' ')
OR
NVL(u.user_status_seq,99) != NVL(arr_user_status_seq(idx),99)
l_count := arr_person_key.COUNT ;
l_update := l_update + l_count ;
EXIT WHEN users_upd%NOTFOUND ;
END LOOP ;
CLOSE users_upd ;
COMMIT ;
dbms_output.put_line('updated records: ' || l_update);
EXCEPTION
WHEN bulk_errors THEN
FOR i IN 1 .. sql%BULK_EXCEPTIONS.COUNT
LOOP
l_err_code := sql%BULK_EXCEPTIONS(i).error_code ;
l_err_msg := sqlerrm(-l_err_code) ;
l_idx := sql%BULK_EXCEPTIONS(i).error_index;
dbms_output.put_line('error code: ' || l_err_code);
dbms_output.put_line('error msg: ' || l_err_msg);
dbms_output.put_line('at index: ' || l_idx);
END LOOP ;
ROLLBACK;
RAISE;
end ;
cslmo@awpswebj-dev> @cslmo_users_update
updated records: 1274There are about 20 or so other procedure in the import script. I don't want to rewrite them.
Does anyone know why the UPDATE/SELECT is failing? I checked Metalink and could not find anything about this problem.This is now an Oracle bug, #9182070 on Metalink.
TDE (transparent data encryption) does not work when an update/select statement references a remote database. -
PLS-00801: internal error with FORALL
I have the following procedure that I am trying to compile but I am getting an error:
<pre>
PROCEDURE procedure_1 AS
cursor cur_1 is
select column1 || column2 || column3 || column4 || column5 ||
column6 || column7 || column8 as concat_column
from table_1
for update wait 5;
type type_table_1 is table of varchar2(100);
tab_1 type_table_1;
bulk_error EXCEPTION;
PRAGMA EXCEPTION_INIT(bulk_error, -24381);
BEGIN
open cur_1;
loop
fetch cur_1 bulk collect into tab_1 limit 100;
exit when tab_1.COUNT = 0;
forall ctr in 1 .. tab_1.COUNT save exceptions
update table_1
set column_20 = array_line(tab_1(ctr).concat_column);
end loop;
close cur_1;
EXCEPTION
when bulk_error then
for i in 1 .. sql%bulk_exceptions.count loop
NULL;
end loop;
END procedure_1;
Error(622,21): PLS-00801: internal error [*** ASSERT at file pdw4.c, line 3572; Can't handle Object = -2147476152 in D_S_ED -2147476153.;
The offending line seems to be the update statement inside the forall loop. I cannot tell why I am getting this error though as everything seems ok to me.
Please help.
ThanksAnd what are you trying to do? You are updating column20 in all rows in table_1 over and over. And what is array_line? Type type_table_1 is not a table of objects, so what is tab_1(ctr).concat_column? Without questioning code logic (although I already did :) ), remove that ".concat_column":
set column_20 = array_line(tab_1(ctr));SY. -
Hello Gurus,
I have a problem with the Save Exceptions. I am using database 11g.
When I am doing bulk insert I would like to insert the error records into a new table. But when I am inserting
the error records I am getting the error "error:- ORA-00984: column not allowed here
ORA-24381: error(s) in array DML".
I am putting my code below.
DECLARE
CURSOR C_FRT2STORE IS
SELECT ROWID,
STORE_CD,
MNR_CD,
'FRT',
DT,
TO_DATE('31-DEC-2049'),
FRT_FAC,
TRUNC(SYSDATE),
'ADMINUSR'
FROM FRT2STORE;
CURSOR C_FRT2STORE_EXC_TAB IS
SELECT 'Y'
FROM ALL_TABLES
WHERE TABLE_NAME = 'FRT2STORE_EXC';
TYPE STORE$MNR2CST_REC_TYPE IS RECORD
(C_STORE$MNR2CST_ROWID VARCHAR2(100),
C_STORE_CD STORE$MNR2CST.STORE_CD%TYPE,
C_MNR_CD STORE$MNR2CST.MNR_CD%TYPE,
C_CST_CD STORE$MNR2CST.CST_CD%TYPE,
C_BEG_DT STORE$MNR2CST.BEG_DT%TYPE,
C_END_DT STORE$MNR2CST.END_DT%TYPE,
C_FAC NUMBER(13,3), --STORE$MNR2CST.FAC%TYPE,
C_AMT STORE$MNR2CST.AMT%TYPE,
C_CUBIC_AMT STORE$MNR2CST.CUBIC_AMT%TYPE,
C_LST_ACTN_DT STORE$MNR2CST.LST_ACTN_DT%TYPE,
C_EMP_CD STORE$MNR2CST.EMP_CD%TYPE
TYPE STORE$MNR2CST_TYPE IS TABLE OF STORE$MNR2CST_REC_TYPE
INDEX BY PLS_INTEGER;
STORE$MNR2CST_COL STORE$MNR2CST_TYPE;
V_TOT_REC PLS_INTEGER := 0;
V_FRT2STORE_EXC_TAB CHAR(1);
V_TOT_REC_IN_STORE$MNR2CST PLS_INTEGER;
V_ERR_REC PLS_INTEGER;
BULK_ERRORS EXCEPTION;
PRAGMA EXCEPTION_INIT (BULK_ERRORS, -24381);
BEGIN
--GETTING DATA FROM FRT2STORE TABLE AND INSERTING INTO THE STORE$MNR2CST TABLE
SELECT COUNT(1)
INTO V_TOT_REC_IN_STORE$MNR2CST
FROM STORE$MNR2CST ;
IF V_TOT_REC_IN_STORE$MNR2CST = 0 THEN
OPEN C_FRT2STORE;
LOOP
FETCH C_FRT2STORE BULK COLLECT INTO STORE$MNR2CST_COL LIMIT 1000;
EXIT WHEN STORE$MNR2CST_COL.COUNT = 0;
V_TOT_REC := STORE$MNR2CST_COL.COUNT;
IF V_TOT_REC > 0 THEN
BEGIN
FORALL I IN STORE$MNR2CST_COL.FIRST..STORE$MNR2CST_COL.LAST SAVE EXCEPTIONS
INSERT INTO STORE$MNR2CST
(STORE_CD,
MNR_CD,
CST_CD,
BEG_DT,
END_DT,
FAC,
AMT,
CUBIC_AMT,
LST_ACTN_DT,
EMP_CD
VALUES
(STORE$MNR2CST_COL(I).C_STORE_CD,
STORE$MNR2CST_COL(I).C_MNR_CD,
STORE$MNR2CST_COL(I).C_CST_CD,
STORE$MNR2CST_COL(I).C_BEG_DT,
STORE$MNR2CST_COL(I).C_END_DT,
STORE$MNR2CST_COL(I).C_FAC,
STORE$MNR2CST_COL(I).C_AMT,
STORE$MNR2CST_COL(I).C_CUBIC_AMT,
STORE$MNR2CST_COL(I).C_LST_ACTN_DT,
STORE$MNR2CST_COL(I).C_EMP_CD
COMMIT;
EXCEPTION WHEN BULK_ERRORS THEN
OPEN C_FRT2STORE_EXC_TAB;
FETCH C_FRT2STORE_EXC_TAB INTO V_FRT2STORE_EXC_TAB;
IF C_FRT2STORE_EXC_TAB%NOTFOUND THEN
EXECUTE IMMEDIATE ('CREATE TABLE FRT2STORE_EXC AS SELECT * FROM FRT2STORE WHERE 1 = 2');
END IF;
CLOSE C_FRT2STORE_EXC_TAB;
FOR J IN 1..SQL%BULK_EXCEPTIONS.COUNT
LOOP
V_ERR_REC := SQL%BULK_EXCEPTIONS(J).ERROR_INDEX;
EXECUTE IMMEDIATE 'INSERT INTO FRT2STORE_EXC (STORE_CD,MNR_CD,FRT_FAC,DT) VALUES ('
||STORE$MNR2CST_COL(V_ERR_REC).C_STORE_CD||','
||STORE$MNR2CST_COL(V_ERR_REC).C_MNR_CD||','
||STORE$MNR2CST_COL(V_ERR_REC).C_FAC||','
||STORE$MNR2CST_COL(V_ERR_REC).C_BEG_DT||')';
END LOOP;
COMMIT;
END;
STORE$MNR2CST_COL.DELETE;
END IF;
END LOOP;
CLOSE C_FRT2STORE;
END IF;
COMMIT;
EXCEPTION WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('error:- '||SQLERRM);
END ;
Could any one tell me how to achive this requirment.
Thanks,
Sun1. Please format your code using the code tags.
2. You should never need to code create tables like this "EXECUTE IMMEDIATE ('CREATE TABLE FRT2STORE....". This is often seen when creating temporary tables in non-Oracle database but is a misunderstanding in how to do things in Oracle. You should create them outside of your plsql as permanent objects.
3. In your example, you should not need dynamic sql like this "EXECUTE IMMEDIATE 'INSERT INTO FRT2STORE_EXC...."
4. In 10gR2 / 11g, DML Error Logging might be a better solution
http://www.oracle.com/technology/oramag/oracle/06-mar/o26performance.html -
Hi,
How to handle fail over mechanism in OWB...
For example, I executed a mapping and loaded 3000 records in target db and program was disconnected/failed due
to some network or with other problem.
Here when I execute nextime the mapping should start from 3001 record.
How can we handle this process for all the mappings
Kindly let me know if you have any ideas/logic how to implement this.
With Regards,
Kranth..Use For All Bulk Collect with exception Handling
DECLARE -- Oracle9i and above!
/*Define Cursor to get data*/
l_array <array_type_declaration>;
bulk_errors EXCEPTION;
PRAGMA EXCEPTION_INIT ( bulk_errors, -24381 );
BEGIN
FORALL indx IN l_array.FIRST .. l_array.LAST
SAVE EXCEPTIONS
/*DML statement of choice*/
EXCEPTION
WHEN bulk_errors
THEN
FOR indx IN 1 .. SQL%BULK_EXCEPTIONS.COUNT
LOOP
/*Insert into Error table*/
DBMS_OUTPUT.PUT_LINE (
'Error ' || indx || ' occurred during ' ||
'iteration ' || SQL%BULK_EXCEPTIONS(indx).ERROR_INDEX ||
' updating name to ' ||
enames_with_errors(SQL%BULK_EXCEPTIONS(indx).ERROR_INDEX));
DBMS_OUTPUT.PUT_LINE (
'Oracle error is ' ||
SQLERRM(-1 * SQL%BULK_EXCEPTIONS(indx).ERROR_CODE));
END LOOP;
END;
/ -
Error in the below sql.
Hi
I am getting the below error in the below sql
Hi
I am getting the error in the below sql
DECLARE
pgm_id NUMBER := &1;
schd_dt DATE := TO_DATE('&2','MM/DD/YYYY');
l_schd_dt DATE := NULL;
l_pgm_id NUMBER :=0;
l_src_id NUMBER;
l_bulkCollectSize NUMBER;
l_trace_level NUMBER := 0;
l_CommitAllowance INFT1.PRM_VALUE%TYPE;
v_insrcdcnt NUMBER := 0;
g_ErrorString VARCHAR2(500) := NULL;
g_log_error VARCHAR2(300) := NULL;
g_recs_upd NUMBER :=0;
g_recs_ins NUMBER :=0;
g_aud_upd_ts DATE := NULL;
l_data_nbr NUMBER := 0;
l_ts_1 DATE :=NULL;
l_ts_2 DATE :=NULL;
l_rest_empno emp_STG.mbr_nbr%TYPE :='0';
l_Commitsize NUMBER;
CURSOR curTrnRecs(l_rest_empno VARCHAR)
IS
SELECT /* user_hash(tmp) PARALLEL(tmp,8) */ tmp.sec_lbl
,tmp.empno
,tmp.ename
,tmp.sal
,tmp.deptno
FROM emp_stg tmp where tmp.mbr_nbr > l_rest_empno order by tmp.mbr_nbr;
TYPE rec_emp_stg is TABLE OF emp_STG%ROWTYPE index by PLS_INTEGER;
stg_emp_stg rec_emp_stg ;
counter NUMBER :=0;
l_idx NUMBER;
errors PLS_INTEGER;
ins_errors EXCEPTION;
PRAGMA EXCEPTION_INIT(ins_errors, -24381);
BEGIN
/* Copy values into local variables */
l_pro:= pgm_id;
l_schd_dt := schd_dt;
/* Check if this is the first execution of the program; Get the last processed timestamp if the run is a restart */
/* The restartability of this program is slightly differnt. Data_nbr =1 indicates that the last run was successful. The same program can*/
/* be called multiple times for the same t47date. The restartability is designed accordingly */
BEGIN
SELECT /* SQL_TAG(<$RCSfile: t50lyt_can_hist_trans_load.sql,v $><2>) */
data_nbr,1,1,
NVL(key_text,'0')
INTO l_data_nbr,
l_ts_1,
l_ts_2,
l_rest_mbr_nbr
FROM inft
WHERE TRUNC(key_ts)=TRUNC(l_schd_dt)
AND pro_id = l_pro_id;
EXCEPTION
WHEN NO_DATA_FOUND THEN
l_data_nbr:=9;
NULL;
WHEN OTHERS then
g_ErrorString := g_log_error||' : SQLCODE = '||SQLCODE||' , ERRORMESSAGE = '||substr(SQLERRM, 1,200);
RAISE;
END;
IF l_data_nbr = 1 THEN
crm_msg.msg('Exiting:: Program already run');
RETURN;
ELSIF l_data_nbr = 0 THEN
crm_msg.msg('This is a restart for the date '||l_schd_dt);
ELSIF l_data_nbr= 9 THEN
crm_msg.msg('First execution of this program');
END IF;
BEGIN
if l_data_nbr =9 THEN
crm_msg.msg('This is the First execution of this program');
INSERT
INTO inft
pgm_id,
key_ts,
key_text,
data_nbr,
data_ts,
data_text
VALUES
l_pro,
l_schd_dt,
0, --to hold empno
sysdate,
0 --no of recs processed
COMMIT;
END IF;
END;
OPEN curTrn(l_rest_empno);
LOOP
BEGIN
FETCH curTrn BULK COLLECT INTO stg_emp_rec LIMIT 50000;
IF nvl(curTrnRecs%ROWCOUNT,0)=0 THEN
crm_msg.msg('No Historical Data');
END IF;
FORALL i in 1..stg_emp_rec.COUNT SAVE EXCEPTIONS
INSERT INTO emp values stg_emp_stg(i);
counter := counter + 1;
g_recs_ins := g_recs_ins+SQL%ROWCOUNT;
EXCEPTION
WHEN ins_errors THEN
errors := SQL%BULK_EXCEPTIONS.COUNT;
for j in 1..errors
LOOP
l_idx :=sql%bulk_exceptions(j).error_index;
UPDATE emp SET src_id=stg_emp_rec(i).empno,ename=stg_emp_rec(i).ename,sal = stg_emp_rec(i).sal,
WHERE deptno= stg_emp_rec(i).deptno;
g_recs_upd := g_recs_upd + SQL%ROWCOUNT;
---END;
-- EXIT WHEN curTrnRecs%NOTFOUND;
-- END LOOP;
-- CLOSE curTrnRecs;
EXCEPTION
WHEN OTHERS THEN
g_ErrorString := g_log_error||' : SQLCODE = '||SQLCODE||' , ERRORMESSAGE = '||substr(SQLERRM, 1,200);
crm_msg.msg(g_ErrorString);
RAISE;
END;
END
IF (counter >= l_CommitSize) THEN
BEGIN /* To keep track of the timestamp of the last record processed inthe batch; for restartability */
UPDATE inft
SET data_ts = SYSDATE
,key_text = l_empno (idx)
WHERE pgm_id = l_pgm_id
AND TRUNC(key_ts)= TRUNC(l_schd_dt);
COMMIT;
counter:=0;
END IF;
EXCEPTION
WHEN OTHERS THEN
g_ErrorString := g_log_error||' : SQLCODE = '||SQLCODE||' , ERRORMESSAGE = '||substr(SQLERRM, 1,200);
crm_msg.msg(g_ErrorString);
RAISE;
END;
COMMIT;
EXIT WHEN curTrn%NOTFOUND;
-- END LOOP; --End of looping for the main cursor fetch
END LOOP;
CLOSE curTrn;
BEGIN /* Update the data_nbr to 1 to indicate the update is complete */
UPDATE inft
SET data_nbr=1,
data_ts=nvl(g_aud_upd_ts,data_ts),
data_text = counter
WHERE pro_id = l_pgm_id
AND TRUNC(key_ts)=TRUNC(l_schd_dt);
COMMIT;
EXCEPTION
WHEN OTHERS THEN
g_ErrorString := g_log_error||' : SQLCODE = '||SQLCODE||' , ERRORMESSAGE = '||substr(SQLERRM, 1,200);
crm_msg.msg(g_ErrorString);
RAISE;
END;
g_log_error := 'LOGGING SUMMARY';
crm_msg.msg_tab('RECS UPDATED',g_recs_upd);
crm_msg.msg_tab('RECS INSERTED',g_recs_ins);
crm_msg.msg('Program ends Successfully');
EXCEPTION
WHEN OTHERS THEN
g_ErrorString := g_log_error||' : SQLCODE = '||SQLCODE||' , ERRORMESSAGE = '||substr(SQLERRM, 1,200);
crm_msg.msg(g_ErrorString);
END;
Elapsed: 00:00:00.00
EXCEPTION
ERROR at line 248:
ORA-06550: line 248, column 3:
PLS-00103: Encountered the symbol "EXCEPTION" when expecting one of the following:
( begin case declare end exit for goto if loop mod null
pragma raise return select update when while with
<an identifier> <a double-quoted delimited-identifier>
<a bind variable> << continue close current delete fetch lock
insert open rollback savepoint set sql execute commit forall
merge pipe purge
ORA-06550: line 255, column 5:
PLS-00103: Encountered the symbol "IF" when expecting one of the following:
ORA-06550: line 314, column 2:
PLS-00103: Encountered the symbol "EXCEPTION" when expecting one of the following:
( begin case declare end exit for goto if loop mod null
pragma raise return select update while with <an identifier>
<a double-quoted delimited-
ORA-06550: line 322, column 0:
PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following:
end not pragma final instantiable order overriding static
member constructor mapAppreciate ur help on the above?
Edited by: user1014019 on Oct 3, 2011 6:45 AM
Edited by: BluShadow on 03-Oct-2011 15:08
added {noformat}{noformat} tags. Please read {message:id=9360002} and learn to do this yourself.Please provide a code that can be compiled, the sample that you provided has compilation errors:
Have made change to your code block, so that it compiles.Try to run the below code block:
/* Formatted on 2011/10/03 21:08 (Formatter Plus v4.8.5) */
DECLARE
pgm_id NUMBER := &1;
schd_dt DATE := TO_DATE ('&2', 'MM/DD/YYYY');
l_schd_dt DATE := NULL;
l_pgm_id NUMBER := 0;
l_src_id NUMBER;
l_bulkcollectsize NUMBER;
l_trace_level NUMBER := 0;
l_commitallowance inft1.prm_value%TYPE;
v_insrcdcnt NUMBER := 0;
g_errorstring VARCHAR2 (500) := NULL;
g_log_error VARCHAR2 (300) := NULL;
g_recs_upd NUMBER := 0;
g_recs_ins NUMBER := 0;
g_aud_upd_ts DATE := NULL;
l_data_nbr NUMBER := 0;
l_ts_1 DATE := NULL;
l_ts_2 DATE := NULL;
l_rest_empno emp_stg.mbr_nbr%TYPE := '0';
l_commitsize NUMBER;
CURSOR curtrnrecs (l_rest_empno VARCHAR)
IS
SELECT /* user_hash(tmp) PARALLEL(tmp,8) */ tmp.sec_lbl, tmp.empno,
tmp.ename, tmp.sal, tmp.deptno
FROM emp_stg tmp
WHERE tmp.mbr_nbr > l_rest_empno
ORDER BY tmp.mbr_nbr;
TYPE rec_emp_stg IS TABLE OF emp_stg%ROWTYPE
INDEX BY PLS_INTEGER;
stg_emp_stg rec_emp_stg;
counter NUMBER := 0;
l_idx NUMBER;
ERRORS PLS_INTEGER;
ins_errors EXCEPTION;
PRAGMA EXCEPTION_INIT (ins_errors, -24381);
BEGIN
/* Copy values into local variables */
l_pro := pgm_id;
l_schd_dt := schd_dt;
/* Check if this is the first execution of the program; Get the last processed timestamp if the run is a restart */
/* The restartability of this program is slightly differnt. Data_nbr =1 indicates that the last run was successful. The same program can*/
/* be called multiple times for the same t47date. The restartability is designed accordingly */
BEGIN
SELECT /* SQL_TAG(<$RCSfile: t50lyt_can_hist_trans_load.sql,v $><2>) */
data_nbr, 1, 1, NVL (key_text, '0')
INTO l_data_nbr, l_ts_1, l_ts_2, l_rest_mbr_nbr
FROM inft
WHERE TRUNC (key_ts) = TRUNC (l_schd_dt) AND pro_id = l_pro_id;
EXCEPTION
WHEN NO_DATA_FOUND
THEN
l_data_nbr := 9;
NULL;
WHEN OTHERS
THEN
g_errorstring :=
g_log_error
|| ' : SQLCODE = '
|| SQLCODE
|| ' , ERRORMESSAGE = '
|| SUBSTR (SQLERRM, 1, 200);
RAISE;
END;
IF l_data_nbr = 1
THEN
crm_msg.msg ('Exiting:: Program already run');
RETURN;
ELSIF l_data_nbr = 0
THEN
crm_msg.msg ('This is a restart for the date ' || l_schd_dt);
ELSIF l_data_nbr = 9
THEN
crm_msg.msg ('First execution of this program');
END IF;
BEGIN
IF l_data_nbr = 9
THEN
crm_msg.msg ('This is the First execution of this program');
INSERT INTO inft
(pgm_id, key_ts, key_text, data_nbr, data_ts, data_text
VALUES (l_pro, l_schd_dt, 0, --to hold empno
SYSDATE, 0 --no of recs processed
COMMIT;
END IF;
END;
OPEN curtrn (l_rest_empno);
LOOP
BEGIN
FETCH curtrn
BULK COLLECT INTO stg_emp_rec LIMIT 50000;
IF NVL (curtrnrecs%ROWCOUNT, 0) = 0
THEN
crm_msg.msg ('No Historical Data');
END IF;
FORALL i IN 1 .. stg_emp_rec.COUNT SAVE EXCEPTIONS
INSERT INTO emp
VALUES stg_emp_stg (i);
counter := counter + 1;
g_recs_ins := g_recs_ins + SQL%ROWCOUNT;
EXCEPTION
WHEN ins_errors
THEN
ERRORS := SQL%BULK_EXCEPTIONS.COUNT;
FOR j IN 1 .. ERRORS
LOOP
l_idx := SQL%BULK_EXCEPTIONS (j).ERROR_INDEX;
UPDATE emp
SET src_id = stg_emp_rec (i).empno,
ename = stg_emp_rec (i).ename,
sal = stg_emp_rec (i).sal
WHERE deptno = stg_emp_rec (i).deptno;
g_recs_upd := g_recs_upd + SQL%ROWCOUNT;
END LOOP;
--END;
-- EXIT WHEN curTrnRecs%NOTFOUND;
--END LOOP;
--CLOSE curTrnRecs;
WHEN OTHERS
THEN
g_errorstring :=
g_log_error
|| ' : SQLCODE = '
|| SQLCODE
|| ' , ERRORMESSAGE = '
|| SUBSTR (SQLERRM, 1, 200);
crm_msg.msg (g_errorstring);
RAISE;
END;
IF (counter >= l_commitsize)
THEN
BEGIN
/* To keep track of the timestamp of the last record processed inthe batch; for restartability */
UPDATE inft
SET data_ts = SYSDATE,
key_text = l_empno (idx)
WHERE pgm_id = l_pgm_id AND TRUNC (key_ts) = TRUNC (l_schd_dt);
COMMIT;
counter := 0;
EXCEPTION
WHEN OTHERS
THEN
g_errorstring :=
g_log_error
|| ' : SQLCODE = '
|| SQLCODE
|| ' , ERRORMESSAGE = '
|| SUBSTR (SQLERRM, 1, 200);
crm_msg.msg (g_errorstring);
RAISE;
END;
END IF;
COMMIT;
EXIT WHEN curtrn%NOTFOUND;
-- END LOOP; --End of looping for the main cursor fetch
END LOOP;
CLOSE curtrn;
BEGIN /* Update the data_nbr to 1 to indicate the update is complete */
UPDATE inft
SET data_nbr = 1,
data_ts = NVL (g_aud_upd_ts, data_ts),
data_text = counter
WHERE pro_id = l_pgm_id AND TRUNC (key_ts) = TRUNC (l_schd_dt);
COMMIT;
EXCEPTION
WHEN OTHERS
THEN
g_errorstring :=
g_log_error
|| ' : SQLCODE = '
|| SQLCODE
|| ' , ERRORMESSAGE = '
|| SUBSTR (SQLERRM, 1, 200);
crm_msg.msg (g_errorstring);
RAISE;
END;
g_log_error := 'LOGGING SUMMARY';
crm_msg.msg_tab ('RECS UPDATED', g_recs_upd);
crm_msg.msg_tab ('RECS INSERTED', g_recs_ins);
crm_msg.msg ('Program ends Successfully');
EXCEPTION
WHEN OTHERS
THEN
g_errorstring :=
g_log_error
|| ' : SQLCODE = '
|| SQLCODE
|| ' , ERRORMESSAGE = '
|| SUBSTR (SQLERRM, 1, 200);
crm_msg.msg (g_errorstring);
END;Hope its useful.
Cheers -
ORA-01722: invalid number error with Bulk collect
Hi ,
I have been using the script to delete old seasonal data from my application DB tables. The stored procedure has been created successfully but when i try to run the proc it has been throwing 'ORA-01722: invalid number' exception at line 'FETCH C1_CUR BULK COLLECT INTO C1_TYPE_VAR LIMIT v_bulklimit;'.
Could you please help me here?
Below is the stored proc:
CREATE OR REPLACE PROCEDURE clean_old_season_data(P_SEASON VARCHAR2) AS
CURSOR C1_CUR IS SELECT ROWID RID,pro.* FROM PROPS pro where pro.ITEMPK IN
(SELECT sve.pk FROM SAVEDVALUEENTRY sve WHERE sve.p_parent IN
(SELECT s.pk FROM SAVEDVALUES s WHERE s.P_MODIFIEDITEM IN
(SELECT a.PK
FROM products a
WHERE a.p_season IN (select s.pk from Seasons s where s.P_code=P_SEASON)
) ) ) and rownum<5;
CURSOR C2_DEL IS SELECT RID FROM PROPS_HISTORY;
TYPE C1_TYPE IS TABLE OF C1_CUR%ROWTYPE;
C1_TYPE_VAR C1_TYPE;
TYPE C2_TYPE IS TABLE OF UROWID;
C2_TYPE_VAR C2_TYPE;
ex_dml_errors EXCEPTION;
PRAGMA EXCEPTION_INIT(ex_dml_errors, -24381);
l_error_count NUMBER;
err_num NUMBER;
err_msg VARCHAR2 (300);
COMMIT_VARIABLE PLS_INTEGER:=0;
v_bulklimit NUMBER:=2;
BEGIN
/*------------------ Data Selection and INSERTION IN HISTORY TABLE ---------------------------------------*/
OPEN C1_CUR;
LOOP
DBMS_OUTPUT.put_line('Cursor opend now in loop');
FETCH C1_CUR BULK COLLECT INTO C1_TYPE_VAR LIMIT v_bulklimit;//ERROR OCCURS HERE
DBMS_OUTPUT.put_line('Cursor count is'|| C1_TYPE_VAR.COUNT);
FORALL I IN 1..C1_TYPE_VAR.COUNT SAVE EXCEPTIONS
INSERT INTO PROPS_HISTORY VALUES C1_TYPE_VAR(I);
COMMIT_VARIABLE := COMMIT_VARIABLE + v_bulklimit;
DBMS_OUTPUT.put_line('Commit variable'|| COMMIT_VARIABLE.COUNT);
IF COMMIT_VARIABLE = v_bulklimit THEN
COMMIT;
COMMIT_VARIABLE := 0;
END IF;
EXIT WHEN C1_CUR%NOTFOUND;
END LOOP;
DBMS_OUTPUT.put_line('Cursor closed now in loop and data inserted in history table');
CLOSE C1_CUR;
/*------------------ Data Selection and DELETION IN Live TABLE ---------------------------------------*/
COMMIT_VARIABLE := 0;
OPEN C2_DEL;
LOOP
FETCH C2_DEL BULK COLLECT INTO C2_TYPE_VAR LIMIT 2;
FORALL I IN 1..C2_TYPE_VAR.COUNT SAVE EXCEPTIONS
DELETE FROM PROPS WHERE ROWID = C2_TYPE_VAR(I);
COMMIT_VARIABLE := COMMIT_VARIABLE + 2;
IF COMMIT_VARIABLE = 2 THEN
COMMIT;
COMMIT_VARIABLE := 0;
END IF;
EXIT WHEN C2_DEL%NOTFOUND;
END LOOP;
CLOSE C2_DEL;
END;Although there are many things which should not have been done in the posted code, I could not find any reason why the Invalid number error should occur at the Fetch clause.
I would suggest you to Insert into Table by providing the Order of Columns i.e. Insert into table (col1, ... colN) values (coll(i).col1...col(i).colN);
I tested below code and it did not give any errors.
drop table test_table;
create table test_Table
rid varchar2(100),
emp_id number(5),
fname varchar2(20),
lname varchar2(50)
set serveroutput on;
declare
cursor c_cur is
select rowid rid, e.*
from employees e
where rownum < 10;
type typ_cur is table of c_cur%rowtype;
typ typ_cur;
l_bulk_limit number := 5;
begin
open c_cur;
loop
fetch c_cur bulk collect into typ limit l_bulk_limit;
dbms_output.put_line('Collection Count :: ' || typ.count);
forall i in 1..typ.count --typ.first..typ.last
insert into test_Table (rid, emp_id, fname, lname) values (typ(i).rid,typ(i).employee_id,typ(i).first_name,typ(i).last_name);
dbms_output.put_line('Processed ' || l_bulk_limit || ' records.');
exit when c_cur%notfound;
end loop;
commit;
end;
select * from test_table;PS:- 1. When you are processing only 4 Records, then why are you breaking them in 2 Loops?
2. Why Commit every time you are processing a DML? Why not maintain an Error Flag and Rollback the Transaction as soon as error is encountered?
3. Use "{code}" (Exclude Double Quotes) to format the code. I am not sure if works.
Regards,
P.
Maybe you are looking for
-
Hi. I am in Canada, on a low-speed upload connection (1 Mbps). That's how it is, all providers offer pretty much the same speed. I use skype to call my parents in Romania, with a huge upload speed (40 Mbps). For several months we have this problem: t
-
How do i delete songs using iTunes from macbook pro
i synced my iphones to a new i tunes library and now i have three unwated songs how do i delete them?
-
Get-order of FTP-adapter (bpel/esb)
Hello, Is it possible to change or influence the order of getting files, i.e. get files by oldest creation date? Scenario: I'm using an FTP-adapter in a bpel process to get files. The interval is set to 1 minute. However, sometimes files are created
-
Exporting and AEP to an earlier version of AfterEffects
I need to export a project that I created in CS4 so that I can open it up in CS3. Does anyone know how to do this? Thanks in advance
-
Server installation zurücksetzen
wie kann ich meine Serverinstallation zurückseten und den Assistenten neu starten?