forall statmant doesn't work - no data found - oracle

keep getting
"element in index [1] does not exist"...
but I do get output from the "dbms_output.put_line (v_lahad_wiz_eq.count);", about 20 lines of '100' and then a line of '61' and a '0', so there is data getting in...
declare
c_limit number :=100;
--set data type and set verible
type lahad_wiz_eq_typ is table of lahad_wiz_eq%rowtype INDEX BY BINARY_INTEGER;
v_lahad_wiz_eq lahad_wiz_eq_typ;
cursor c1 is
select *
FROM wiz_equip_trx q
WHERE q.ACCOUNT_NUMBER > 0
AND q.MANUFACTURER = 'FK';
begin
open c1 ;
loop
fetch c1
bulk collect into v_lahad_wiz_eq
limit c_limit;
dbms_output.put_line (v_lahad_wiz_eq.count);
exit when v_lahad_wiz_eq.count = 0;
end loop;
close c1;
dbms_output.put_line (v_lahad_wiz_eq.last);
forall i in 1 .. 100
insert into lahad_wiz_eq
values v_lahad_wiz_eq (i) ;
dbms_output.put_line ( sql%rowcount);
commit;
end;

You need not loop to get records through BULK COLLECT as you do for normal FETCH INTOstatements and hence no need of EXIT WHEN. Actually, Your loop was overwriting the collection the second time with no values and exit when v_lahad_wiz_eq.count = 0 satisfied the second time to come out of loop.
SET SERVEROUTPUT ON;
DECLARE
c_limit NUMBER := 100;
--set data type and set verible
TYPE lahad_wiz_eq_typ IS
TABLE OF lahad_wiz_eq%rowtype INDEX BY BINARY_INTEGER;
v_lahad_wiz_eq lahad_wiz_eq_typ;
CURSOR c1 IS SELECT
*
FROM
wiz_equip_trx q
WHERE
q.account_number > 0
AND q.manufacturer = 'FK';
BEGIN
OPEN c1;
FETCH c1 BULK COLLECT INTO v_lahad_wiz_eq LIMIT c_limit;
dbms_output.put_line (v_lahad_wiz_eq.count);
CLOSE c1;
dbms_output.put_line(v_lahad_wiz_eq.last);
FORALL i IN 1..v_lahad_wiz_eq.COUNT
INSERT INTO lahad_wiz_eq VALUES v_lahad_wiz_eq ( i );
dbms_output.put_line(SQL%rowcount);
COMMIT;
END;
/

Related

PL/SQL: How to insert depending on column value

I'm a novice at PL/SQL. I have attempted various approaches to use a Cursor to insert into a temp table depending on whether or not the value already exists in the temp table. I either get too many rows or nothing is inserted.
This is my last pseudocode approach and is the bare essence of what I'm attempt to accomplish:
DB: Oracle 12
Using SQL Developer
Goal: Take duplicate accountno info from table1 and merge / combine into single row in temptable
1. Add initial accountno info if it doesn’t already exists in temptable
2. If accountno exists in temptable add the additional info to accountno row
Suggestions are greatly appreciated.
Pseudocode
Declare
V_cnt number (20);
CURSOR c1 is select * from table1;
C1d c1%rowtype;
BEGIN
--
OPEN C1;
LOOP
FETCH C1 INTO c1d;
EXIT WHEN C1%NOTFOUND;
-- Limit attempts
IF LINE > 5 THEN EXIT; END IF;
select accountno INTO v_cnt from table1 where Exists(select 1 from temptable where accountno <> c1d.accountno);
IF v_cnt is NULL THEN
INSERT INTO temptable (accountno)
values(c1d.accountno);
END IF;
LINE:= LINE + 1;
END LOOP;
CLOSE C1;
EXCEPTION
WHEN NO_DATA_FOUND THEN
dbms_output.put_line ('NO DATA');
END;
If you strictly want to correct your pseudo code, You may try -
Declare
V_cnt number (20);
CURSOR c1 is select * from table1;
C1d c1%rowtype;
BEGIN
--
OPEN C1;
LOOP
FETCH C1 INTO c1d;
EXIT WHEN C1%NOTFOUND;
-- Limit attempts
IF LINE > 5 THEN
EXIT;
END IF;
BEGIN
SELECT accountno
INTO V_cnt
FROM temptable
WHERE accountno = c1d.accountno
AND ROWNUM = 1;
EXCEPTION
WHEN NO_DATA_FOUND THEN
V_cnt := NULL;
END;
IF V_cnt is NULL THEN
INSERT INTO temptable (accountno)
values(c1d.accountno);
END IF;
LINE:= LINE + 1;
END LOOP;
CLOSE C1;
EXCEPTION
WHEN NO_DATA_FOUND THEN
dbms_output.put_line ('NO DATA');
END;
I would strongly recommend to use below pseudo code -
Declare
V_cnt number (20);
CURSOR c1 is select * from table1;
C1d c1%rowtype;
BEGIN
--
OPEN C1;
LOOP
FETCH C1 INTO c1d;
EXIT WHEN C1%NOTFOUND;
-- Limit attempts
IF LINE > 5 THEN
EXIT;
END IF;
MERGE INTO temptable
USING table1
ON (accountno = c1d.accountno)
WHEN NOT MATCHED THEN
INSERT (accountno)
values(c1d.accountno);
LINE:= LINE + 1;
END LOOP;
CLOSE C1;
EXCEPTION
WHEN NO_DATA_FOUND THEN
dbms_output.put_line ('NO DATA');
END;

