--複合變量table
declare
Type mytabtype is table of varchar2(10) index by binary_integer;
mytab mytabtype;
begin
mytab(10):='市場部';
mytab(20):='財務部';
mytab(30):='研發部';
dbms_output.put_line('10='||mytab(10));
dbms_output.put_line('20='||mytab(20));
dbms_output.put_line('30='||mytab(30));
end;
/
--複合變量table和rowtype組合
declare
type my_tab_type is table of dept%rowtype;
v_tab my_tab_type;
begin
select *bulk collect into v_tab from dept;
for i in 1..v_tab.count
loop
dbms_output.put_line(v_tab(i).deptno||','||v_tab(i).dname);
end loop;
end;
/
--匿名塊
begin
dbms_output.put_line('hello,world lili');
end;
/
--匿名塊打印變量
declare
v1 varchar2(20);
begin
v1:='&請輸入大名';
dbms_output.put_line('hello '||v1);
end;
/
--匿名塊+異常
declare
v_empno number(5);
v_ename varchar2(10);
begin
v_empno:=&請輸入要查詢的工號;
select ename into v_ename from emp where empno=v_empno;
dbms_output.put_line(v_ename);
exception
when no_data_found then
dbms_output.put_line(v_empno||'不存在');
when others then
dbms_output.put_line('未知錯誤!');
end;
/