Home » SQL & PL/SQL » SQL & PL/SQL » Why require insert into command
Why require insert into command [message #38461] Thu, 18 April 2002 16:39 Go to next message
Sid
Messages: 38
Registered: May 1999
Member
Why do I have to have the command "insert into" when doing this select query?

DECLARE
v_result dept.deptno%type;
BEGIN
select deptno
into v_result -- simple test to find why cannot leave this line out
from dept
where deptno = 20;

END;
/

If you leave out the clause it gives the following errors:

*
ERROR at line 4:
ORA-06550: line 4, column 2:
PLS-00428: an INTO clause is expected in this SELECT statement
ORA-06550: line 4, column 2:
PL/SQL: SQL Statement ignored
Re: Why require insert into command [message #38462 is a reply to message #38461] Thu, 18 April 2002 17:51 Go to previous messageGo to next message
seng
Messages: 191
Registered: February 2002
Senior Member
This error is confuse only. it is mean that your statement is wrong. it should look like below

INSERT INTO table1 SELECT * FROM table2;

note: table1 is similar to table2.

Hope this is helping
Re: Why require insert into command [message #38466 is a reply to message #38461] Fri, 19 April 2002 05:50 Go to previous message
Mahesh Rajendran
Messages: 10707
Registered: March 2002
Location: oracleDocoVille
Senior Member
Account Moderator
if u give the sql statement after begin, u have to use select ...into ... from table;
******
ex
******
declare
a number;
begin
select empno into a from emp;
end;

but if u use the sql before begin no need to give into satement.

declare
cursor c1 is select * from emp;
begin
for mag in c1 loop
exit when c1%notfound;
dbms_output.put_line(mag.empno);
end loop;
end;
..............
Previous Topic: Primary key and unique key
Next Topic: Parsed SQL
Goto Forum:
  


Current Time: Fri Apr 26 08:52:52 CDT 2024