Directory
Data type
Defining variables
PL/SQL Control structure
Reference oracle10g data Types Summary PL/SQL basic articles
Data type
Learning Summary
Character type
Char, nchar, varchar, nvarchar: There are n characters stored with no n in bytes storage, VAR is variable, storage space is stored in the actual size, no var is fixed size, from the space to be padded.
Number Type
Number (P[,s]): Fixed-point numbers, S is the number of decimal digits
Binary_float:32 bit single-precision floating-point number type
binary_double:64-bit double-precision floating-point number type.
Time Type
Date
Defining variables
Resources
Oracle User Manual (i)---declaring variables
You can use: = To assign values when defining variables
1. Define BASIC variables
Such as: Declare variable name variable type
2. Define%type with attributes
Can be a property of a table field or variable
declare name Tablename.fieldname%type;
DECLARE name2 Name%type
3, using%rowtype, define the variable is a row of the table
Delcare Row Tablename%rowtype
4. Define record type variables-record data types that bundle multiple base data types together.
Syntax: Type record name is record (definition base type)
Set Serveroutput on
Declare
Type Myrecord is record (
Sid Int,
Sdate date);
Srecord Myrecord; --Declare an instance of a custom record type variable
Begin
Select Sid,sdate into Srecord from student where sid=68;
Dbms_output.put_line (' ID: ' | | srecord.sid | | ' Date: ' | | Srecord.sdate); --' | | ': It is a string connector.
End
5. Table Type variables
Grammar:
TYPE table_name is table of data_type [not NULL]
INDEX by Binary_integer;
The syntax is described as follows:
--table_name the name of the table type created.
The--is table indicates that a table type was created.
--data_type can be any of the legitimate PL/SQL data types, such as VARCHAR2.
--index by Binary_integer Specifies that the system creates a primary key index that refers to a specific row in a table-type variable.
Declare a table with only one field:
Declare
Type Tabletype1 is Table of VARCHAR2 (4) index by Binary_integer;
Mytable1 Tabletype1
A table that declares multiple fields
Declare
Type Tabletype1 is table of Student%rowtype index by Binary_integer;
Table1 Tabletype1;
Type tabletype2 is table of record type variable index by Binary_integer
Table2 taabletype2
DECLARENumber (7, 2): = 1234.33;--Initial value Field1 tablename.fieldname%type-- field2 field1% type declared with table field -- declare with variable attributes
PL/SQL Control structure
1. If
Oracle PL/SQL Syntax basics