--复合变量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;
/