Home > Database > Oracle > How to declare variables in oracle stored procedure

How to declare variables in oracle stored procedure

青灯夜游
Release: 2022-03-02 17:27:23
Original
13327 people have browsed it

How to declare variables in Oracle stored procedures: 1. Declare according to data type, syntax "variable name data type (size)"; 2. Use "%TYPE" declaration, syntax "variable name table name.field" Name %TYPE"; 3. Use "%ROWTYPE" statement, syntax "variable name table name %ROWTYPE".

How to declare variables in oracle stored procedure

The operating environment of this tutorial: Windows 7 system, Oracle 11g version, Dell G3 computer.

Declaration of variables in Oracle stored procedures

In Oracle stored procedures, there are three ways to declare variables:

1. Declare by data type

① Directly declare the data type

② Format: Variable name Data type (size)

V_TEST varchar2(20);
V_NUM  number;
Copy after login

Note: Variables declared in a stored procedure must be declared before begin

and the size must be specified when declaring a string, otherwise an error will be reported

2. Use %TYPE statement

①Format: Variable name table name.Field name%TYPE

②Meaning: The data type of this variable is consistent with the data type of the specified field of the specified table

V_NAME DFGZ_PKG.NAME%TYPE;
Copy after login

3. Use %ROWTYPE statement

①Format: Variable name table name%ROWTYPE

②Meaning: the data of the variable The type is consistent with the data type of the specified row record (all fields) of the specified table

--V_TOTALL_ROW 表的整行数据
V_TYPE_TOTALL_ROW  V_TOTALL_ROW%ROWTYPE;
Copy after login

Summary:

①The declaration of variables in Oracle's stored procedures is not size-sensitive Write

②The use of variables must be declared

Recommended tutorial: "Oracle Tutorial"

The above is the detailed content of How to declare variables in oracle stored procedure. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template