Click here to Skip to main content
15,881,852 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have declare one varaible i.e. srID
then passed value to it from select query then i am trying to pass this variable value insert
in insert statment but it giving me following error:

PL/SQL: ORA-00984: column not allowed here


below is my query---

SQL
declare srID Number;
        begin
        select max(ID)+1 as ID  into srID from table1;
        end;

         INSERT INTO table2 (ID)
         VALUES(srID)
Posted
Updated 30-Jul-13 2:44am
v2

Have a look here: http://www.dba-oracle.com/t_ora_00984_column_not_allowed.htm[^] and try your code without AS ID part:
SQL
declare srID Number;
BEGIN
    SELECT ID INTO srID
    FROM (
        SELECT MAX(ID)+1 AS ID
        FROM table1
        ) AS T;
END;

 INSERT INTO table2 (ID)
 VALUES(srID)



Second way:
SQL
INSERT INTO table2 (ID)
SELECT MAX(ID)+1 AS ID
FROM table1

http://docs.oracle.com/cd/E17952_01/refman-5.1-en/insert-select.html[^]
 
Share this answer
 
v4
Comments
Pro86 30-Jul-13 8:53am    
not work for me still giving same error
Maciej Los 30-Jul-13 9:02am    
See my unswer after update ;)
Pro86 30-Jul-13 9:11am    
this is right but actually i want to use same value in many insert statement
thats why i am trying to store in varible so i can use it in many time
Maciej Los 30-Jul-13 9:17am    
See my answer now ;)
Maciej Los 30-Jul-13 9:27am    
Please see note in here: http://psoug.org/definition/INTO.htm[^]
You should use a sequence to generate keys for your table, perhaps something like this:

Create the sequence:
CREATE SEQUENCE mySequence
  MINVALUE 1
  MAXVALUE 999999999999999999999999999
  START WITH 1
  INCREMENT BY 1
  CACHE 20;

Use the sequence to generate unique primary keys for the table:
INSERT INTO myTable (id, name)
VALUES (mySequence.nextval, 'Oh my ;-)');


Best regards
Espen Harlinn
 
Share this answer
 
Comments
Jörgen Andersson 31-Jul-13 17:16pm    
To paraphrase Mycroft: this is the solution, not the answer.
Espen Harlinn 31-Jul-13 17:23pm    
Thank you, Jörgen - and yes you're quite right ;-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900