Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

PL/SQL insert not working

user476243Sep 27 2012 — edited Sep 29 2012
Not sure what I am doing wrong. Pretty sure it is something silly.

Wondering why the row is not inserting:
scott@ORA11GR2> create table dept1 as select * from dept where rownum < 2;

Table created.

scott@ORA11GR2> select * from dept1;

    DEPTNO DNAME          LOC
---------- -------------- -------------
        10 ACCOUNTING     NEW YORK

scott@ORA11GR2> create table dept2 as select * from dept1 where 1=2;

Table created.

scott@ORA11GR2> select * from dept2;

no rows selected

scott@ORA11GR2> 

declare
   v_deptno  NUMBER;
   v_dname dept1.dname%TYPE;
   v_loc   dept1.loc%TYPE;
begin
        select deptno, dname, loc
        into v_deptno, v_dname, v_loc
        from dept1;
end;
/ 

PL/SQL procedure successfully completed.


scott@ORA11GR2> select * from dept2;

    DEPTNO DNAME          LOC
---------- -------------- -------------


declare
  v_deptno  NUMBER;
  v_dname dept2.dname%TYPE;
  v_loc   dept2.loc%TYPE;
begin
  insert into dept2 (deptno, dname, loc) values (v_deptno, v_dname, v_loc);
end;
/

PL/SQL procedure successfully completed.

scott@ORA11GR2> select * from dept2;

no rows selected
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 27 2012
Added on Sep 27 2012
6 comments
3,085 views