📄 朱志明.txt
字号:
1,从控制台打印下列信息(用签套的循环,外层循环控制行,内层循环控制*号的个数以及出现的样式)
/*declare
toi int ;
toj int ;
tok int;
begin
<<shangbian>>
for toi in 1..4 loop
for tok in reverse 0..(4-toi) loop
dbms_output.put(' ');
end loop;
for toj in 1..(2*toi-1) loop
dbms_output.put('*');
end loop;
dbms_output.new_line();
end loop shangbian;
for toi in 1..3 loop
for tok in 1..toi+1 loop
dbms_output.put(' ');
end loop;
for toj in 1..(7-(toi*2)) loop
dbms_output.put('*');
end loop;
dbms_output.new_line();
end loop;
end; */
_
2. 在程序块里写一个事务分成两个单元(一个存储点)
存储点之前给emp表插入一行数据
存储点之后给emp表的某一行修改下age ,然后查询该行的age ,如果age > 40 回滚到存储点提交事 务,如果条件不满足,提交整个事务
____________________________________________________________
/*declare
age int;
begin
insert into mystudent(stuid,stuname) values(6786,'fffsd');
savepoint p1;
update mystudent set age = 40 where stuid = 1001;
select age into age from mystudent where stuid=&aaaa ;
if age>40 then
rollback to p1;
commit;
else
commit;
end if;
end;*/
_____________________________________________________________
3. 给%TYPE %ROWTYPE RECORD TABLE四种类型分别举出相应的例子
declare
v_ename emp.ename%type;
v_sal emp.sal%type;
begin
select ename,sal into v_ename,v_sal from emp where empno=&eno;
dbms_output.put_Line('雇员名字是'||v_ename);
dbms_output.put_Line('雇员的工资为||v_sal');
end;
________________________________________________
declare
v_emp emp%rowtype;
begin
select * into v_emp from emp where empno=&eno;
dbms_output.put_line('雇员的名字是'||v_emp.ename);
dbms_output.put_line('雇员的工资是'||v_emp.sal);
dbms_output.put_line('雇员的岗位是'||v_emp.job);
end;
_____________________________________________________________________
declare
type emp_record_type is record(name emp.ename%type,
salary emp.sal%type,
job emp.job%type );
emp_record emp_record_type;
begin
select ename,sal,job into emp_record
from emp
where empno=&eno;
dbms_output.put_line('雇员的名字是'||emp_record.name);
dbms_output.put_line('雇员的工资是'||emp_record.salary);
dbms_output.put_line('雇员的岗位是'||emp_record.job);
end;
________________________________________________________________
declare
type emp_table_type is table of emp.ename%type
index by binary_integer;
emp_table emp_table_type;
begin
select ename into emp_table(-1)
from emp
where empno=&eno;
emp_table(0) :='jack';
emp_table(1) :='luck';
dbms_output.put_line('emp_table(-1)雇员的名字是'||emp_table(-1));
dbms_output.put_line('emp_table(0)'|| emp_table(0));
dbms_output.put_line('emp_table(1)'||emp_table(1));
end;
__________________________________________________________________
4. 定义一个table 里面存放的是%rowtype类型,用该类型定义一个变量datas,从emp表取五行记录放到datas里面,通过循环,把五行数据 的值输出来
declare
type emp_table_type is table of emp5%rowtype
index by binary_integer;
datas emp_table_type;
i int;
begin
while i<6 loop
select * into datas(i) from emp5 where id=i;
i:=i+1;
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(' sal '||datas(i).sal);
dbms_output.put(' ldid '||datas(i).ldid);
dbms_output.new_line();
end loop;
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -