Pl/sql block definition part of a scalar type

Source: Internet
Author: User
Tags constant integer scalar

The definition section mainly defines variables and constants, and the syntax is as follows:

DECLARE

Virablename [CONSTANT] dataType [NOT null][:=|default exp or value];

The following guidelines should be followed when naming variables or constants:

1, variable name can only start the letter, other bits can contain _, $, #和数字

2, Length 1-30

3, case-insensitive

4, cannot be the system key word

The constant keyword represents the definition of a constant, which must be given an initial value, and the value cannot be changed again.

DataType is a data type, note that the data type here is the Pl/sql data type, not the SQL data type that the table uses.

Not NULL represents a variable or a constant is not allowed to be null, and must provide a Non-null initial value when defined.

The following code code defines variables and constants:

DECLARE
credit_limit     CONSTANT NUMBER :=5000;--常量
invalid          BOOLEAN := FALSE;--布尔类型变量
acct_id          INTEGER(4) NOT NULL default 9999;--必须附初值的变量
pi               CONSTANT REAL := 3.14159;--浮点数常量
postal_code      VARCHAR2(20);--与VARCHAR2(20 BYTE)同义
last_name        VARCHAR2(20 CHAR);--变量
my_ename         emp.ename%TYPE;--与emp表的ename列数据类型相同

The Pl/sql data types are divided into four categories, scalar types, composite types, reference types, and LOB types.

One, scalar type

The meaning of a scalar type is that it holds a single value. The scalar types are divided into shaping, numbers, characters, dates, and Boolean types.

1, Binary_integer

The range is aninteger from -2 to--2, and if the floating-point number is assigned to the type, the floating-point number is rounded to the integer and then assigned to the type. In addition, there are several subtypes of the type:

NATURAL 0-2 range of integers

POSITIVE 1-2 range of integers

NATURALN does not allow null values, other same natural

Positiven does not allow null values, other same positive

Signtype symbol type, only three values allowed-1 0 13 values

Note: Binary_integer and its subtypes are pl/sql data types, not SQL data types, that is, they cannot be used when creating tables.

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.