Stored procedures and stored functions [parameter description of out]

I. Overview

Stored procedure: It is a section of pl / sql language that has been compiled in advance, placed on the database side, and can be called directly. Generally, this pl / sql statement is a fixed-step business.

2. Grammar [Store Procedure]

1. Template

create or replace procedure 过程名(变量名 【输出类型】 数据类型)
is
begin
  sql语句

end;

2. Grammar analysis
image

1.rar

3. Examples

image

4. Grammar [stored function]

1. Template

create or replace function 函数名(变量名 输出类型 数据类型)
retrun 返回值数据类型
is 返回值变量名称 数据类型
begin
  return(返回值);
end;

2. Grammar analysis

image

2.rar

V. Examples

(1) Storage path

image

(2) Method demonstration

image

image

6. Differences and details of stored functions and stored procedures

1. Details

The key word of the stored procedure is procedure, and the key word of the stored function is function.

The parameters of stored procedures and stored functions cannot take length. [Except for reference data types]

Stored functions have a return value type, but they cannot be written in length.

2. Difference

1. The key word of stored procedure is procedure, and the key word of stored function is function.

2. The stored function has two more returns than the stored procedure.

3. The essential difference is that stored procedures have no return value, while stored functions have return values.

If the stored procedure requires a return value, you must use the return value parameter of type out.

Even if the return value parameter of the out type is set in the stored procedure, it does not really have a return value in essence, but we internally assign a value to out in the stored procedure, and after executing the code, we directly get the value of the output type parameter .

4. We can use the stored function's return value feature to customize the function.

Stored procedures cannot be used to define functions.

Seven.out type parameters

1. How to use the out parameter

image

2. The difference between in and out

All parameters that involve the assignment of into query statements or: = assignment operations must be decorated with out.

8. The practical application of stored functions [Comparison of stored functions and traditional queries]

1. Case

Query the employee's name and department information.

2. Examples

image

Published 63 original articles · won praise 20 · views 6817

Guess you like

Origin blog.csdn.net/qq_45421186/article/details/105470554