PLSQL stored procedures and functions

1. Storage process and overview

       ORACLE can store PL/SQL programs in the database and run them anywhere. This is called a stored procedure or function. Procedures and functions , collectively known as PL/SQL subroutines and named PL/SQL blocks, are stored in the database and exchange information with their callers through input and output parameters or input/output parameters. The only difference between procedures and functions is that functions always return data to the caller, while procedures do not.

1.1. Create a stored procedure statement

create [or replace] procedure stored procedure name [(parameter in|out|in out parameter data type,...)]

is|as

   reputation part;

begin

   plsql code block;

   exception

     Exception handling;

end;

1.2. Calling stored procedures

1. Call in plsql block    

       Write the name directly

2.call command call

       call stored procedure name();

3.execute command call

      Execute on the console. If you do not want to print the result, you need to run set serveroutput on;

1.3. Delete stored procedures

     drop procedure stored procedure name;

1.4. Three modes of stored procedure parameters  

     IN is used to accept the value of the calling program. Default parameter mode

     OUT is used to return a value to the calling program

     IN OUT is used to accept the value of the caller and return the updated value to the caller

2. Function

2.1. Statements to create functions

create [or replace] function function name [(formal parameter parameter type,...)]

return return value type

is

   claim variable;

begin

  plsql code block;

  return return value;

end;

2.2. How to access functions

1. Use SQL statements

      select function name from dual;

2. Using PL/SQL blocks

     declare

           v varchar2(30);

    begin

           v:=f1;

           dbms_output.put_line(v);

     end;

Guess you like

Origin blog.csdn.net/weekendholiday/article/details/127518887