⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 冯刚.txt

📁 关于oracle和sql的书籍和ppt教程,非常好,本人珍藏品
💻 TXT
字号:
1,从控制台打印下列信息(用签套的循环,外层循环控制行,内层循环控制*号的个数以及出现的样式)
         *
        ***
       *****
      *******
       *****
        ***
         *
    dbms_output.put('*');   ----输出一个字符不换行
    dbms_output.new_line();  ----换行



declare
i int;
j int;
k int;
begin

for i in 1..4                    --前四行
loop
    for j in 1..(5-i)
    loop
    dbms_output.put(' ');        -- 输出空格
    end loop;
    for k in 1..(i*2-1)
    loop
    dbms_output.put('*');        --输出*
    end loop;
    dbms_output.new_line();

end loop;
for i in 5..7                   --后三行
loop
    for j in 1..(i-3)
    loop
    dbms_output.put(' ');
    end loop;
    for k in 1..(15-i*2)
    loop
    dbms_output.put('*');
    end loop;
    dbms_output.new_line();
    end loop;
    
 end;

2,在程序块里写一个事务分成两个单元(一个存储点)
   存储点之前给emp表插入一行数据
   存储点之后给emp表的某一行修改下age ,然后查询该行的age ,如果age > 40 回滚到存储点提交事务,如果条件不满足,提交整个事务
declare
age1 stu0.age%type;

begin 
insert into stu0(sid,age,sex) values(&a,55,'男');
 savepoint p1;
update stu0 set age=&age where sid=&sid;
select age into age1 from stu0 where sid=&sid;
if age1 >40
  then rollback to p1;
  commit;
  dbms_output.put_line('已提交至p1');
  else
  rollback;
  commit;
  
  dbms_output.put_line('已提交事务');
  end if;
  end;

3,给%TYPE   %ROWTYPE  RECORD  TABLE四种类型分别举出相应的例子

4,定义一个table 里面存放的是%rowtype类型,用该类型定义一个变量datas,从emp表取五行记录放到datas里面,通过循环,把五行数据的值输出来

declare
type table_type is table of stu0%rowtype index by binary_integer;
dates table_type;
i int;
begin
for i in 1..5
loop
select * into datas from stu0 where sid = i;
dbms_output.put_line(dates.sid,datas.sname,datas.sex);
end loop;
end;


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -