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;

  • 相关阅读:
    Spring 在xml配置里配置事务
    Spring事务的传播行为
    Spring 自动装配;方法注入
    Spring 依赖注入(一、注入方式)
    Spring事务
    C3P0使用详解
    php 解析json失败,解析为空,json在线解析器可以解析,但是json_decode()解析失败(原)
    Linux下的crontab定时执行任务命令详解
    crontab 常见 /dev/null 2>&1 详解
    实体字符转换,同样变量密码加盐MD5后生成的加密字符串不同解决办法 (原)
  • 原文地址:https://www.cnblogs.com/sheying/p/8629196.html
Copyright © 2011-2022 走看看