select *from emp
declare
v_ename varchar2(20);
v_date date;
v_sal number(20);
begin
select ename,hiredate,sal into v_ename,v_date,v_sal from emp where empno=&renyi;
dbms_output.put_line('员工姓名:'||v_ename);
dbms_output.put_line('员工入职信息:'||to_char(v_date,'yyyy-mm-dd'));
dbms_output.put_line('员工的工资:'||v_sal);
exception
when no_data_found then dbms_output.put_line('没有该员工');
end;
declare
v_ename emp.ename%type;
v_date emp.hiredate%type;
begin
select ename,hiredate into v_ename,v_date from emp where empno=7499;
dbms_output.put_line('员工姓名'||v_ename);
dbms_output.put_line('员工姓名'||to_char(v_date,'yyyy-mm-dd'));
exception
when no_data_found then dbms_output.put_line('没有改员工');
end;
select *from dept
declare
v_dept_row dept%rowtype;
begin
select * into v_dept_row from dept where deptno=&ff;
dbms_output.put_line('员工编号'||v_dept_row.deptno);
dbms_output.put_line('员工姓名'||v_dept_row.dname);
dbms_output.put_line('员工上司'||v_dept_row.loc);
exception
when no_data_found then dbms_output.put_line('没有该员工');
end;
select *from emp
declare
type emp_record_type is record
(
ename emp.ename%type,
sal number(20)
);
v_emp_type emp_record_type;
begin
select ename,sal into v_emp_type from emp where empno=ⅆ
dbms_output.put_line('员工姓名'||v_emp_type.ename);
dbms_output.put_line('员工工资'||v_emp_type.sal);
exception
when no_data_found then dbms_output.put_line('没有该员工信息');
end;
select * from dept
declare
type dept_table_type is table of dept%rowtype index by binary_integer;
v_dept_table dept_table_type;
begin
select * into v_dept_table(0) from dept where deptno=≪
dbms_output.put_line('编号'||v_dept_table(0).deptno||'姓名'||v_dept_table(0).dname||'所在地'||v_dept_table(0).loc);
exception
when no_data_found then dbms_output.put_line('没有该条信息');
end;
declare
shu number(10):=&e;
begin
if shu>0 then dbms_output.put_line('它是大于0的');
end if;
end;
declare
shu number(10):=&e;
begin
if shu=1 then dbms_output.put_line('1');
else
dbms_output.put_line('不等于1');
end if;
end;
declare
shu number(10):=&e;
begin
if shu=0 then dbms_output.put_line('0');
elsif shu=1 then dbms_output.put_line('1');
elsif shu=2 then dbms_output.put_line('2');
else dbms_output.put_line('不再这些范围');
end if;
end;
select * from tab_aaa
declare
v_aaa tab_aaa%rowtype;
begin
v_aaa.tid:=&e;
select * into v_aaa from tab_aaa where tid=v_aaa.tid;
dbms_output.put_line('更新前成绩'||v_aaa.tcj);
if v_aaa.tcj =70 then
update tab_aaa set tcj=tcj+20 where tid=v_aaa.tid;
else
if v_aaa.tcj =50 then
update tab_aaa set tcj=tcj+20 where tid=v_aaa.tid;
else
update tab_aaa set tcj=tcj+30 where tid=v_aaa.tid;
end if;
end if;
end;
declare
shu varchar2(10):=ⅆ
begin
case shu
when 0 then dbms_output.put_line('0');
when 1 then dbms_output.put_line('1');
when 2 then dbms_output.put_line('2');
end case;
exception
when case_not_found then dbms_output.put_line('没有改信息');
end;
declare
shu number(10):=&e;
begin
loop
if shu>2 then exit;
end if;
dbms_output.put_line('niaho1'||shu);
shu:=shu+1;
end loop;
end;
select * from tab_aaa
declare
type v_aaa_type is table
of tab_aaa%rowtype
index by binary_integer;
shu number(5):=0;
v_aaa_table v_aaa_type;
begin
v_aaa_table(0).tid:=4;
v_aaa_table(0).tname:='a';
v_aaa_table(0).tcj:=88;
v_aaa_table(1).tid:=5;
v_aaa_table(1).tname:='a';
v_aaa_table(1).tcj:=78;
v_aaa_table(2).tid:=5;
v_aaa_table(2).tname:='a';
v_aaa_table(2).tcj:=78;
loop
if shu>2 then exit;
end if;
insert into tab_aaa values(v_aaa_table(shu).tid,v_aaa_table(shu).tname,v_aaa_table(shu).tcj);
shu:=shu+1;
end loop;
end;
declare
v_shu number(10):=&e;
begin
while v_shu<=2 loop
dbms_output.put_line('你好'||v_shu);
v_shu:=v_shu+1;
end loop;
end;
select *from tab_aaa
declare
type v_aaa_type is table
of tab_aaa%rowtype
index by binary_integer;
shu number(5):=0;
v_aaa_table v_aaa_type;
begin
v_aaa_table(0).tid:=4;
v_aaa_table(0).tname:='a';
v_aaa_table(0).tcj:=88;
v_aaa_table(1).tid:=5;
v_aaa_table(1).tname:='a';
v_aaa_table(1).tcj:=78;
v_aaa_table(2).tid:=5;
v_aaa_table(2).tname:='a';
v_aaa_table(2).tcj:=78;
while
shu<=2 loop
insert into tab_aaa values(v_aaa_table(shu).tid,v_aaa_table(shu).tname,v_aaa_table(shu).tcj);
shu:=shu+1;
end loop;
end;
declare
a number(30):=&ea;
begin
for i in 1 .. a loop
sys.dbms_output.put_line('bbb' || i);
end loop;
commit;
end;
select *from tab_aaa
declare
type v_aaa_type is table
of tab_aaa%rowtype
index by binary_integer;
shu number(5):=0;
v_aaa_table v_aaa_type;
begin
v_aaa_table(0).tid:=4;
v_aaa_table(0).tname:='a';
v_aaa_table(0).tcj:=88;
v_aaa_table(1).tid:=5;
v_aaa_table(1).tname:='a';
v_aaa_table(1).tcj:=78;
v_aaa_table(2).tid:=5;
v_aaa_table(2).tname:='a';
v_aaa_table(2).tcj:=78;
for shu in 0..v_aaa_table.count-1 loop
insert into tab_aaa values(v_aaa_table(shu).tid,v_aaa_table(shu).tname,v_aaa_table(shu).tcj);
end loop;
end;
begin
inset into emp(emp,ename) values(11,'asd');
inset into emp(emp,ename) values(12,'asd');
savepoint a;
inset into emp(emp,ename) values(13,'asd');
rollback to a;
inset into emp(emp,ename) values(14,'asd');
commit;
end;
declare
v_emp emp.ename%type;
begin
for i in 1..5 loop
select ename into v_emp from (select ename,rownum r from emp order by empno) where r=i;
dbms_output.put_line(v_emp);
end loop;
end;