指引网

当前位置: 主页 > 数据库 > Oracle >

Oracle语句块PL/SQL循环判断

来源:网络 作者:佚名 点击: 时间:2018-01-13 06:39
[摘要] --pl/sql Procedural Language /sql --被数据库编译保存,由用户调用 --程序块 /* 语法 Declare 声明变量 --声明变量 Age int; //没有默认值的变量 Age2 int := 0; begin //写正常的处理语句 dbms_output.
PLSQL
--pl/sql Procedural Language /sql
    --被数据库编译保存,由用户调用
    --程序块
    /*
    语法
    Declare – 声明变量
    --声明变量
    Age int; //没有默认值的变量
    Age2 int :=  0;
    begin
    //写正常的处理语句
    dbms_output.put_line('Hello');
    end ;
    / -写一个就是执行
    */
    --一个hello world 的程序块
    declare
    age INTEGER:=3;
    begin
    DBMS_OUTPUT.PUT_LINE('hello world');
    DBMS_OUTPUT.PUT_LINE('age=3');
    end;
    --输出默认关闭手工打开
    set serveroutput on;
    --控制语句
    /*
    if then
    elsif then
    else
    end if
    */
    --一个if的语句块
    declare
    age integer:=3;
    begin
    if age=1 then
    DBMS_OUTPUT.PUT_LINE('age=1');
    elsif age=2 then
    DBMS_OUTPUT.PUT_LINE('age=2');
    else
    DBMS_OUTPUT.PUT_LINE('age=3');
    end if;
    end;
    --循环
    declare
    i int:=1;
    begin
    loop
    exit when i>10;
    DBMS_OUTPUT.PUT_LINE('编号为'||i);
    i:=i+1;
    end loop;
    end;
------分隔线----------------------------