--使用pl/sql语句打印一个hello world

begin

  dbms_output.put_line('hello,world');

end;

  
 

但是在sqlplus里面就不一样了

首先输入

begin

dbms_output.put_line('hello,world');

end;

/

通过set serveroutput on

/

来调用输出语句

 

可以通过edit命令对过程语句进行修改

 

name [constrant]datatype[notnull]:=|default value

 

 

--pl/sql语句中的if语句

declare

     sal1 number(6,2);

begin

  select sal into sal1 from emp where lower(ename)=lower('&ename');

  if (sal1<2000) then

    dbms_output.put_line('less 2000');

    end if;

end;

 

--pl/sql 里面的 if else 语句

declare

     sal1 number(6,2);

begin

  select sal into sal1 from emp where lower(ename)=lower('&ename');

  if (sal1<2000) then

    dbms_output.put_line('less 2000');

    else

      dbms_output.put_line('more 2000');

    end if;

end;

 

--pl/sql语句中的if elsif语句

declare

     sal1 number(6,2);

begin

  select sal into sal1 from emp where lower(ename)=lower('&ename');

    if (sal1<2000) then

    dbms_output.put_line('less 2000');

    elsif (sal1>2000 and sal1<400) then

    dbms_output.put_line('between 2000 and 4000');

    elsif (sal1>400) then

    dbms_output.put_line('more 4000');

    else

      dbms_output.put_line('other...........');

    end if;

end;

 

--pl/sql语句里面的case语句

declare

    a number(2):=0;

begin

    a:=&a;

    case a

      when 10 then

        dbms_output.put_line('aaaaaaaaaaa');

      when 20 then

        dbms_output.put_line('bbbbbbbbbbbb');

      else

        dbms_output.put_line('other.....');

    end case;    

end;

 

--pl/sql语句里面的loop语句

declare

    q number :=0;

begin

    loop

      q:=q+1;

      dbms_output.put_line('q='||q);

      exit when q=10;

    end loop;

end;

 

--使用if 结束的

declare

    q number :=0;

begin

    loop

      q:=q+1;

      dbms_output.put_line('q='||q);

      if q=10 then

        exit;

      end if;

    end loop;

end;

 

 

--使用 while 循环

declare

     q number :=0;

begin

     while(q<10)loop

      q:=q+1;

      dbms_output.put_line('q='||q);

     end loop;

end;

 

--使用 for循环  反向遍历 reverse

declare

begin

     for i in reverse 1..10 loop

      dbms_output.put_line(i);  

     end loop;

end;

 

 

PLS_INTEGER和BINARY_INTENER唯一区别是在计算当中发生溢出时,BINARY_INTENER型的变量会被自动指派给一个NUMBER型而不会出错,PLS_INTEGER型的变量将会发生错误。

 

 

record  定义类型

 

集合容器

index_by table

嵌套表

varray

type num_array is table of number(5) index by binary_integer;

 

 

单行单列  变量 varchar2 %type

单行多列 record

单列多行 集合 (type)

多行多列 集合(rowtype)

 

索引表的格式

type name is table of element_type index by key_type;

 

declare

     v_ename emp.ename%type;

     v_emp emp%rowtype;

begin

     select ename into v_ename from emp where empno=7369;

     select * into v_emp from emp where empno=7369;

     dbms_output.put_line(v_ename);

     dbms_output.put_line(v_emp.sal||'  '||v_emp.ename);

end;

 

--仅输出特殊的结构   使用 record来定义

declare

    type emp_record is record(

         v_ename emp.ename%type,

         v_sal emp.sal%type,

         v_deptno emp.deptno%type

    );

    v_emp_record emp_record;

begin

    select ename,sal,deptno into v_emp_record from emp where empno=7369;

    --我也可以通过赋值语句修改里面的值

    v_emp_record.v_ename:='zhaan';

    dbms_output.put_line(v_emp_record.v_ename);

    dbms_output.put_line(v_emp_record.v_sal);

    dbms_output.put_line(v_emp_record.v_deptno);

end;

 

--

declare

    type num_array is table of number(5) index by binary_integer;

    a num_array;

begin

    for i in 1..10 loop

      a(i):=i;

    end loop;

    for i in 1..10 loop

      dbms_output.put_line(a(i));

    end loop;

end;

 

 

--例子一

declare

    type emp_array is table of emp%rowtype index by binary_integer;

    a emp_array;

begin

    select * bulk collect into a from emp;

    for i in a.first..a.last loop

      dbms_output.put_line(a(i).ename||'  '||a(i).job);

    end loop;

end;

--集合中装有集合

declare

    type record1 is record(

         vempno emp.empno%type,

         vename emp.ename%type,

         vsal   emp.sal%type

    );

    type record2 is record(

         vdeptno emp.deptno%type,

         vrecord record1

    );

    a record1;

    b record2;

begin

  select empno,ename,sal into a from emp where empno=7369;

  b.vrecord:=a;

  dbms_output.put_line(b.vrecord.vempno);

  dbms_output.put_line(b.vrecord.vename);

  dbms_output.put_line(b.vrecord.vsal);

