Detailed explanation of the definition and use of Oracle variables _c language

Source: Internet
Author: User

When you define variables, constants, and parameters in your program, you must specify the Pl/sql data type for them. When writing Pl/sql programs, you can use scalar (Scalar) types, composite (composite) types, reference (Reference) types, and lobs (Large
Object) type, etc. four types.
The most used in Pl/sql is the scalar variable, which, when defined, must specify the header data type, and the header data type generally includes: numeric type, character type, date type, Boolean type, and each type contains the corresponding subclass, for example, the number type contains an integer, Positive and other subtypes.

First, commonly used scalar types

1.VARCHAR2 (N)

2.CHAR (N)

3.NUMBER (P,s)

4.DATE

5.TIMESTAMP
The data type is incremented at 9i, and it is also used to define date and time data. The method to assign a value to it is exactly the same as the method that assigns the date variable. But when displayed, it not only displays the date, but also displays the time and the afternoon mark.

6.LONG and Long
RAW

7.BOOLEAN

8.binary_integer

9.binary_float
And BINARY DOUBLE These two types are ORACLE10 new added when used not a lot of

Second, the use of scalar variables

Assigning values to variables in Pl/sql differs from other programming languages, and you must precede the equals sign with a colon (: =).

eg

DECLARE

X number;
Y number;

--7: Output Several number, 3 is rounded three digits (positive: decimal point right three digits, negative: three digits to 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);
--Assigning values to variable Codeid
SELECT SUM (user_id)
Into the Codeid from Hr_employee hr;

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

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

Print the results as follows:
x=200.0088
y=210.0088
z=1000.009
codeid=1045
codeid=104500

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.