Oracle Reading Notes-basic data type and program structure of PL/SQL programming (1)

Source: Internet
Author: User

PL/SQLIt is an efficient transaction processing language and has the following advantages:

1. SupportSQL

2. Support for Object-Oriented Programming

3. better performance and higher efficiency

4. Easy to write

5.OracleHighly integrated

6. Good Security

 

I. PL/SQLVariables and basic data types

1. PL/SQLVariable definition

The basic data type variables are defined as follows:

Variable name type identifier[: =Value];

For example: STR varchar2 [1, 100]: ='China';

You can also use keywordsDefaultTo replace the value assignment.

STR varchar2 [100] default'China';

Note: The values matching the colon and equal sign cannot be separated;

 

 

2. Basic Data Types

 

Iii. PL/SQLProgramStructure

First, let's look at a simple example:The following is a completePL/SQLProgram used to evaluate EquationsAx2.+ Bx + c = 0Root

 

1   Declare  2 A Int : =   3  ;  3 B Int : =   8  ;  4 C Int : =  2  ;  5 X1 Number ( 8 , 2  );  6 X2 Number ( 8 , 2  );  7 T Number (8 , 2  );  8   Error exception;  9   Begin  10 T: = B **  2  -  4  * A * C;  11     If T <  0   Then  12   Raise error;  13     End   If  ;  14 X1: = ( - B + SQRT (T) / ( 2  *  A ));  15 X2: = (B +  SQRT (T) / ( 2  *  A ));  16 Dbms_output.put_line ( ' X1 =  '  |  X1 );  17 Dbms_output.put_line ( '  X2 =  '  |  X2 );  18   Exception  19      When Error Then Dbms_output.put_line ( ' No solution to this equation  '  );  20   End ;

 

 

We can see from the abovePL/SQLPrograms are divided3Parts:

 

1) definition section.InPL/SQLThe constants, variables, and cursors used in the program must be defined in this section.

However, variable definitions in this section cannot be separated by commas to declare multiple variables at the same time.

A semicolon represents the declaration of each variable and the terminator of the statement.

IfPL/SQLIf no variables need to be defined in the program, this part can be removed.

 

 

2) execution part.This part isPL/SQLThe core part of the program, including the value assignment statement, database operation statement, and process control statement.PL/SQLThe Basic Block Structure of the program.

The execution part must have at least one executable statement.

 

 

3) Exception Handling Section.An exception occurs when the program detects an error. ByExceptionIdentify to handle exceptions in the program process.

 So onePL/SQLThe basic structure of a program can be:

Declare

Definition

Begin

Execution part

Exception

Exception Handling

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.