Getting ORA-06532: Subscript outside of limit

I have created varray collection type inorder to get a serv_item_id column value from serv_item table. But while executing im getting subsript outside of limit error.
declare
type t1 is varray(1000) of serv_item%rowtype;
v_t1 t1:=t1();
n number :=0;
cursor c1 is select * from serv_item;
begin
open c1;
loop
v_t1.extend();
fetch c1 into v_t1(n);
exit when c1%notfound;
n:=n+1;
end loop;
close c1;
for i in 0..v_t1.count
loop
dbms_output.put_line('The serv item'||v_t1(i).serv_item_id);
end loop;
end;
/
varray indexing begins at 1, not 0.

Get Specific Row From Table Type With my Filter Values

I have procedure like as below:
cursor my_cursor is
select first_column, second_column, third_column from table_name;
TYPE my_cursor_type is TABLE OF my_cursor_type%ROWTYPE INDEX BY BINARY INTEGER;
my_cur my_cursor_type;
TYPE table_type IS TABLE OF table_name%ROW_TYPE INDEX BY BINARY INTEGER;
table_obj table_type;
begin
open my_cursor;
loop
fetch my_cursor bulk collect
into my_cur limit 5000;
exit when my_cursor%notfound;
for i in 1 .. my_cur.count loop
table_obj(i).first_column := my_cur(i).first_column;
table_obj(i).second_column := my_cur(i).second_column;
table_obj(i).third_column := my_cur(i).third_column;
end loop;
end loop;
Close my_cursor;
……
Now after these codes ı have table_obj which has 100000 record. And this table object has first_column, second_column, third_column.
I search one record's third_column in table_obj. I know first_column, second_column, and i search third_column in table_obj. I must fetch row from table_obj rows. This searched row has my first_column, second_column values.
And i get third_column_value from this row. How can i get specific row from table_obj rows with plsql ?
This can be done by transforming the first two columns to a single index. Concatenation with a separator works best for that. The separator should be a Character that is not used in either of the first two columns.
DECLARE
CURSOR my_cursor
IS
SELECT first_column, second_column, third_column FROM table_name;
TYPE my_cursor_type IS TABLE OF my_cursor_type%ROWTYPE
INDEX BY BINARY_INTEGER;
my_cur my_cursor_type;
TYPE table_type IS TABLE OF table_name%ROWTYPE
INDEX BY BINARY_INTEGER;
table_obj table_type;
l_composite_idx VARCHAR2( 61 );
l_test_idx_1 VARCHAR2( 30 ) := 'Test1';
l_test_idx_2 VARCHAR2( 30 ) := 'Success';
BEGIN
OPEN my_cursor;
LOOP
FETCH my_cursor BULK COLLECT INTO my_cur LIMIT 5000;
FOR i IN 1 .. my_cur.COUNT
LOOP
l_composite_idx := my_cur( i ).first_column || '&' || my_cur( i ).second_column;
table_obj( l_composite_idx ).first_column := my_cur( i ).first_column;
table_obj( l_composite_idx ).second_column := my_cur( i ).second_column;
table_obj( l_composite_idx ).third_column := my_cur( i ).third_column;
END LOOP;
EXIT WHEN my_cursor%NOTFOUND;
END LOOP;
CLOSE my_cursor;
-- You access a row in my_cur like this:
DBMS_OUTPUT.put_line( 'Result: ' || table_obj( l_test_idx_1 || '&' || l_test_idx_2 ) );
END;
Hope this helps!

