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