Question:
I am writing a block of code. I am inserting the statement 'Select * from employee' in PLSQL block.
Is this possible? If yes, how can you do it? If no, What is the error thrown during compilation?
Answer:
Answer is both YES and NO. Dont get confused.
If you are to say 'YES', go with the below answer.
Yes. It can be done using DYNAMIC SQL concept.
You can either use DBMS_SQL or EXECUTE IMMEDIATE
set serveroutput on
begin
execute immediate 'Select * from dual';
end;
/
If you are to say 'NO', justify as below.
No. Because a Select statement should have INTO clause with statement structure.
set serveroutput on
begin
Select * from dual;
end;
/
Error report:
ORA-06550: line 2, column 1:
PLS-00428: an INTO clause is expected in this SELECT statement
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
I am writing a block of code. I am inserting the statement 'Select * from employee' in PLSQL block.
Is this possible? If yes, how can you do it? If no, What is the error thrown during compilation?
Answer:
Answer is both YES and NO. Dont get confused.
If you are to say 'YES', go with the below answer.
Yes. It can be done using DYNAMIC SQL concept.
You can either use DBMS_SQL or EXECUTE IMMEDIATE
set serveroutput on
begin
execute immediate 'Select * from dual';
end;
/
If you are to say 'NO', justify as below.
No. Because a Select statement should have INTO clause with statement structure.
set serveroutput on
begin
Select * from dual;
end;
/
Error report:
ORA-06550: line 2, column 1:
PLS-00428: an INTO clause is expected in this SELECT statement
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
Comments