Bulk insert using FORALL in Oracle

I am currently using the following code to do a bulk insert of 50 million rows:
declare cnt number;
BEGIN
select max(run_ver_issue_id) into cnt from "ABHINAV"."MV_RUN_VER_ISSUE";
FOR x IN 1 .. 50000000 LOOP
INSERT INTO "ABHINAV"."MV_RUN_VER_ISSUE" NOLOGGING ("RUN_VER_ISSUE_ID","CUST_ISSUE_ID","TITLE","ORIGINAL_ISSUE_ID","SOURCE_FILE_LINE","DISPLAY_TEXT","RUN_VER_ID","SANDBOX_SRC_FILE_ID","ACCOUNT_ID","ISSUE_STATE","CURRENT_SEVERITY","INSERT_TS","MODIFIED_TS","CWE_ID","TEMPLATE_FILE_ID","TEMPLATE_FILE_LINE","CURRENT_EXPLOIT_LEVEL","CNT","SOURCE_FUNCTION_PROTOTYPE","SOURCE_RELATIVE_LOCATION","SOURCE_SCOPE","PROCEDURE_NAME","PROCEDURE_HASH","PROTOTYPE_HASH","STATEMENT_HASH","STATEMENT_HASH_COUNT","STATEMENT_HASH_ORDINAL","SUBMODULE_PATH") VALUES (x+cnt,2,..);
END LOOP;
END;
It takes almost 6 hours it to finish. The table does have an index on RUN_VER_ISSUE_ID, but still doesn't help. I tried using FORALL, getting an error PLS-00430: FORALL iteration variable X is not allowed in this context for the below code:
declare cnt number;
BEGIN
select max(run_ver_issue_id) into cnt from "ABHINAV"."MV_RUN_VER_ISSUE";
FORALL x IN 1 .. 5
INSERT INTO "ABHINAV"."MV_RUN_VER_ISSUE" NOLOGGING ("RUN_VER_ISSUE_ID","CUST_ISSUE_ID","TITLE","ORIGINAL_ISSUE_ID","SOURCE_FILE_LINE","DISPLAY_TEXT","RUN_VER_ID","SANDBOX_SRC_FILE_ID","ACCOUNT_ID","ISSUE_STATE","CURRENT_SEVERITY","INSERT_TS","MODIFIED_TS","CWE_ID","TEMPLATE_FILE_ID","TEMPLATE_FILE_LINE","CURRENT_EXPLOIT_LEVEL","CNT","SOURCE_FUNCTION_PROTOTYPE","SOURCE_RELATIVE_LOCATION","SOURCE_SCOPE","PROCEDURE_NAME","PROCEDURE_HASH","PROTOTYPE_HASH","STATEMENT_HASH","STATEMENT_HASH_COUNT","STATEMENT_HASH_ORDINAL","SUBMODULE_PATH") VALUES (x+cnt,2,.....);
END;
I would request you to please provide your suggestions and comments as to how I can speed this up.
you may use this:
declare
p_array_size number := 100000;
type array is table of number;
l_data ARRAY;
cursor c is select rownum seq_no from dual connect by rownum <= p_array_size;
cnt number;
begin
open c;
loop
select max(RUN_VER_ISSUE_ID) into cnt from "ABHINAV"."MV_RUN_VER_ISSUE";
fetch c bulk collect into l_data limit p_array_size;
forall x IN 1 .. l_data.count
insert into "ABHINAV"."MV_RUN_VER_ISSUE"("RUN_VER_ISSUE_ID","CUST_ISSUE_ID","TITLE","ORIGINAL_ISSUE_ID","SOURCE_FILE_LINE","DISPLAY_TEXT","RUN_VER_ID","SANDBOX_SRC_FILE_ID","ACCOUNT_ID","ISSUE_STATE","CURRENT_SEVERITY","INSERT_TS","MODIFIED_TS","CWE_ID","TEMPLATE_FILE_ID","TEMPLATE_FILE_LINE","CURRENT_EXPLOIT_LEVEL","CNT","SOURCE_FUNCTION_PROTOTYPE","SOURCE_RELATIVE_LOCATION","SOURCE_SCOPE","PROCEDURE_NAME","PROCEDURE_HASH","PROTOTYPE_HASH","STATEMENT_HASH","STATEMENT_HASH_COUNT","STATEMENT_HASH_ORDINAL","SUBMODULE_PATH")
values(l_data(x)+cnt,2,'0pJDFy1viDnN2Ku66XPl458gKakF4xz4pTawwoOZYCt0yR2YOw7tH1Mk3oKQ7ynuyasbBjBXr1teBbBdmIsJReIM3kbzWY7H4c6CVgVaw',NULL,230969,'04gQD6Q8uu6ipUbYZ1yKWnU2f8ZsDe6mvfQYLzaNs6ijSI8eRiHtuLyB1v0XtprqPPwRSmw2mKdTzP4tM722PKavefz84MrvtNzJYtA6uDXPDtqTGREXa0J77B1FcqMVWVqTv7AUwUhXu0GQCBOd8YGKRwd4015JzQao2P2CRVtLAy8otaHZ2Mlc1h0Ua8EZkChMAjEPkmEFhfKoQ3ZBRB2b7IlOkhhCe3pVLoROV5PuQrdoXbtNah5wiT0SR0K1d8uulffqMTWaVLWe7txiuBqadhCKjc5jRlZ1uku2BB8xhHi68TDwd61bIPscESFWUauoJ8J4OowO8JRdVlWVpqmqyBtWoNsry8S1nBKUTbjkW2RzzaDFmtFedMcmSYO81jyekw8BO8lccKH8O2EZsiZaMpBtEImlSIKTfXYOp5FuH3kpYlPfW5qNmNoZAuwjrRuoV6mzf1FkGPp6scwi7o2i1R4pyHzv8BhZmm7jg7AoBaCJSrgThp81KxSUvuNlslTrdLOva6Fc3nj4NRwxOjwS3dOYyOV4E0FVyxCdYs0r8vQb1BAO7P0O5WegpIwcSQNDXTkokPpBvRFq0kOrjwUDMqafX1e0RrSpDl4a8SnJSEq40g3GrxpEoQ7YbJ453N454GGrHvksOnaY7reaFurn1MbPKRRlX6yUScAd2TQfzFRkzfKcpZDRD2sxXeyM4KNvQ4qVLdvsh64wely1WTRQE0iaCYVGkQj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IQ6gwX3Xhjl338BqTJaMZUKxzMcdTovIPF6iD3lXeW4szUglzWNmFKXlYQ71cRQM1v0BAZwUqf1lRZfCsKnPlJIDdgy0JmHrfVHGGy84c3NMf7TRuNOeqj7xUYCV','Aox4fssjHKLaZwTS0Bq',57753,NULL,'C:\DOCS\TEMP75');
exit when c%notfound;
end loop;
close c;
commit;
end;

