📄 607练习与答案.txt
字号:
1,从控制台打印下列信息(用签套的循环,外层循环控制行,内层循环控制*号的个数以及出现的样式)
*
***
*****
*******
*****
***
*
dbms_output.put('*'); ----输出一个字符不换行
dbms_output.new_line(); ----换行
2,在程序块里写一个事务分成两个单元(一个存储点)
存储点之前给emp表插入一行数据
存储点之后给emp表的某一行修改下age ,然后查询该行的age ,如果age > 40 回滚到存储点提交事务,如果条件不满足,提交整个事务
3,给%TYPE %ROWTYPE RECORD TABLE四种类型分别举出相应的例子
4,定义一个table 里面存放的是%rowtype类型,用该类型定义一个变量datas,从emp表取五行记录放到datas里面,通过循环,把五行数据的值输出来
第一题:
declare
i int;
--k int;
--j int;
begin
i := 0;
<<hang>>
for i in 1..4 loop --上四行
for k in reverse 0..(4-i) loop --打印空格
dbms_output.put(' ');
end loop;
for j in 1..(2*i-1) loop --打印*号
dbms_output.put('*');
end loop;
dbms_output.new_line();
end loop hang;
for i in 1..3 loop --下三行
for k in 0..i loop
dbms_output.put(' ');
end loop;
for j in reverse 1..(7-2*i) loop
dbms_output.put('*');
end loop;
dbms_output.new_line();
end loop;
end;
第二题:
declare
newage student.age%type;
--newid student.id%type;
begin
insert into student(id,age) values(6,50);
savepoint p1;
update student set age=&a where id=&i;
select age into newage from student where id = &i;
if newage>40 then
rollback to p1;
dbms_output.put_line('已返回回滚点提交');
commit;
else
dbms_output.put_line('已直接提交');
commit;
end if;
end;
第三题:
declare
wage emp.sal%type; --%type例子
whole emp%rowtype; --rowtype例子
type rec is record(
nam emp.ename%type,
job emp.job%type
);myrec rec; --record例子
type tabl is table of emp.job%type index by binary_integer;mytable tabl; --table例子
begin
select sal into wage from emp where empno=7654;
dbms_output.put_line('wage is ' ||wage);
select * into whole from emp where empno = &exrow;
dbms_output.put_line('姓名'||whole.ename);
dbms_output.put_line('岗位'||whole.job);
select ename,job into myrec from emp where empno=&exrec;
dbms_output.put_line('姓名'||whole.ename);
dbms_output.put_line('岗位'||whole.job);
select ename into mytable(-1) from emp where empno=&extab;
dbms_output.put_line('姓名'||mytable(-1));
end;
第四题:
declare
--row_in_table emp%rowtype;
type row_table is table of emp_20%rowtype index by binary_integer;
datas row_table;
begin
for i in 1..5 loop
select * into datas(i) from emp_20 where id=i;
end loop;
for i in 1..5 loop
dbms_output.put('id '||datas(i).id);
dbms_output.put(' name '||datas(i).name);
dbms_output.put(' sex '||datas(i).sex);
dbms_output.put(' age '||datas(i).age);
dbms_output.put(' salary '||datas(i).salary);
dbms_output.put(' sid '||datas(i).sid);
dbms_output.new_line();
end loop;
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -