Oracle Learning (eight) Pl/sql Introduction, BASIC program structure and statements

Source: Internet
Author: User
Tags oracle database

1. Variable

2. Constant

3. Basic program Structure and statement

Pl/sql can reside in both Oracle database servers and Oracle development tools environments. In both environments, the Pl/sql engine accepts any pl/sql block and subroutine as input, and the engine executes a procedure statement that sends the SQL statement to the SQL statement executor executed by the Oracle server.

1, Pl/sql variable

(1) The declaration of the variable:

Variables are usually defined in the Declarations section of a pl/sql block, and each variable has a specific type.

The basic format for a variable definition is:

< variable name > < data type >[(width):=< initial value

For example, define a number type variable named Countnum, with an initial value of 1, which can be written as follows:

Countnum number: = 1;

--The basic naming rules for variables are as follows:

--a. Variable names must begin with a letter

--b. Variable length not exceeding 30 characters

--c. Cannot have spaces in variable names

(2) The properties of the variable

% is used to represent property prompts.

%type property. The%type property provides properties for variables and database columns. This property is very convenient, assuming that there is a table A, there is a field B, now to define a variable C, it needs its data type and field B, this time we can not know the data type of B, the direct use of b%type can be, such as: C B%type.

%rowtype property. This property provides a data type that represents one row of records in a table. With it, we can easily use a variable to represent a row in a cursor, such as Cursorrecord Cursorname%rowtype, where Cursorrecord represents a variable name on one row of the cursor, Cursorname represents the name of the corresponding cursor, using% RowType can be taken to a row of record types, so that later in the data, you can directly use the

Fetch cursorname into Cursorrecord. Sample code:

DECLARE CURSOR modulecursor is
      
      
select * from T_module;  
      
      
Modulerecord Modulecursor%rowtype;  
      
      
Begin
      
      
  Open modulecursor;  
      
      
  Fetch modulecursor into Modulerecord;  
      
      
  While Modulecursor%found   
      
      
  loop  
      
      
    dbms_output.put_line (Modulerecord.name | | '**********************');  
      
      
    Fetch modulecursor into Modulerecord;  
      
      
  End Loop;  
      
      
  Close modulecursor;  
      
      
End

Related Article

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.