zoukankan      html  css  js  c++  java
  • ORACLE1.21 PLSQL 01

    -- 有了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;

  • 相关阅读:
    设计模式之策略模式
    assert断言——调试中不应该是syso
    Spring AOP
    MyBatis
    事务处理与使用连接池管理连接
    管理结果集(ResultSet)
    执行SQL语句的方式
    JDBC基础:
    NIO.2
    NIO
  • 原文地址:https://www.cnblogs.com/wyj1212/p/8646044.html
Copyright © 2011-2022 走看看