--
DECLARE
text emp.empno%TYPE :=7499;
rec emp%ROWTYPE;
BEGIN
SELECT * INTO rec FROM emp WHERE empno=text;
DBMS_OUTPUT.PUT_LINE(‘姓名:‘||rec.ename||‘工资:‘||rec.sal||‘工作时间:‘||rec.hiredate);
END;
declare
text2 jiesuan.商品%type :=‘手机‘;
ee jiesuan%rowtype;
begin
select * into ee from jiesuan where 商品=text2;
dbms_output.put_line(‘商品:‘||ee.商品);
end;
--嵌套
DECLARE
v_Number emp.empno%type :=7782;
dd emp%rowtype;
BEGIN
DECLARE
v_number2 emp.empno%type :=7788;
ff emp%rowtype;
BEGIN
select * into ff from emp where empno=v_number2;
dbms_output.put_line(‘姓名:‘||ff.ename);
END;
select * into dd from emp where empno=v_number;
dbms_output.put_line(‘********************‘||dd.ename||‘--‘||dd.sal);
END;
--if条件判断
declare
v_id stu1.成绩%type :=&jhvgh;
v_name stu1%rowtype;
begin
if v_id>50 then
select * into v_name from stu1 where 成绩=v_id;
dbms_output.put_line(‘姓名:‘||v_name.姓名);
else
select * into v_name from stu1 where 成绩=v_id;
dbms_output.put_line(‘姓名:‘||v_name.班级);
end if;
end;
--case表达式
declare
v_id stu1.成绩%type :=&jjj;
v_name varchar(30);
begin
select stu1.姓名 into v_name from stu1 where stu1.成绩=v_id;
v_name :=
case v_id
when 10 then V_name
when 20 then V_name
when 50 then V_name
end;
dbms_output.put_line(‘v_name:‘||V_name);
end;
--循环语句loop
declare
int number(20) :=0;
begin
loop
int :=int+1;
insert into stu1 values(‘马‘,‘四年六班‘,1003,43);
exit when int=2;
end loop;
end;
select * from stu1
--循环语句while
declare
int number(30) :=1;
begin
while
int <=3
loop
dbms_output.put_line(‘数值:‘||int);
int :=int+1;
end loop;
end;
--循环语句for
declare
int number(30) :=0;
begin
for int in 1..4 loop
dbms_output.put_line(‘int=‘||int);
end loop;
end;
--rollback回滚
select * from emp
delete emp where empno=7777
rollback;
--commit提交数据
--savepoint创建保存点
create table stu3(
v_name varchar2(10),
v_number number(10)
);
savepoint a;
insert into stu3 values(‘马强‘,1001 );
savepoint b;
insert into stu3 values(‘马季‘,1002 );
savepoint C;
update stu3 set v_name=‘马云‘ where v_number=1001;
rollback to savepoint b;
--查询表
select * from stu3;