Invalid reference to variable, ORA-22806: not an object or REF [message #622659] |
Thu, 28 August 2014 06:02 |
|
lvrvln
Messages: 5 Registered: August 2014
|
Junior Member |
|
|
Hi Team
Please help me on below issue
DROP TABLE test PURGE;
CREATE TABLE test (id NUMBER);
DROP TABLE test1 PURGE;
CREATE TABLE test` (id NUMBER);
BEGIN
INSERT INTO test
VALUES (1);
INSERT INTO test
VALUES (2);
INSERT INTO test
VALUES (3);
INSERT INTO test
VALUES (4);
INSERT INTO test
VALUES (5);
INSERT INTO test
VALUES (6);
INSERT INTO test
VALUES (7);
INSERT INTO test
VALUES (8);
COMMIT;
END;
BEGIN
INSERT INTO test1
VALUES (1);
INSERT INTO test1
VALUES (7);
INSERT INTO test1
VALUES (8);
COMMIT;
END;
SELECT * FROM sad1;
DECLARE
TYPE t1 IS TABLE OF test1.id%TYPE;
a_id t1;
a NUMBER;
BEGIN
SELECT id
BULK COLLECT INTO a_id
FROM test
WHERE id NOT IN (SELECT id
FROM test1
WHERE test.id = test1.id);
FOR r IN 1 .. a_id.COUNT
LOOP
INSERT INTO test1 VALUES (a_id(r).id);
a := SQL%ROWCOUNT;
DBMS_OUTPUT.put_line (a);
END LOOP;
END;
I am getting below error.
ORA-06550: line 16, column 34:
PLS-00487: Invalid reference to variable 'TEST1.ID%TYPE'
ORA-06550: line 16, column 34:
PL/SQL: ORA-22806: not an object or REF
ORA-06550: line 16, column 9:
PL/SQL: SQL Statement ignored
please help me to solve above error
Lalit :
1. Added code tags
2. Changed topic name from "Need Help" to something meaningful
[Updated on: Thu, 28 August 2014 06:15] by Moderator Report message to a moderator
|
|
|
|
|
|
|
|
Re: Need Help [message #622720 is a reply to message #622667] |
Thu, 28 August 2014 12:58 |
Solomon Yakobson
Messages: 3273 Registered: January 2010 Location: Connecticut, USA
|
Senior Member |
|
|
Or you could use database types. And there is even no need to create one, we can use pre-defined type sys.OdciNumberList:
DECLARE
v_id_list sys.OdciNumberList;
v_cnt number;
BEGIN
SELECT id
BULK COLLECT INTO v_id_list
FROM test
WHERE id NOT IN (SELECT id
FROM test1
WHERE test.id = test1.id);
INSERT INTO test1 SELECT * FROM TABLE(v_id_list);
v_cnt := SQL%ROWCOUNT;
DBMS_OUTPUT.put_line(v_cnt);
END;
/
5
PL/SQL procedure successfully completed.
SQL>
And, of course, there is no need for PL/SQL here at all. It can be done with single SQL:
SQL> INSERT
2 INTO test1
3 SELECT id
4 FROM test
5 WHERE id NOT IN (SELECT id
6 FROM test1
7 WHERE test.id = test1.id);
5 rows created.
SQL>
SY.
SY.
|
|
|
|
Re: Need Help [message #622728 is a reply to message #622721] |
Thu, 28 August 2014 13:35 |
|
Michel Cadot
Messages: 68645 Registered: March 2007 Location: Nanterre, France, http://...
|
Senior Member Account Moderator |
|
|
Yes I didn't populate it, I just populated the first table and focused on the code.
Sorry for any misleading.
|
|
|