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;

 

转载于:https://www.cnblogs.com/sheying/p/8629196.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值