Bulk Collect Oracle

Can bulk collect be done if data is getting inserted into table A from Table B and while selecting data, substr, instr, trunc functions has been used on columns fetched?
INSERT INTO A
SELECT
DISTINCT
SUBSTR(b.component, 1, INSTR(b.component, ':', 1) - 1),
TRUNC(c.end_dt, 'DDD'),
FROM
B b,
C c
WHERE
TRUNC(c.end_dt)=TRUNC(b.last_Date, 'DDD') ;
How can I insert data into table A using bulk collect?
The only reason you'd use Bulk Collect and FORALL to insert rows is when you absolutely need to process/insert rows in chunks. Otherwise always use SQL.
DECLARE
CURSOR c_data IS
SELECT * FROM source_tab;
--
TYPE t_source_tab IS TABLE OF source_tab%ROWTYPE;
l_tab t_source_tab;
v_limit NUMBER:= 1000;
BEGIN
OPEN c_data;
LOOP
FETCH c_data BULK COLLECT INTO l_tab LIMIT v_limit;
EXIT WHEN l_tab.count = 0;
-- Insert --
FORALL i IN l_tab.first .. l_tab.last
INSERT INTO destination_tab VALUES l_tab(i);
COMMIT;
-- prints number of rows processed --
DBMS_OUTPUT.PUT_LINE ('Inserted ' || SQL%ROWCOUNT || ' rows:');
-- Print nested table of records - optional.
-- May overflow the buffer and slow down the performance if you process many rows.
-- Use for testing only and limit the rows with Rownum or Row_Number() in cursor query:
FOR i IN l_tab.FIRST..l_tab.LAST -- or l_tab.COUNT
LOOP
DBMS_OUTPUT.PUT_LINE (l_tab(i).hire_date ||chr(9)||l_tab(i).last_name ||chr(9)||l_tab(i).first_name);
END LOOP;
END LOOP;
CLOSE c_data;
END
/

Resources