Bulk collect error
Declare
cursor c1 is select * from emp;
Type t1 is table of emp%rowtype index by binary_integer;
details t1;
rows natural:=1000;
begin
open c1;
loop
fetch c1 bulk collect into details limit rows;
exit when details.count=0;
end loop;
end;
when i compiled this program i got this below error "ORA-06550"
INTO LIST OF WRONG TYPE
I got this error in fetch statement.suggest some methods to avoid this problem.
additionally,...
By Morgan
>
One should never set a limit unless it is necessary to do so. In a table with a few thousand rows using a LIMIT clause would in most cases just
increase overhead and reduce performance.
Nor would I ever advise anyone to set a limit of 1000 rows.
The number of rows in the limit clause should be tuned beginning with a minimum number of 100 and the results graphed. The number of rows
is never a direct correlation but rather rows * bytes/row so the number of rows in a table with 30 bytes per row is going to be substantially
different from that in a table with 500 bytes per row.
Please do not throw out numbers like 1000 as though there is some authoritative rationale behind them. Almost always, as in this case, there is not.
I have plenty of applications where the best number is between 5,000 and 10,000.
>
Regards,
Christian Balz
Similar Messages
-
Error while doing bulk collect
Dear forum,
I am getting following error while i try to use the bulk collect
ERROR at line 1:
ORA-06500: PL/SQL: storage error
ORA-04030: out of process memory when trying to allocate 16408 bytes (koh-kghu
call ,pmuccst: adt/record)
ORA-06512: at "XLAPP14.TEST_LOAD", line 30
ORA-06512: at line 2
Pls assist
ThanksThis is a duplicate post.
Please never post more than once.
Everyone should ignore this. -
Too many values when trying insert records by bulk collect
Hi
Can anyone advice on the bulk collect error please?
Following is my code where I am getting too many values error...
TYPE p_empid_type IS TABLE OF emp%ROWTYPE;
v_empid p_empid_type;
BEGIN
SELECT DISTINCT emp_id , 'ABC'
BULK COLLECT INTO v_empid
FROM emp
WHERE empid IN (SELECT ord_id
FROM table_x
WHERE column_x = 'ABC');
FORALL i IN v_empid.FIRST .. v_empid.LAST
INSERT INTO my_table
VALUES v_empid(i);
COMMIT;
PL/SQL: ORA-00913: too many values in line - BULK COLLECT INTO v_empidHello, since you're SELECTing a constant string, why not:
TYPE p_empid_type IS TABLE OF INTEGER;
v_empid p_empid_type;
BEGIN
SELECT DISTINCT emp_id
BULK COLLECT INTO v_empid
FROM emp
WHERE empid IN (SELECT ord_id
FROM table_x
WHERE column_x = 'ABC');
FORALL i IN v_empid.FIRST .. v_empid.LAST
INSERT INTO my_table
VALUES v_empid(i), 'ABC';
Edit Untested: may not work
This would be the best BULK COLLECT of all:
INSERT /*+ APPEND */ INTO my_table
SELECT DISTINCT emp_id , 'ABC'
FROM emp
WHERE empid IN (SELECT ord_id
FROM table_x
WHERE column_x = 'ABC');
COMMIT; -
How to view errors if bulk collect has thrown errors
Hi,
I have few questions.
1.How to view error whether bulk collect is successful or not
2.What is identified & unidentified relationships in ERWIN
3.How to see the errors whether the sql loder is successful or not
and how to open the log file.Is there any specific command in UNIX
which tells loader is successful or thrown error
4.When executing the pl/sql procedure from UNIX.how to check for errors.
Please provide the answers for this
ThanksUse SAVE EXCEPTIONS clause in your FORALL loop.
Is this for homework/test? -
Error while doing Bulk Collect to a table type
I'm using a Table type to accumulate resultset from a loop and finally return the records in the table type as a ref cursor to the front end.
But when I'm using Bult collect to insert into the table type object it keeps throwing an error
'PLS-00597: expression 'TAB_CALENDAR_AVAIL_RESULTSET' in the INTO list is of wrong type'. Can someone help me to let me know what could be the reason for this error. I'm not able to proceed further, please help.
Here is the code.
CREATE OR REPLACE PACKAGE hotel
AS
TYPE calendar_cursor IS REF CURSOR;
TYPE type_calendar_avail is RECORD(
HOTEL_ID AVAILABILITY_CALENDAR.hotel_id%TYPE,--varchar2(4), --AVAILABILITY_CALENDAR.hotel_id%TYPE,
AVAIL_DATE AVAILABILITY_CALENDAR.AVAIL_DATE%TYPE ,
TOTAL_COUNT number
TYPE type_calendar_avail_resultset IS TABLE OF type_calendar_avail;
tab_calendar_avail_resultset type_calendar_avail_resultset ; -- declare variable of type type_calendar_avail_resultset
PROCEDURE sp_get_calendar_results (
sallhotelswithavaildate VARCHAR2,
ilengthofstay NUMBER,
sorcowner VARCHAR2,
all_unittypes VARCHAR2, --DBMS_SQL.VARCHAR2S
calendar_resultset OUT calendar_cursor
-- tab_calendar_avail_resultset out type_calendar_avail_resultset
PROCEDURE sp_get_calendar_results (
sallhotelswithavaildate VARCHAR2,
ilengthofstay NUMBER,
-- ivariant NUMBER,
sorcowner VARCHAR2,
all_unittypes VARCHAR2, --DBMS_SQL.VARCHAR2S
calendar_resultset OUT calendar_cursor
AS
sbuf VARCHAR2 (200);
sepr VARCHAR2 (1);
shotelwithdate VARCHAR2 (200);
shotelid VARCHAR2 (10);
savaildate VARCHAR2 (8);
sactualavaildate VARCHAR2 (8);
pos NUMBER;
istart NUMBER;
sstartdate VARCHAR2 (8);
senddate VARCHAR2 (8);
squery VARCHAR2 (32767) := '';
sunittypecond VARCHAR2 (500) := '';
sunitdesccond VARCHAR2 (500) := '';
v_unit_cond a_unit_cond;
tempunitcond VARCHAR2 (50) := '';
BEGIN
istart := 1;
LOOP
tempunitcond := hotel.stringtokenizer (all_unittypes, istart, '|');
IF tempunitcond IS NOT NULL
THEN
v_unit_cond (istart) := tempunitcond;
istart := istart + 1;
END IF;
EXIT WHEN tempunitcond IS NULL;
END LOOP;
sunitdesccond := hotel.get_unit_description_cond (v_unit_cond);
DBMS_OUTPUT.put_line ('unit description : ' || sunitdesccond);
sbuf := sallhotelswithavaildate;
sepr := '|';
istart := 1;
LOOP
shotelwithdate := hotel.stringtokenizer (sbuf, istart, sepr);
EXIT WHEN shotelwithdate IS NULL;
shotelid :=
SUBSTR (shotelwithdate, 1, INSTR (shotelwithdate, ',') - 1);
savaildate :=
SUBSTR (shotelwithdate, INSTR (shotelwithdate, ',') + 1);
squery :=
' SELECT MIN (ad.avail_date) '
|| ' FROM wvo_fonres.fpavail_daily ad'
|| ' WHERE ad.hotel_id = '
|| shotelid
|| ' AND ad.days_left >= '
|| ilengthofstay
|| ' AND ad.avail_date >= '
|| savaildate;
IF UPPER (sorcowner) = 'N'
THEN
squery :=
squery
|| ' AND ad.ORC_TYPE != ''R'' and ad.ORC_TYPE != ''P'' and ad.ORC_TYPE != ''E'' ';
END IF;
squery := squery || ' AND ( ' || sunitdesccond || ') ';
EXECUTE IMMEDIATE squery
INTO sactualavaildate;
DBMS_OUTPUT.put_line ('Actual available Date: ' || sactualavaildate);
hotel.sp_get_startdate_enddate (sactualavaildate,
--ivariant,
sstartdate,
senddate
sunittypecond := hotel.get_unittype_cond (v_unit_cond, sorcowner);
-- execute immediate
squery :=
'select HOTEL_ID, AVAIL_DATE, ' || sunittypecond || ' AS TOTAL_COUNT '
|| ' FROM AVAILABILITY_CALENDAR A '
|| 'WHERE '
|| 'AVAIL_DATE >= '''
|| sstartdate
|| ''' '
|| 'AND '
|| 'AVAIL_DATE <= '''
|| senddate
|| ''' '
||'AND '
|| 'A.HOTEL_ID IN ('
|| shotelid
|| ') '
|| 'AND ('
|| sunittypecond
|| '> 0) '
|| -- where total available count of unit type is greater than 0
' ORDER BY AVAIL_DATE'; --order clause
open calendar_resultset for squery;
fetch calendar_resultset BULK COLLECT INTO tab_calendar_avail_resultset;
istart := istart + 1;
END LOOP;
COMMIT;
EXCEPTION
WHEN NO_DATA_FOUND
THEN
NULL;
WHEN OTHERS
THEN
DBMS_OUTPUT.put_line
(SQLERRM (SQLCODE));
RAISE;
END sp_get_calendar_results;
END hotel;
/1. put tags [co[/b][b]de] and [co[/b][b]de] around your code, so it's readable
B. what does "hotel.get_unittype_cond (v_unit_cond, sorcowner)" actually retun?
and third, try this for the array declaration:
tab_calendar_avail_resultset type_calendar_avail_resultset := type_calendar_avail_resultset ; () ; -
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. -
Error while using bulk collect
Hi
I tried with the following code,
DECLARE
TYPE EmpRec IS RECORD (last_name EMP.ename%TYPE,
salary emp.sal%TYPE);
emp_info EmpRec;
TYPE empnest IS TABLE OF EMP.empno%TYPE;
empnestvar empnest;
BEGIN
empnestvar := empnest(7566,7788);
FOR i in empnestvar.first..empnestvar.last LOOP
UPDATE emp SET sal = sal * 1.1 WHERE empno = empnestvar(i)
RETURNING ename, sal BULK COLLECT INTO emp_info;
DBMS_OUTPUT.PUT_LINE('Just gave a raise to ' || emp_info.last_name ||
', who now makes ' || emp_info.salary);
ROLLBACK;
END LOOP;
END;getting this following err
RETURNING ename, sal BULK COLLECT INTO emp_info;
ERROR at line 11:
ORA-03113: end-of-file on communication channelCould you please advice me in this
ThanksThe main problem i you are bulk collecting into a "record" type variable.
SQL>
SQL> SHOW user
USER is "SCOTT"
SQL> SELECT * FROM v$version;
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.2.0 - Prod
PL/SQL Release 10.2.0.2.0 - Production
CORE 10.2.0.2.0 Production
TNS for Solaris: Version 10.2.0.2.0 - Production
NLSRTL Version 10.2.0.2.0 - Production
SQL> SET SERVEROUT on
SQL> DECLARE
TYPE EmpRec IS RECORD(
last_name EMP.ename%TYPE,
salary emp.sal%TYPE);
TYPE emp_bl IS TABLE OF EmpRec; --Added.
emp_info emp_bl; --Changed.
TYPE empnest IS TABLE OF EMP.empno%TYPE;
empnestvar empnest;
BEGIN
empnestvar := empnest(7566, 7788);
FOR i in empnestvar.first .. empnestvar.last LOOP
UPDATE emp
SET sal = sal * 1.1
WHERE empno = empnestvar(i) RETURNING ename, sal BULK COLLECT INTO
emp_info;
DBMS_OUTPUT.PUT_LINE('Just gave a raise to ' || emp_info(1)
.last_name || ', who now makes ' || emp_info(1)
.salary);
ROLLBACK;
END LOOP;
END; 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
22 /
Just gave a raise to JONES, who now makes 3272.5
Just gave a raise to SCOTT, who now makes 3300
PL/SQL procedure successfully completed.
SQL>Although, I must say that, as because empno is the primary key, here RETURNING INT with BULK COLLECT doesn't make any sense. -
Bulk Collect with FORALL not working - Not enough values error
Hi,
I am trying to copy data from one table to another which are having different number of columns. I am doing the following. But it threw not enough values error.
Table A has more than 10 millions of records. So I am using bulk collect instead of using insert into select from.
TABLE A (has more columns - like 25)
c1 Number
c2 number
c3 varchar2
c4 varchar2
c25 varchar2
TABLE B (has less columns - like 7)
c1 Number
c2 number
c3 varchar2
c4 varchar2
c5 number
c7 date
c10 varchar2
declare
TYPE c IS REF CURSOR;
v_c c;
v_Sql VARCHAR2(2000);
TYPE array is table of B%ROWTYPE;
l_data array;
begin
v_Sql := 'SELECT c1, c2, c3, c4, c5, c7, c10 FROM A ORDER BY c1';
OPEN v_c FOR v_Sql;
LOOP
FETCH v_c BULK COLLECT INTO ldata LIMIT 100000;
FORALL i in 1 .. ldata.count
INSERT
INTO B
VALUES ldata(i);
END LOOP;
COMMIT;
exception
WHEN OTHERS THEN
ROLLBACK;
dbms_output.put_line('Exception Occurred' || SQLERRM);
END;
When I execute this, I am getting
PL/SQL: ORA-00947: not enough values
Any suggestions please. Thanks in advance.Table A has more than 10 millions of records. So I am using bulk collect instead of using insert into select from.That doesn't make sense to me. An INSERT ... SELECT is going to be more efficient, more maintainable, easier to write, and easier to understand.
INSERT INTO b( c1, c2, c3, c4, c5, c7, c10 )
SELECT c1, c2, c3, c4, c5, c7, c10
FROM a;is going to be faster, use fewer resources, be far less error-prone, and have a far more obvious purpose when some maintenance programmer comes along than any PL/SQL block that does the same thing.
If you insist on using PL/SQL, what version of Oracle are you using? You should be able to do something like
DECLARE
TYPE b_tbl IS TABLE OF b%rowtype;
l_array b_tbl;
CURSOR a_cursor
IS SELECT c1, c2, c3, c4, c5, c7, c10 FROM A;
BEGIN
OPEN a_cursor;
LOOP
FETCH a_cursor
BULK COLLECT INTO l_array
LIMIT 10000;
EXIT WHEN l_array.COUNT = 0;
FORALL i IN l_array.FIRST .. l_array.LAST
INSERT INTO b
VALUES l_array(i);
END LOOP;
COMMIT;
END;That at least eliminates the infinite loop and the unnecessary dynamic SQL. If you're using older versions of Oracle (it's always helpful to post that information up front), the code may need to be a bit more complex.
Justin
Edited by: Justin Cave on Jan 19, 2011 5:46 PM -
Bulk collect & forall error in script
hi,
i am having senerio as below in my code.but i am getting error "too many values for emp1". i know why i m getting error but i need to insert emp column " EMPNO, ENAME" value in emp1 table &
emp column " EMPNO, ENAME,sal" value in emp2 table .
how to do it.sud i declare 2 diffrent cursor ? 1 cursor having only "EMPNO, ENAME" & 2nd having "EMPNO, ENAME, SAL" values.
or any other best way to do this. plz help ..
DECLARE
CURSOR s_cur1
IS SELECT EMPNO, ENAME, SAL
FROM EMP E;
TYPE fetch_array1 IS TABLE OF s_cur1%ROWTYPE;
s_array1 fetch_array1;
BEGIN
OPEN s_cur1;
LOOP
FETCH s_cur1 BULK COLLECT INTO s_array1 LIMIT 1000;
FORALL i IN 1..s_array1.COUNT SAVE EXCEPTIONS
INSERT INTO EMP1 --(EMPNO, ENAME)
VALUES s_array1(i);
FORALL i IN 1..s_array1.COUNT SAVE EXCEPTIONS
INSERT INTO EMP2 --(EMPNO, ENAME, sal)
VALUES s_array1(i);
EXIT WHEN s_cur1%NOTFOUND;
END LOOP;
CLOSE s_cur1;
COMMIT;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('Unexpected Error:'||SqleRrm);
END;
table structures:-
CREATE TABLE EMP (
EMPNO NUMBER,
ENAME VARCHAR2 (100),
SAL NUMBER ) ;
CREATE TABLE EMP1 (
EMPNO NUMBER,
ENAME VARCHAR2 (100),
CREATE TABLE EMP2 (
EMPNO NUMBER,
ENAME VARCHAR2 (100),
SAL NUMBER ) ;
---------------------------------------------------------------------Do it in one simple SQL.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL> desc emp
Name Null? Type
EMPNO NOT NULL NUMBER(4)
ENAME VARCHAR2(10)
JOB VARCHAR2(9)
MGR NUMBER(4)
HIREDATE DATE
SAL NUMBER(7,2)
COMM NUMBER(7,2)
DEPTNO NUMBER(2)
SQL> desc emp1
Name Null? Type
EMPNO NUMBER
ENAME VARCHAR2(100)
SQL> desc emp2
Name Null? Type
EMPNO NUMBER
ENAME VARCHAR2(100)
SAL NUMBER
SQL> INSERT ALL WHEN 1 = 1 THEN INTO emp1
2 (empno, ename)
3 VALUES
4 (empno, ename) WHEN 2 = 2 THEN INTO emp2
5 (empno, ename, sal)
6 VALUES
7 (empno, ename, sal)
8 SELECT empno, ename, sal FROM emp;
28 rows created.
SQL> SELECT COUNT(*) FROM emp1;
COUNT(*)
14
SQL> SELECT COUNT(*) FROM emp2;
COUNT(*)
14
SQL> SELECT COUNT(*) FROM emp;
COUNT(*)
14
SQL> -
Retruning bulk collect into---Error
the code:
DECLARE
v_file UTL_FILE.file_type;
TYPE emp_tab_type IS TABLE OF emp%ROWTYPE;
v_row VARCHAR2 (100);
emp_tab emp_tab_type;
BEGIN
v_file := UTL_FILE.fopen ('XML_DIR', 'emp.txt', 'w');
EXECUTE IMMEDIATE 'select * from emp'
RETURNING BULK COLLECT INTO emp_tab;
FOR i IN emp_tab.FIRST .. emp_tab.LAST
LOOP
v_row :=
emp_tab.empno
|| ','
|| emp_tab.ename
|| ','
|| emp_tab.job
|| ','
|| emp_tab.mgr
|| ','
|| emp_tab.hiredate
|| ','
|| emp_tab.sal
|| ','
|| emp_tab.comm
|| ','
|| emp_tab.deptno;
UTL_FILE.put_line (v_file, v_row, TRUE);
END LOOP;
UTL_FILE.fclose (v_file);
EXCEPTION
WHEN OTHERS
THEN
UTL_FILE.fclose (v_file);
END;
the error:
ORA-06550: line 12, column 7:
PLS-00429: unsupported feature with RETURNING clause
please help!Couple of errors:
1) There is absolutely no need to use dynamic SQL here, so get rid of the EXECUTE IMMEDIATE.
2) If any error occurs, then you are hiding it from the caller by your WHEN OTHERS THEN exception handler. Just get rid of it, or use WHEN OTHERS THEN UTL_FILE.fclose (v_file); RAISE; END;
3) You have to refer to the elements of your nested table emp_tab and not to the nested table itself, so add a "(i)" to refer to the element inside the loop.
Example:
SQL> DECLARE
2 TYPE emp_tab_type IS TABLE OF emp%ROWTYPE;
3 v_row VARCHAR2 (100);
4 emp_tab emp_tab_type;
5 BEGIN
6 select *
7 BULK COLLECT INTO emp_tab
8 from emp
9 ;
10 FOR i IN emp_tab.FIRST .. emp_tab.LAST
11 LOOP
12 v_row :=
13 emp_tab(i).empno || ',' ||
14 emp_tab(i).ename || ',' ||
15 emp_tab(i).job || ',' ||
16 emp_tab(i).mgr || ',' ||
17 emp_tab(i).hiredate || ',' ||
18 emp_tab(i).sal || ',' ||
19 emp_tab(i).comm || ',' ||
20 emp_tab(i).deptno
21 ;
22 dbms_output.put_line(v_row);
23 END LOOP;
24 END;
25 /
7369,SMITH,CLERK,7902,17-12-1980 00:00:00,800,,20
7499,ALLEN,SALESMAN,7698,20-02-1981 00:00:00,1600,300,30
7521,WARD,SALESMAN,7698,22-02-1981 00:00:00,1250,500,30
7566,JONES,MANAGER,7839,02-04-1981 00:00:00,2975,,20
7654,MARTIN,SALESMAN,7698,28-09-1981 00:00:00,1250,1400,30
7698,BLAKE,MANAGER,7839,01-05-1981 00:00:00,2850,,30
7782,CLARK,MANAGER,7839,09-06-1981 00:00:00,2450,,10
7788,SCOTT,ANALYST,7566,09-12-1982 00:00:00,3000,,20
7839,KING,PRESIDENT,,17-11-1981 00:00:00,5000,,10
7844,TURNER,SALESMAN,7698,08-09-1981 00:00:00,1500,0,30
7876,ADAMS,CLERK,7788,12-01-1983 00:00:00,1100,,20
7900,JAMES,CLERK,7698,03-12-1981 00:00:00,950,,30
7902,FORD,ANALYST,7566,03-12-1981 00:00:00,3000,,20
7934,MILLER,CLERK,7782,23-01-1982 00:00:00,1300,,10
PL/SQL procedure successfully completed.Regards,
Rob. -
Error during runtime when using BULK collect
Hi
CREATE OR REPLACE TYPE VAR_ROW AS OBJECT
VAR_1 VARCHAR2(20),
VAR_2 VARCHAR2(20)
CREATE OR REPLACE TYPE V_TAB AS table of VAR_ROW
CREATE OR REPLACE FUNCTION get_id RETURN var_tbl
PIPELINED AS
/* declaration */
i INTEGER;
--TYPE x_t IS TABLE OF VAR_ROW;
x_t V_TAB;
c_wip sys_refCursor;
BEGIN
c_wip := getTable('abc'); --the result return: 10 rows with 2 columns.
LOOP
FETCH c_wip BULK COLLECT
INTO x_t LIMIT 20; <-- error seems to come from this line
FOR i IN x_t.FIRST .. x_t.LAST LOOP
PIPE ROW(x_t(i).VAR_1);
--PIPE ROW(x(i).VAR_1);
END LOOP;
exit when c_wip%NOTFOUND;
end loop;
RETURN;
END;
SELECT *
FROM TABLE(get_id)
Error msg: ORA-00932:inconsistent datatypes:expected UDT got CHARWhat could be the cause of the error?In addition, if your cursor returns two separate columns, you'll have to call an appropriate object constructor to create a VAR_ROW object from the two columns. The easiest solution would be to do this in your getTable method. Where you have
SELECT column1, column2in getTable today, you'd want
SELECT var_row( column1, column2 )Otherwise, Oracle cannot construct the VAR_ROW object from the cursor, so you cannot bulk collect it into an array of VAR_ROW.
Justin
Distributed Database Consulting, Inc.
http://www.ddbcinc.com/askDDBC -
Re: ORA 06550 in FOR ALL INSERT...Please help me ..
DECLARE
CURSOR c1 IS SELECT fs.user_id, fs.lot_id, ts.ml_ac_no, ts.td_prs_dt, ts.unit_cost, ts.cost_basis
FROM tb_xop_sharelot_fraction_snap fs, tb_xop_sharelot ts
WHERE fs.lot_id=ts.lot_id AND fs.user_id=ts.user_id;
Type ty_tab1 is table of C1%rowtype index by PLS_INTEGER;
ltab1 ty_tab1;
BEGIN
OPEN C1;
LOOP
FETCH C1 BULK COLLECT INTO ltab1 LIMIT 5000;
LOOP
FORALL i in ltab1.first ..ltab1.last
Update tb_xop_sharelot_fraction_snap
set ml_ac_no=ltab1(i).ml_ac_no
,td_prs_dt=ltab1(i).td_prs_dt
,unit_cost=ltab1(i).unit_cost
,cost_basis=ltab1(i).cost_basis;
commit;
END LOOP;
EXIT WHEN C1%NOTFOUND;
END LOOP;
CLOSE C1;
DBMS_OUTPUT.PUT_LINE('ml_ac_no, td_prs_dt, unit_cost and cost_basis columns are updated successfully:'||ltab1.count);
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line(SQLCODE|| ' ' ||SQLERRM);
END;
{ORA-06550: line 21, column 37:
PLS-00436: implementation restriction: cannot reference fields of BULK In-BIND table of records
ORA-06550: line 21, column 37:
PLS-00382: expression is of wrong type
ORA-06550: line 20, column 36:
PLS-00436: implementation restriction: cannot reference fields of BULK In-BIND table of records
ORA-06550: line 20, column 36:
PLS-00382: expression is of wrong type
ORA-06550: line 19, column 56:
PLS-00436: implementation restriction: cannot reference fields of BULK In-BIND table of records
ORA-06550: line 19, column 56:
PLS-00382: expression is of wrong type
ORA-06550: line 18, column 46:
PLS-00436: implementation restriction: cannot reference fields of BULK In-BIND table of records
ORA-06550: line 18, column 46:
PLS-00382: expression is of wrong type
ORA-06550: line 21, column 37:
PL/SQL: ORA-22806: not an object or REF
ORA-06550: line 17, column 16:
PL/SQL: SQL Statement ignored
{Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi this version}Hoek wrote:
Some more detail: http://www.oracle-developer.net/display.php?id=410
Creating object type + using treat seems like an overkill to simply creating individual collections:
SQL> declare
2 cursor v_cur is select empno,ename,sal from emp where deptno = 10;
3 type v_tbl_type is table of v_cur%rowtype index by pls_integer;
4 v_tbl v_tbl_type;
5 begin
6 select empno,ename,sal
7 bulk collect
8 into v_tbl
9 from emp
10 where deptno = 10;
11 forall i in 1..v_tbl.count
12 update tbl
13 set name = v_tbl(i).ename,
14 sal = v_tbl(i).sal;
15 end;
16 /
sal = v_tbl(i).sal;
ERROR at line 14:
ORA-06550: line 14, column 19:
PLS-00436: implementation restriction: cannot reference fields of BULK In-BIND
table of records
ORA-06550: line 14, column 19:
PLS-00382: expression is of wrong type
ORA-06550: line 13, column 20:
PLS-00436: implementation restriction: cannot reference fields of BULK In-BIND
table of records
ORA-06550: line 13, column 20:
PLS-00382: expression is of wrong type
ORA-06550: line 14, column 19:
PL/SQL: ORA-22806: not an object or REF
ORA-06550: line 12, column 7:
PL/SQL: SQL Statement ignored
SQL> declare
2 cursor v_cur is select empno,ename,sal from emp where deptno = 10;
3 v_empno_tbl sys.OdciNumberList;
4 v_ename_tbl sys.OdciVarchar2List;
5 v_sal_tbl sys.OdciNumberList;
6 begin
7 select empno,ename,sal
8 bulk collect
9 into v_empno_tbl,v_ename_tbl,v_sal_tbl
10 from emp
11 where deptno = 10;
12 forall i in 1..v_empno_tbl.count
13 update tbl
14 set name = v_ename_tbl(i),
15 sal = v_sal_tbl(i);
16 end;
17 /
PL/SQL procedure successfully completed.
SQL> SY. -
Forall with bulk collect .. getting error
it's 10 g.
gettting this error.
drop table t2;
create table t2
( seq_id number,
act number,
is_p varchar2(1),
other varchar2(20)
insert into t2 values(1,2,'N','Test 1');
drop table t3;
create table t3
( seq_id number
-- ,act number
-- ,is_p varchar2(1)
set serveroutput on
declare
type t2_r is table of t2%ROWTYPE;
cursor c1 is select * from t2 ;
t t2_r;
begin
open c1;
fetch c1 BULK collect into t;
forall i in 1..t.count
insert into t3(seq_id) values (t(i).seq_id);
end;
ORA-06550: line 10, column 35:
PLS-00436: implementation restriction: cannot reference fields of BULK In-BIND table of records
ORA-06550: line 10, column 35:
PLS-00382: expression is of wrong type
ORA-06550: line 10, column 35:
PL/SQL: ORA-22806: not an object or REF
ORA-06550: line 10, column 4:
PL/SQL: SQL Statement ignoredThe PLS-00436 is an annoying error message indeed.
On 10g:
rwijk@ORA10GR2> create table t2
2 ( seq_id number,
3 act number,
4 is_p varchar2(1),
5 other varchar2(20)
6 );
Tabel is aangemaakt.
rwijk@ORA10GR2> insert into t2 values(1,2,'N','Test 1');
1 rij is aangemaakt.
rwijk@ORA10GR2> create table t3
2 ( seq_id number
3 -- ,act number
4 -- ,is_p varchar2(1)
5 );
Tabel is aangemaakt.
rwijk@ORA10GR2> declare
2 type t2_r is table of t2%ROWTYPE;
3 cursor c1 is select * from t2 ;
4 t t2_r;
5 begin
6 open c1;
7 fetch c1 BULK collect into t;
8 forall i in 1..t.count
9 insert into t3(seq_id) values (t(i).seq_id);
10 close c1;
11 end;
12 /
insert into t3(seq_id) values (t(i).seq_id);
FOUT in regel 9:
.ORA-06550: Regel 9, kolom 35:
PLS-00436: Implementatierestrictie: kan niet verwijzen naar velden van BULK In-BIND-recordtabel..
ORA-06550: Regel 9, kolom 35:
PLS-00382: Uitdrukking heeft onjuist type..
ORA-06550: Regel 9, kolom 35:
PL/SQL: ORA-22806: Geen object of REF..
ORA-06550: Regel 9, kolom 4:
PL/SQL: SQL Statement ignored.You can code it slightly different using SQL object types like this, to make the code work in 10g:
rwijk@ORA10GR2> create type t2_otype is object
2 ( seq_id number
3 , act number
4 , is_p varchar2(1)
5 , other varchar2(20)
6 );
7 /
Type is aangemaakt.
rwijk@ORA10GR2> create type t2s is table of t2_otype;
2 /
Type is aangemaakt.
rwijk@ORA10GR2> declare
2 cursor c1 is select t2_otype(seq_id,act,is_p,other) from t2 ;
3 t t2s;
4 begin
5 open c1;
6 fetch c1 BULK collect into t;
7 forall i in 1..t.count
8 insert into t3(seq_id) values (treat(t(i) as t2_otype).seq_id);
9 close c1;
10 end;
11 /
PL/SQL-procedure is geslaagd.On 11g, as said, you don't have to modify your code:
rwijk@ORA11G> create table t2
2 ( seq_id number,
3 act number,
4 is_p varchar2(1),
5 other varchar2(20)
6 );
Tabel is aangemaakt.
rwijk@ORA11G> insert into t2 values(1,2,'N','Test 1');
1 rij is aangemaakt.
rwijk@ORA11G> create table t3
2 ( seq_id number
3 -- ,act number
4 -- ,is_p varchar2(1)
5 );
Tabel is aangemaakt.
rwijk@ORA11G> declare
2 type t2_r is table of t2%ROWTYPE;
3 cursor c1 is select * from t2 ;
4 t t2_r;
5 begin
6 open c1;
7 fetch c1 BULK collect into t;
8 forall i in 1..t.count
9 insert into t3(seq_id) values (t(i).seq_id);
10 close c1;
11 end;
12 /
PL/SQL-procedure is geslaagd.Regards,
Rob. -
How can I see error when execute UPDATE with BULK COLLECT
Hi
I have a code
CURSOR c_renov_eleg IS
SELECT t2.ROWID
FROM mytable t2
WHERE BLA BLA BLA
OPEN c_renov_eleg;
LOOP
FETCH c_renov_eleg BULK COLLECT
INTO w_rowid LIMIT 1000;
FORALL i IN 1 .. w_rowid.COUNT
UPDATE mytable
SET id_baixa_elegibilidade = K_SCNOB_BXA_RENOVACAO,
column01 = arr_ciclo(1),
dt_ultima_atualizacao = SYSDATE,
cd_usuario_atualizacao = USER
WHERE ROWID = w_rowid(i);
COMMIT;
EXIT WHEN c_renov_eleg%NOTFOUND;
END LOOP;How can I to sse when and where have some error ? , in Exception return what record ?How can I to sse when and where have some error
?Have a look at
[url=http://download.oracle.com/docs/cd/B28359_01/appd
ev.111/b28370/tuning.htm#i49099]Handling FORALL
Exceptions (%BULK_EXCEPTIONS Attribute).btw. just never ever commit in a for loop ;)
(Tubby is just too fast ;))
Hi , thank all
btw. just never ever commit in a for loopWhen I must to COMMIT using BULK COLLECT ? -
Error in bulk collect into nested table
I keep getting an error while trying to compile this line:
fetch c_juros bulk collect into wrk_juros_plano(p_ind_segreg);
LINE/COL ERROR
0/0 PLS-00801: internal error [74306]When i put that single line into comments it goes fine. Sure it doesn't do what I want.
The data structure i use is as follows:
cursor c_juros(p_ind_segreg in varchar2) is
select (((power(1 + (i.prc_juros_atuari_ano / 100), 1 / 12) - 1) * 100) / 100) prc_juros_efetiv_mes,
i.dat_inic_vigenc,
(nvl(i.dat_fim_vigenc, sysdate) + 1) dat_fim_vigenc,
i.ind_segreg
from v_indexador_taxa_atuarial i
where i.ind_segreg = p_ind_segreg
order by i.dat_inic_vigenc;
type t_juros_plano is table of c_juros%rowtype;
type t_tab_juros_plano is table of t_juros_plano index by binary_integer;
wrk_juros_plano t_tab_juros_plano;the code goes like this:
begin
if not(wrk_juros_plano.exists(p_ind_segreg))
then
if c_juros%isopen
then
close c_juros;
end if;
open c_juros(p_ind_segreg);
wrk_juros_plano(p_ind_segreg) := t_juros_plano();
fetch c_juros bulk collect into wrk_juros_plano(p_ind_segreg);
end if;
...p_ind_segreg is my input parameter, that should be the index of the array.
The purpose is to create the parameter indexed element if it doesn't already exist, fetching it
from the cursor, that defines a nested table.
I tried removing the initialization line to no effect, among other things.Ok, I just found out a way around it. It works, but that error is probably a bug, cause workarounds are not really cute.
I declared a nested table compatible with the element from the associative array:
wrk_juros t_juros_plano;and chaged that line that was causing the error
fetch c_juros bulk collect into wrk_juros_plano(p_ind_segreg);for
fetch c_juros bulk collect into wrk_juros;
wrk_juros_plano(p_ind_segreg) := wrk_juros;Awesome =\
Maybe you are looking for
-
HP Color LaserJet 2840 misidentified as 2830
Hello, Everyone We were having problems with our HP Color LaserJet 2840 so I took it to a local computer store for repair. (The problems were that the printer was squeaking really bad, and tray 2 had ceased working...) So, I got it back from the sh
-
I have had some issues with Windows 8.1 on my Sony laptop, and Sony has told me that they recommend doing a factory reset on my computer and re-installing windows 8.1. I am concerned because I have Office 2013 installed on my computer, and my Univer
-
Invalid Data Type Exception Error in SAPBC
Hi All: We are using SAPBC as our middleware for communication between SAP and external billing application. We are trying to send PO in the form of IDocs (ORDERS) from SAP to the external application through SAPBC. The message type ORDERS in SAPBC h
-
Mouse-independant balloon-style tooltips
Hi, When the user enters invalid values inside a JTextComponent, I'd like to beep and pop up a balloon for two seconds discussing why his value was rejected. JToolTip is designed to display only when the mouse is over a certain component whereas I wa
-
What is the procedures to upgrade graphic card
I've just got a GT 120 graphic card and want to replace the old GT7300. (some articals say it works fine with 1st gen intel mac pro and say that install the driver first, but no driver cd in the upgrade kit) I've also upgrade to OS10.6. But I don't k