end;

--

declare

    type cc is table of varchar2(20) index by varchar2(20);

    a cc;

begin

    a('beijing'):='china';

    a('dongjing'):='japan';

    a('huashengdun'):='usa';

    dbms_output.put_line(a('beijing'));

end;

学习pl/sql之一的更多相关文章

  1. Oracle 学习PL/SQL

    先上一张实用的图:用于转义字符的. SQL> select chr(42) ||'is what?' from dual; CHR(42)||---------*is what? 想转义哪个就转 ...

  2. 使用PL/SQL Developer 学习pl/sql

    1.创建表并且插入一些数据 (这里表名为test): 2. New 一个SQL Window敲下如下代码(--为注释部分): declare   --declare:用于plsql中的声明变量,和be ...

  3. Oracle PL/SQL学习之Hello World(0)

    1.PL/SQL是Oracle数据库的一大创举,让一些复杂繁琐的常规主流编程代码做的编码处理过程,只需要在PL/SQL中使用简短的几句代码就可以解决,并且准确高效.那么遵循惯例,我们学习PL/SQL编 ...

  4. Oracle PL/SQL实战代码下载

    最近在学习PL/SQL编程,算是一个进阶吧,书没带光盘,所以按照书中的地址去下载样例,无法下载,到图灵官网找到了源代码下载地址,无法下载的留邮箱,我发给大家 下载地址: http://www.itur ...

  5. Oracle数据库之PL/SQL基础

    介绍PL/SQL之前,先介绍一个图像化工具:Oracle SQL Developer 在oracle的开发过程中, 我们难免会使用第三方开发的软件来辅助我们书写SQL, pl/sql是一个不错的sql ...

  6. pl/sql编程

    body { font-family: "Microsoft YaHei UI","Microsoft YaHei",SimSun,"Segoe UI ...

  7. ORACLE PL/SQL开发--bulk collect的用法 .

    刚刚在inthirties老大的博客里看到这篇文章,写的不错,正好自己最近在学习PL/SQL,转过来学习学习. ============================================ ...

  8. pl/sql 的 put和put_line区别

    在学习PL/SQL脚本时,打印语句是用得最多的语句. 在Oracle中,又有两种打印的方法:put和put_line.它们的区别是:put:不换行输出,输出在缓冲区,不显示出来,直到执行put_lin ...

  9. PL/SQL程序中调用Java代码(转)

    主要是学习PL/SQL调用JAVA的方法. 平台:WINDOWS 1.首先使用IDE写好需要调用的java代码,再添加"create or replace and compile java ...

随机推荐

  1. jQuery----(类似抽奖转盘)高亮显示

    效果如图: 原图 鼠标进入后开始变化图                                                                              实现需 ...

  2. sqli-labs学习(less-1-less-4)

    学习sqli-labs之前先介绍一些函数,以便于下面的payload看的懂 group_concat函数 将查询出来的多个结果连接成一个字符串结果,用于在一个回显显示多个结果 同理的还有 concat ...

  3. 学习笔记一:I2C协议学习和Verilog实现

    ////////////////////////////////////////////////// //clk = 20 MHz ,一个周期50ns //sck = 100 kHz (scl) ,一 ...

  4. 20155327 java第四周学习笔记

    20155327 java第四周学习笔记 五六章知识整理 1子类与父类 父类是接口或者是抽象类,子类必须继承自父类. 2子类的继承性 在Java中,通过关键字extends继承一个已有的类,被继承的类 ...

  5. Linux tree 命令乱码

    今天在执行Linux下的tree命令的时候,出现了乱码.上网查了一下说需要使用tree --charset ASCII,强制使用ASCII字符.这样确实可以输出正常了.但是我的环境里的LANG=US. ...

  6. 【转】QT事件传递与事件过滤器

        [概览] 1.重载特定事件函数.    比如: mousePressEvent(),keyPressEvent(),  paintEvent() .     2.重新实现QObject::ev ...

  7. 18-[JavaScript]-函数,Object对象,定时器,正则表达式

    1.函数创建 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <ti ...

  8. 10-[CSS]-盒模型:border,padding,margin

    1.CSS盒子模型 HTML文档中的每个元素都被描绘成矩形盒子,这些矩形盒子通过一个模型来描述其占用空间,这个模型称为盒子模型. 盒子模型通过四个边界来描述:margin(外边距),border(边框 ...

  9. spark-client 一直 accepted,无法提交任务,报错Failed to connect to driver at

    这个问题的原因有几个: 1.客户端安装的机器一般是虚拟机,虚拟机的名称可能是随便搞的,然而,yarn-client模式提交任务,是默认把本机当成driver的.所以导致其他的机器无法通过host的na ...

  10. [JLOI2013]地形生成[组合计数]

    题意 \(n\) 元素各有一个高度 \(h\) 和关键数字 \(b\) .求有多少个下标序列和高度序列,满足对任意 \(i\),\(j< i\) 且 \(h_j < h_i\)的 \(j\ ...