zoukankan      html  css  js  c++  java
  • Oracle PLSQL入门

    -- 有了SQL 为什么还需要PL/SQL

    -- SQL功能很强大,但如果是单1sql语句,没有流程控制

    -- PL/SQL 是什么?

    --不仅仅实现流程控制,同时保留SQL本身所有的功能

    --还提供变量、常量等支持

    --提供更多数据类型的支持

    --第一,学习PL/SQL块(有开头,有结尾,还有块之外)

    <script language=javascript>

      ...

    </script>

    int a = 3;

    int a = a+3;

          :=

    PL/SQL块的定义

    --声明

    declare 

    begin

      

      exception

        

    end;

    --------

    String userName = "小明";

    System.out.println();

    dbms   output  put_line

    变量的定义

    变量的赋值1

    变量的赋值2(通过查询把,结果赋值给变量,注意,必须是单条记录)

    create table t1(

       id number primary key,

       user_name varchar2(20)

    );

    insert into t1 values(1,'小军');

    commit

    select user_name from t1 where id=1

    常量的使用

    -- 会话session级别的变量

    -- 宿主变量

    create table tt3(

       id number primary key,

       user_name varchar2(20),

       city varchar2(20),

       is_java number,

       is_boy number,

       age number

    );

    insert into tt3 values(1,'小明','珠海',1,1,19);

    commit;

    ---

    declare

      show_name varchar2(100);

    begin

      select user_name||' '||city into show_name from tt3 where id=1;

      dbms_output.put_line(show_name);

    end;

    ---

    declare

      is_java number;

      age number;

      is_java_stu boolean;

      more_than_age boolean;

      xxx varchar2(100);

    begin

      select is_java,age into is_java,age from tt3 where id=1;

      is_java_stu:=  (is_java=1);

      more_than_age:= (age>18);

      if (is_java_stu and more_than_age ) then 

         select '是一个java程序员' into xxx from dual;

      else

         select '不招' into xxx from dual;    

      end if;

      dbms_output.put_line(xxx);  

    end;

  • 相关阅读:
    BZOJ2199[Usaco2011 Jan]奶牛议会——2-SAT+tarjan缩点
    BZOJ3862Little Devil I——树链剖分+线段树
    BZOJ2325[ZJOI2011]道馆之战——树链剖分+线段树
    BZOJ1018[SHOI2008]堵塞的交通——线段树
    BZOJ2733[HNOI2012]永无乡——线段树合并+并查集+启发式合并
    BZOJ4127Abs——树链剖分+线段树
    bzoj 4753 最佳团体
    bzoj 4472 salesman
    bzoj 5369 最大前缀和
    bzoj 1226 学校食堂Dining
  • 原文地址:https://www.cnblogs.com/sheying/p/8629196.html
Copyright © 2011-2022 走看看