Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

PL/SQL statement

2025-01-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

I. naming convention

Naming method

Naming method

Applicable

UserPrivilege is suitable for people who are good at English, and like cadence and artistic beauty. Userprivilege is suitable for those who are good at English and are more rigorous. Tbl_user_prifilege is suitable for those who do development (my commonly used naming convention). Yhqx loves Chinese.

Do not use keywords

You can refer to the query results as follows

SELECT * FROM V$RESERVED_WORDS WHERE RESERVED='Y'

Length

1x 30 characters

Second, define constant

Syntax: constant name constant data type identifier [not null]: = value

Example:

I_count constant Int not null:=200-defines a constant i_count with a value of 200; III. Define basic data type variables

Syntax: variable name type identifier [not null]: = value

Example:

Sex Boolean not null: = 0;-define variable sex value is 0; fourth, use% TYPE to define variable

The purpose of this type is to make the data type of the variable consistent with the data type in the table. After it is defined, the data type in the table changes, and so does the data type of the variable.

Syntax: variable name, user name. Table name. Field name TYPE

Example:

The sex SCOTT.Tdetails.SEX%TYPE;-sex variable is the same as the sex field in the Tdetails table under the scott user. 5. Record type variable

A record type stores logically related data as a unit. It must include at least one member of the scalar or RECORD data type, a FIELD called PL/SQL RECORD, whose function is to store different but logically related information.

Syntax:

TYPE variable name IS RECORD (variable name 1 basic data type, variable name 2 basic data type,...)

Example:

TYPE tRecords IS RECORD (Name varchar2, Sex Boolean); ttt tRecords;-- the method Select name,sex into ttt from classuser; that uses this variable-- thus puts the data in the classuser table into the variable ttt. Define variables using% ROWTYPE

Make the type of the child variable of the defined variable consistent with the data type of the corresponding field in the table.

Syntax: variable name, user name. Table name TYPE

Example:

DECLARE to_records tdetails%ROWTYPE; BEGIN SELECT * INTO to_records FROM tdetails where type='pay'; DBMS_OUTPUT.PUT_LINE (to_records.object | |'| | toRecords.money | |'| | toRecords.payDate); END; 7. Define one-dimensional table type data

Equivalent to an one-dimensional array

Syntax: TYPE table type IS TABLE OF type INDEX BY BINARY_INTEGER

Example:

TYPE score IS TABLE OF INT (3) INDEX BY BINARY_INTEGER;-defines an array of integers with a capacity of 3; score (1) = 1 position score (2) = 2;... -- use it when visiting

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report