--type用于定于不确定的数据类型
declare
v_fd_change_left EKP_CHANGE.fd_change_left%type; --v_id是表name的id的数据类型
v_fd_change_total EKP_CHANGE.fd_change_total%type;
begin
select fd_change_left,fd_change_total
into v_fd_change_left,v_fd_change_total --只能返回一条数据
from EKP_CHANGE;
dbms_output.put_line(v_fd_change_left);
dbms_output.put_line(v_fd_change_total);
exception
when others then
dbms_output.put_line('错误');
end;
--rowtype
declare
r_name EKP_CHANGE%rowtype; --定义r_name的数据是name表一行数据对应的数据类型;
begin
select fd_change_left,fd_change_total
into r_name.fd_change_left,r_name.fd_change_total --只能返回一条数据
from EKP_CHANGE;
dbms_output.put_line(r_name.fd_change_left);
dbms_output.put_line(r_name.fd_change_total);
exception
when others then
dbms_output.put_line('错误');
end;
declare
r_ekp_change EKP_CHANGE%rowtype; --定义r_name的数据是name表一行数据对应的数据类型;
begin
select *
into r_ekp_change --这里表示r_name.id,r_name.name,r_name.grade和name表的数据对应的类型是一致的
from EKP_CHANGE;
dbms_output.put_line(r_ekp_change.fd_id);
dbms_output.put_line(r_ekp_change.fd_change_left);
end;
--数据库复合数据类型,数组varray()
declare
type str is varray(5) of varchar(18); --定义一个长度为5的数组str,每个元素为varchar(18);
strlist str:=str('I','am','xie','xing','xing'); --定义一个sreList变量来引用str数组的值;
begin
dbms_output.put_line(strlist(1)); --从1开始
dbms_output.put_line(strlist (2));
dbms_output.put_line(strlist (3));
dbms_output.put_line(strlist (4));
dbms_output.put_line(strlist (5));
end;
declare
type str is varray(5) of varchar(18); --定义一个长度为5的数组str,每个元素为varchar(18);
strlist str:=str('',''); --定义一个sreList变量来引用str数组的值;
begin
select fd_change_left,fd_change_total
into strlist(1),strlist(2)
from ekp_change;
dbms_output.put_line(strlist(1)); --从1开始
dbms_output.put_line(strlist (2));
end;
--数据库复合数据类型,数组table
declare
type str_table is table of varchar(18) index by binary_integer;
strList str_table;
begin
strList(1):='hello';
strList(2):='world'; --下标无下限
dbms_output.put_line(strList(1)||strList(2));
end;
declare
type str_table is table of EKP_CHANGE%rowtype index by binary_integer;
strList str_table;
begin
select fd_id,fd_change_left,fd_change_total
into strList(1).fd_id,strList(1).fd_change_left,strList(1).fd_change_total
from EKP_CHANGE;
dbms_output.put_line(strList(1).fd_id||strList(1).fd_change_left||strList(1).fd_change_total);
end;
--数据库复合数据类型,数组record()
declare
type v_record is record(
fd_id VARCHAR(32),
fd_change_left EKP_CHANGE.fd_change_left%type,
fd_change_total EKP_CHANGE.fd_change_total%type
);
name_record v_record;
begin
select fd_id,fd_change_left,fd_change_total
into name_record.fd_id,name_record.fd_change_left,name_record.fd_change_total
from EKP_CHANGE;
dbms_output.put_line(name_record.fd_id);
dbms_output.put_line(name_record.fd_change_left);
dbms_output.put_line(name_record.fd_change_total);
end;
declare
v_fd_change_left EKP_CHANGE.fd_change_left%type; --v_id是表name的id的数据类型
v_fd_change_total EKP_CHANGE.fd_change_total%type;
begin
select fd_change_left,fd_change_total
into v_fd_change_left,v_fd_change_total --只能返回一条数据
from EKP_CHANGE;
dbms_output.put_line(v_fd_change_left);
dbms_output.put_line(v_fd_change_total);
exception
when others then
dbms_output.put_line('错误');
end;
--rowtype
declare
r_name EKP_CHANGE%rowtype; --定义r_name的数据是name表一行数据对应的数据类型;
begin
select fd_change_left,fd_change_total
into r_name.fd_change_left,r_name.fd_change_total --只能返回一条数据
from EKP_CHANGE;
dbms_output.put_line(r_name.fd_change_left);
dbms_output.put_line(r_name.fd_change_total);
exception
when others then
dbms_output.put_line('错误');
end;
declare
r_ekp_change EKP_CHANGE%rowtype; --定义r_name的数据是name表一行数据对应的数据类型;
begin
select *
into r_ekp_change --这里表示r_name.id,r_name.name,r_name.grade和name表的数据对应的类型是一致的
from EKP_CHANGE;
dbms_output.put_line(r_ekp_change.fd_id);
dbms_output.put_line(r_ekp_change.fd_change_left);
end;
--数据库复合数据类型,数组varray()
declare
type str is varray(5) of varchar(18); --定义一个长度为5的数组str,每个元素为varchar(18);
strlist str:=str('I','am','xie','xing','xing'); --定义一个sreList变量来引用str数组的值;
begin
dbms_output.put_line(strlist(1)); --从1开始
dbms_output.put_line(strlist (2));
dbms_output.put_line(strlist (3));
dbms_output.put_line(strlist (4));
dbms_output.put_line(strlist (5));
end;
declare
type str is varray(5) of varchar(18); --定义一个长度为5的数组str,每个元素为varchar(18);
strlist str:=str('',''); --定义一个sreList变量来引用str数组的值;
begin
select fd_change_left,fd_change_total
into strlist(1),strlist(2)
from ekp_change;
dbms_output.put_line(strlist(1)); --从1开始
dbms_output.put_line(strlist (2));
end;
--数据库复合数据类型,数组table
declare
type str_table is table of varchar(18) index by binary_integer;
strList str_table;
begin
strList(1):='hello';
strList(2):='world'; --下标无下限
dbms_output.put_line(strList(1)||strList(2));
end;
declare
type str_table is table of EKP_CHANGE%rowtype index by binary_integer;
strList str_table;
begin
select fd_id,fd_change_left,fd_change_total
into strList(1).fd_id,strList(1).fd_change_left,strList(1).fd_change_total
from EKP_CHANGE;
dbms_output.put_line(strList(1).fd_id||strList(1).fd_change_left||strList(1).fd_change_total);
end;
--数据库复合数据类型,数组record()
declare
type v_record is record(
fd_id VARCHAR(32),
fd_change_left EKP_CHANGE.fd_change_left%type,
fd_change_total EKP_CHANGE.fd_change_total%type
);
name_record v_record;
begin
select fd_id,fd_change_left,fd_change_total
into name_record.fd_id,name_record.fd_change_left,name_record.fd_change_total
from EKP_CHANGE;
dbms_output.put_line(name_record.fd_id);
dbms_output.put_line(name_record.fd_change_left);
dbms_output.put_line(name_record.fd_change_total);
end;