Oracle(pl/sql)

不管数据类型,直接用数据表的数据类型?

declare 

  v_id  stu.sid%type;

 v_name stu.sname%type;

begin 

 v_id:='&请输入编号';

 select  sname  into  v_name  from stu  where  sid=v_id;

   dbms_output.put_line('取出的姓名:'||v_name);

end;

行的数据类型  %rowtype

declare
       v_id stu.sid%type;
       v_temp stu%rowtype;    
begin
       v_id:='&请输入编号';
       select * into v_temp from stu where sid=v_id;
       dbms_output.put_line('编号:'||v_temp.sid||' 姓名:'||v_temp.sname||'  年龄:'||v_temp.sage);
end;

 

declare
       v_sid student.sid%type;
       v_date student.sdate%type;
begin
       v_sid := '&请输入编号:';
       select sdate into v_date from student where sid=v_sid;
       --dbms_output.put_line('日期:'||v_date);
       dbms_output.put_line('日期:'||to_char(v_date,'yyyy"年"mm"月"dd"日" hh24:mi:ss dy'));
end;

 

-- 行类型 带出一个新的问题:如果取出多行?用游标 cursor解决多行问题!

declare
       v_gid stu.gid%type;    
.       v_temp stu%rowtype;    
begin
       v_gid:='&请输入编号';
       select * into v_temp from stu where gid=v_gid;
       dbms_output.put_line('编号:'||v_temp.sid||' 姓名:'||v_temp.sname||'  年龄:'||v_temp.sage);
end;

declare
       --声明一个类型
       type r_stu is record
       (
             v_id stu.sid%type,
             v_temp stu%rowtype
       );
       v_t r_stu;--v_t:变量 r_stu:数据类型 
begin
       v_t.v_id:='&请输入编号';
       select * into v_t.v_temp from stu where sid=v_t.v_id;
       dbms_output.put_line('编号:'||v_t.v_temp.sid||' 姓名:'||v_t.v_temp.sname||'  年龄:'||v_t.v_temp.sage);
end;

 

 


/*
     多重if结构
*/
declare
     v_score number(3);
begin
     v_score:='&请输入成绩:';
     if(v_score>90) then
          dbms_output.put_line('优秀!');
     elsif(v_score>70) then
          dbms_output.put_line('中等!');
     elsif(v_score>60) then
          dbms_output.put_line('及格!');
     else
         dbms_output.put_line('请家长!');
     end if;
end;

 

/*
     case when then else end case;
*/
declare
     v_score number(3);
begin
     v_score:='&请输入成绩:';
     case
     when v_score>90 then dbms_output.put_line('优秀!');
     when v_score>70 then dbms_output.put_line('中等!');
     when v_score>60 then dbms_output.put_line('及格!');
     else
         dbms_output.put_line('请家长!');
     end case;
end;

 

/*
     循环:loop end loop;
     while和for
*/
declare
     v_i number(4);
begin
     v_i:=1;
     loop
          v_i:=v_i+1;
          exit when v_i>50;--退出的时候 
           dbms_output.put_line(v_i);  
     end loop;
end;

 

--while
declare
     v_i number(4);
begin
     v_i:=1;
     while(v_i<50) loop
           dbms_output.put_line(v_i);
           v_i:=v_i+1;--改变表达式值        
     end loop;
end;
 

--for
declare
begin
     for v_i in 1..50 loop
         dbms_output.put_line(v_i);
     end loop;
end;

 

--for实现 50到1依次输出 reverse:逆向输出
declare
begin
     for v_i in reverse 1..50 loop
         dbms_output.put_line(v_i);
     end loop;
end;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

brid_fly

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值