Follow-up of chapter 1 of PL/SQL

Source: Internet
Author: User

3.2. Compound Variables

Composite variables are used to store multiple values. When you define a composite variable, you must use the PL/SQL Composite data type.
PL/SQL includes PL/SQL records, PL/SQL tables, nested tables, and varray.

2. PL/SQL table
When using a PL/SQL table, you must first define the PL/SQL table type and PL/SQL table variables in the definition section, and then execute
Reference the PL/SQL table variable, for example:

-- Note: ename_table_type indicates the PL/SQL table type. EMP. ename % Type specifies the data type and length of PL/SQL table elements.

;
-- Ename_table is a PL/SQL table variable, and ename_table (-1) indicates an element whose subscript is-1.
Declare
Type ename_table_type is table of EMP. ename % Type
Index by binary_integer;
Ename_table ename_table_type;
Begin
Select ename into ename_table (-1) from EMP where empno = 7788;
Dbms_output.put_line ('employee name: '| ename_table (-1 ));
End;

3.2.5 non-PL/SQL Variables

When a non-PL/SQL variable is referenced in a PL/SQL block, you must add a colon (":") before the non-PL/SQL variable (":")

1. Use the SQL * Plus variable

When referencing the SQL * Plus variable in PL/SQL blocks, you must first use the variable command to define the variable.

To output the variable content, use the print command.

Example:
SQL> var name varchar2 (10)
SQL> begin
2 select ename into: name from EMP where empno = 7788;
3 end;
4/

The PL/SQL process is successfully completed.

SQL> Print name;

Name
--------------------------------
Scott


3.3 compile PL/SQL code
 
1. separator: Refers to a single or combination of symbols with a specific meaning.
Single-symbol separators perform arithmetic operations; combined separators perform value assignment operations (: =) and comparison operations (> = ).
Symbol Meaning
% Attribute prompt
'String Separator
. Component Separator
: Non-PL/SQL variable prompt
@ Remote database access operator
: = Value assignment operator
| Connection Operator
<Start of the label Separator
> End of the separator
"Double quotation mark variable Separator
** Power operators

2. The identifier is used to specify the names of PL/SQL program units and program items.
Define rules:
1. When using identifiers to define variables and constants, each line can only define one identifier.
2. When you use an identifier to define a variable or constant, the identifier name must start with A-Z, A-Z, If you want other characters to start,

Double quotation marks are required.
3. When using identifiers to define variables, constants, identifiers names can only use A-Z, A-Z, 0 ~ 9, _, $, and #. If you want

To start with other characters, you must use double quotation marks.
4. The identifier cannot use the Oracle keyword.

3. Text

In Oracle 10 Gb, if the string text contains single quotes, you can assign values in the original format or use other

Separators ([], {}, <>, etc.) are assigned values. Note: If you want to assign values to strings using separators [], {}, and <>

The separator is enclosed in single quotes and must contain the prefix Q.
Example: String Var = Q' [I'm a sting]'

3.3.2 PL/SQL coding rules
1. identifier command rules
A. when defining a variable, we recommend that you use V _ as the prefix, such as v_sal.
B. When defining constants, we recommend that you use C _ as the prefix, for example, c_rate.
C. when defining a cursor, we recommend that you use _ cursor as the suffix, for example, emp_cursor.
D. When defining exceptions, we recommend that you use E _ as the prefix, for example, e_error.
E. When defining PL/SQL table types, _ table_type is recommended as the suffix, for example, sal_table_type
F. when defining the PL/SQL record type, _ record_type is recommended as the suffix, for example, emp_record_type.
G. When defining PL/SQL record variables, _ record is recommended as the suffix, for example, emp_record

2. Case sensitivity rules
In uppercase format: SQL keywords, PL/SQL keywords, and Data Types
Lowercase format: identifier, parameter, database object, and column

5. SQL functions used in PL/SQL Blocks

 

 

 

 

 

 

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.