Three parameter modes in, out, in out of Plsql

Source: Internet
Author: User

1, in mode

In mode is the default mode of the parameter, which is the value when the program is running, and the value does not change in the program body.

Error Examples:

1  Create or Replace procedureIn_proc (2P_ainch  Number,--Parameter , where the value is the actual argument passed at the call3P_binch  Number 4) as5 begin 6 P_a: = 10; -When the argument is passed in, the value in the program body cannot be changed by 7 p_b: =;8 Dbms_output. Put_Line (p_a);9 Dbms_output. Put_Line (p_b);Ten End;

Error log:

1Line/COL ERROR2 -------- -------------------------------------------3 6/5Pl/Sql:statement ignored4 6/5Pls-00363: An expression'p_a'cannot be used as an assignment target5 7/5Pl/Sql:statement ignored6 7/5Pls-00363: An expression'p_b'cannot be used as an assignment target

Note: The red area is the wrong code, and the value passed into the program body will not change.

2. Out mode

The parameters defined by the out pattern can only be assigned inside the procedure body, indicating that the parameter can pass a value to the call of the stored procedure.

Error Examples:

1 Create or Replace procedureOut_proc (2P_a out Number,--using out mode3P_b out Number 4) as 5 begin6Dbms_output. Put_Line ('p_a:' ||P_A);--Output parameter Values7Dbms_output. Put_Line ('p_b:' ||p_b);8 End;

At present, the OUT_PROC process does not assign values to the parameters, write a plsql block, and verify the process.

1 Declare2V_a Number;--Defining Variables3V_b Number ;4 begin5V_a:= Ten;--Assigning a value to a variable6V_b:=  - ;7Out_proc (V_a, V_b);--calling the Out_proc procedure8 End;

You can see that the values passed in the parameter are not printed at this time, so you can verify that the use of Out mode can not pass the value of the problem.

Program Modification:

1 Create or Replace procedureOut_proc (2P_a out Number,--using out mode3P_b out Number 4) as 5 begin6Dbms_output. Put_Line ('p_a:' ||P_A);--The parameter of the out pattern modifier is not to receive values passed in from the external procedure call7Dbms_output. Put_Line ('p_b:' ||p_b);
8P_a:= -;--assigning values to parameters in the procedure body9P_b:= $ ;Ten End;

Write Plsql block Validation:

1 Declare2V_a Number;--Defining Variables3V_b Number ;4 begin5V_a:= Ten ;6V_b:=  - ;7Out_proc (V_a, V_b);--calling the Out_proc procedure8 Dbms_output. Put_Line (v_a);9 Dbms_output. Put_Line (V_b);Ten End;

This time the value was successfully output. This verifies the previous question (the parameter defined in the out pattern can only be assigned within the procedure body, indicating that the parameter could pass a value to the call of the stored procedure).

In simple terms, out cannot receive the value passed in from the call of the procedure, only the parameter can be assigned within the procedure body, and then the value inside the process body can be passed to the invoked use of the process.

3, in Out mode

In out-of-the-ordinary means that both parameters can be passed to the process body and the values can be transferred from the process body.  

Example:

1 Create or Replace procedureInout_proc (2P_ainchOut Number,--Defining formal parameters3P_binchOut Number 4) as 5 begin 6 dbms_output.  Put_Line (' p_a ' passed into the process body:  ' | | p_a); -- the printout procedure invokes the passed-in argument 7 Dbms_output. Put_Line (' p_b ' passed into the process body:  ' | | p_b);  8 p_a:=  +; -- assigning values to parameters in the procedure body 9 p_b:=  $ ; Ten End;

Write a plsql block to verify the process

1 Declare2V_a Number;--Defining Variables3V_b Number ;4 begin5V_a:= Ten;--Assigning a value to a variable6V_b:=  - ; 7 inout_proc (v_a, V_b); -- call Inout_proc to pass the argument in  8 dbms_output.   Put_Line (' v_a ' passed into the process body:  ' | | v_a); -- the value of the output being modified in the procedure body 9 Dbms_output. Put_Line (' v_b ' passed into the process body:  ' | | v_b); Ten End;

Execution Result:

1 Ten 2   -  34 

In-out is simply the actual argument passed at the procedure call, which is received in the process body. And the value of the parameter assignment in the procedure body is also passed to the procedure call.

< Span lang= "ZH-CN" > < Span lang= "ZH-CN" > < Span lang= "en-US" >  

Beginner understanding too shallow please point out the error!

Three parameter modes in, out, in out of Plsql

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.