Is there a way in oracle PL/SQL to execute a SQL statement. I'm coming from a MS SQL environment to oracle, and in MS SQL we have an EXEC command to execute statement such as:
EXEC('select * from table')
Is there an equivalent in Oracle (8.1.7)?
Thanks in advance
Well kind of... there is EXECUTE IMMEDIATE, but for the example you gave it wouldn't do very much:
2 EXECUTE IMMEDIATE 'select * from table';
PL/SQL procedure successfully completed.
It worked, but the result doesn't appear anywhere.
You can open a cursor for the select like this:
TYPE rc_type REF CURSOR;
OPEN rc FOR 'select * from table';
FETCH rc INTO table_rec;
EXIT WHEN rc%NOTFOUND;
-- Process this row, e.g.
DBMS_OUTPUT.PUT_LINE( 'Name: '||table_rec.name );