zoukankan      html  css  js  c++  java
  • oracle 控制语句

    PL输出语句

    set serverout on; -- 开启PL的输出语句功能
    declare

    n number:=1; -- 声明一个number型的变量n,并赋值为1
    v varchar2(20):='world'; -- 声明一个varchar2类型的变量v 赋值为“world”
    begin -- 控制语句书写在 begin      --     end 之间
    dbms_output.put_line('hello'||n||v); -- 输出语句,数据连接使用‘||’
    end;

    if条件语句
    set serverout on;
    declare emp_count number;
    begin
    select count(*) into emp_count from emp where sal>=3000;
    if emp_count>0 then
    dbms_output.put_line('有'||emp_count||'个员工的基本薪资大于等于3000');
    else
    dbms_output.put_line('没有员工的基本薪资大于等于3000');
    end if;
    end;

    赋值语句
    set serverout on;
    declare emp_count number;
    begin
    select count(*) into emp_count from emp where sal>=3000;  --  查询出数据并赋值给 emp_count
    if emp_count=1 then
    dbms_output.put_line('有1个员工的基本薪资大于等于3000');
    else if emp_count>1 then
    dbms_output.put_line('有超过1个员工的基本薪资大于等于3000');
    else
    dbms_output.put_line('没有员工的基本薪资大于等于3000');
    end if;
    end if;
    end;

    case when 流程控制语句

    set serverout on;
    declare emp_count number;
    begin
    select count(*) into emp_count from emp where sal>=3000;
    case emp_count
    when 0 then dbms_output.put_line('没有员工的基本薪资大于等于3000');
    when 1 then dbms_output.put_line('有1个员工的基本薪资大于等于3000');
    when 2 then dbms_output.put_line('有2个员工的基本薪资大于等于3000');
    when 3 then dbms_output.put_line('有3个员工的基本薪资大于等于3000');
    else dbms_output.put_line('超过3个员工的基本薪资大于等于3000');
    end case;
    end;

    无条件循环 loop

    set serverout on;
    declare g_id number:=2;
    g_losal number;
    g_hisal number;
    begin
    loop
    if(g_id>4) then
    exit;
    end if;

    select losal,hisal into g_losal,g_hisal from salgrade where grade=g_id;
    dbms_output.put_line(g_id || '等级的最低薪资'|| g_losal || ',最高薪资:' || g_hisal);

    g_id:=g_id+1;

    end loop;
    end;

    while 循环
    set serverout on;
    declare g_id number:=2;
    g_losal number;
    g_hisal number;
    begin

    while g_id<5 loop

    select losal,hisal into g_losal,g_hisal from salgrade where grade=g_id;
    dbms_output.put_line(g_id || '等级的最低薪资'|| g_losal || ',最高薪资:' || g_hisal);
    g_id:=g_id+1;
    end loop;

    end;

    for 循环
    set serverout on;
    declare g_losal number;
    g_hisal number;
    begin
    for g_id in 2..4 loop
    select losal,hisal into g_losal,g_hisal from salgrade where grade=g_id;
    dbms_output.put_line(g_id || '等级的最低薪资'|| g_losal || ',最高薪资:' || g_hisal);
    end loop;
    end;

  • 相关阅读:
    微软官方Windows Phone初学者开发视频系列从零开始带您轻松进入开发的世界
    Flash务实主义(五)——AS3的垃圾回收
    各种流行的编程风格
    程序设计的十个做与不做
    Android 上的 10 款 Web 开发工具推荐
    Flex 中的 DataGrid 自动刷新(转)
    Flex 序列化自定义类 解决 sharedObject 保存自定义对象
    Adobe更新手机应用开发工具 涵盖所有平台
    程序员的七大坏毛病
    怎样让失败变成成功之母?
  • 原文地址:https://www.cnblogs.com/getchen/p/8422988.html
Copyright © 2011-2022 走看看