Can i call a pl/sql object by procedure or function from within an anonymous block?
This is a very frequent interview question.
Thanks
Yes:
SQL> set serveroutput on
SQL> --
SQL> select banner from v$version;
BANNER
--------------------------------------------------------------------------------
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
SQL> show user;
USER is "C##TEST"
SQL> --
SQL> CREATE OR REPLACE PROCEDURE myproc
2 IS
3 BEGIN
4 dbms_output.put_line('myproc: OK');
5 END;
6 /
Procedure created.
SQL> --
SQL> show errors
No errors.
SQL> --
SQL> CREATE OR REPLACE FUNCTION myfunc RETURN VARCHAR2
2 IS
3 BEGIN
4 return 'myfunc: OK';
5 END;
6 /
Function created.
SQL> --
SQL> show errors
No errors.
SQL> --
SQL> begin
2 myproc;
3 end;
4 /
myproc: OK
PL/SQL procedure successfully completed.
SQL> --
SQL> declare
2 myvar VARCHAR2(50);
3 begin
4 select myfunc into myvar from dual;
5 dbms_output.put_line(myvar);
6 end;
7 /
myfunc: OK
PL/SQL procedure successfully completed.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.