In-depth Oracle variable definition and usage

Source: Internet
Author: User

InProgramWhen defining variables, constants, and parameters, you must specify the PL/SQL data type for them. When compiling PL/SQL programs, you can use the scalar type, composite type, reference type, and lob (large
Object.
The most common scalar variable in PL/SQL is a scalar variable. when defining a scalar variable, you must specify the title data type. The title data types generally include: Numbers, characters, and dates, boolean type. Each type contains the corresponding subclass. For example, the number type contains sub-types such as integer and positive.

I. Common scalar types

1. varchar2 (N)

2. Char (N)

3. Number (P, S)

4. Date

5. Timestamp
This data type is added when 9i is used to define date and time data. The method used to assign values to the date variable is the same as that used to assign values to the date variable. However, when displayed, it not only displays the date, but also the time and the last afternoon Mark.

6. Long and long
Raw

7. Boolean

8. binary_integer

9. binary_float
Binary double and binary double are not many new types of oracle10.

Ii. Use scalar Variables

Variable assignment in PL/SQL is different from otherProgramming Language, You must add a colon (: =) before the equal sign ).

Eg:

Declare

X number;
Y number;

-- 7: Number of output digits. 3 is rounded to three digits (positive: three digits on the right of the decimal point, negative: three digits on the left of the decimal point)
Z number (7,3 );
Codeid
Number;
Begin
X: = 200.0088;
Y: = x + 10;
Z: = 1000.0088;

Dbms_output.put_line (X );
Dbms_output.put_line ('y = '| y );

Dbms_output.put_line ('z = '| z );
-- Assign a value to the variable codeid
Select sum (user_id)
Into codeid from hr_employee hr;

Dbms_output.put_line ('codeid = '| codeid );
Codeid: = codeid * 100;

Dbms_output.put_line ('codeid = '| codeid );
End;

The output is as follows:
X = 200.0088
Y = 210.0088
* Z = 1000.009
Codeid = 1045
Codeid = 104500

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.