常量
常量名 constant 類型標識符 [not null]:=值;
常量
在【SQLPlus Worksheet】中執行下列PL/SQL程序
執行結果如圖
―――――――――――――――――――――――――――――――――――――
declare
pi constant number(
begin
commit;
end;
―――――――――――――――――――――――――――――――――――――
【配套程序位置】

基本數據類型變量
PL/SQL中常用的基本數據類型如表
表
類型標識符 說明
Number 數字型
Int 整數型
Pls_integer 整數型
Binary_integer 整數型
Char 定長字符型
Varchar
Long 變長字符型
Date 日期型
Boolean 布爾型(TRUE
在PL/SQL中使用的數據類型和Oracle數據庫中使用的數據類型
變量名 類型標識符 [not null]:=值;
在【SQLPlus Worksheet】中執行下列PL/SQL程序

―――――――――――――――――――――――――――――――――――――
declare
age number(
begin
commit;
end;
―――――――――――――――――――――――――――――――――――――
【配套程序位置】
復合數據類型變量
下面介紹常見的幾種復合數據類型變量的定義
為了讓PL/SQL中變量的類型和數據表中的字段的數據類型一致
在【SQLPlus Worksheet】中執行下列PL/SQL程序
執行結果如圖
―――――――――――――――――――――――――――――――――――――
Declare
mydate tempuser
begin
commit;
end;
―――――――――――――――――――――――――――――――――――――
【配套程序位置】

很多結構化程序設計語言都提供了記錄類型的數據類型
下面的程序代碼定義了名為myrecord的記錄類型
程序的執行部分從tempuser
在【SQLPlus Worksheet】中執行下列PL/SQL程序
―――――――――――――――――――――――――――――――――――――
set serveroutput on
declare
type myrecord is record(
myrecordnumber int
mycurrentdate date);
srecord myrecord;
begin
select * into srecord from tempuser
dbms_output
end;
―――――――――――――――――――――――――――――――――――――
【配套程序位置】
在PL/SQL程序中

使用%type可以使變量獲得字段的數據類型
在【SQLPlus Worksheet】中執行下列PL/SQL程序
―――――――――――――――――――――――――――――――――――――
Declare
mytable testtable%rowtype;
begin
select * into mytable
from tempuser
where recordnumber=
dbms_output
end;
―――――――――――――――――――――――――――――――――――――

【配套程序位置】
表類型變量和數據表是有區別的
―――――――――――――――――――――――――――――――――――――
type 表類型 is table of 類型 index by binary_integer;
表變量名 表類型;
―――――――――――――――――――――――――――――――――――――
類型可以是前面的類型定義
在【SQLPlus Worksheet】中執行下列PL/SQL程序
執行結果如圖
―――――――――――――――――――――――――――――――――――――
Declare
type tabletype
type tabletype
table
table
begin
table
table
table
table
dbms_output
dbms_output
end;
―――――――――――――――――――――――――――――――――――――
【配套程序位置】

在【SQLPlus Worksheet】中執行下列PL/SQL程序
―――――――――――――――――――――――――――――――――――――
Declare
type tabletype
table
begin
select * into table
from tempuser
where recordnumber=
dbms_output
end;
―――――――――――――――――――――――――――――――――――――
【配套程序位置】

在定義好的表類型變量裡
在【SQLPlus Worksheet】中執行下列PL/SQL程序
執
From:http://tw.wingwit.com/Article/program/Oracle/201311/17639.html