--使用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. SpringCloud 学习(一) :Features

    话不多说,现在在开发微服务项目,也想系统的学习一下SpringCloud,顾选择硬着头皮跟着英文官方文档学习一遍SpringCloud. 现在公司在用SpringCloud,也有很好的实践应用,加上更 ...

  2. 数据库oracle安装与卸载

    安装的版本是oracle12-OraDb10g_home1服务端,先来卸载,如果电脑安装了oracle,在计算机-->管理-->服务里面可以看见下面三个oracle服务 首先我们要把它这里 ...

  3. 【转】比较详细的Asp伪静态化方法及Asp静态化探讨

    目前,各大搜索引擎如google.百度.雅虎已经对动态页面诸如asp,php有着不错的支持了,只要动态页面后面的参数不要太长,如控制在3个参数内,页面内容做点优化,各大搜索对该类页面收录甚至不比静态h ...

  4. Noip前的大抱佛脚----赛前任务

    赛前任务 tags:任务清单 前言 现在xzy太弱了,而且他最近越来越弱了,天天被爆踩,天天被爆踩 题单不会在作业部落发布,所以可(yi)能(ding)会不及时更新 省选前的练习莫名其妙地成为了Noi ...

  5. vmware虚拟机中的系统(例如kali),输入内容有延迟和卡顿的解决方案

    实际上是因为内存在vmware里设置小了,设置得大点即可, 比如我的kali之前是2gb,然后之前倒是没出过这种问题,但是这次更新系统后可能出了一些问题就变得卡了, 所以我就把kali的内存从2gb调 ...

  6. paramiko 简单的使用

    感觉自己操作服务器还要用xshell,麻烦很多,于是呢就去google,找到了paramiko. 使用这个模块还是很简单的, 我们链接服务器,只需要导入 SSHClient,AutoAddPolicy ...

  7. python应用:生成简单二维码

    概述 \(\quad\)第一篇python的应用就打算写一写用python生成简单的二维码啦.因为二维码在日常生活中越来越常用了,部分博客也用二维码来用作打赏的工具.但是要提醒大家的是,千万不要乱扫街 ...

  8. monkey测试入门3

    本文要感谢一起战斗过的点时小伙伴,程童鞋 打开开始 输入cmd 看到它的目录地址 然后把adb压缩包解压到该地址 插入数据线 打开手机设置打开开发者选项 打开USB调试 右键点击我的电脑 选择管理 左 ...

  9. myBatis逆向工程的使用

    使用myBatis Generator可以快速生成实体类.dao类和mapper文件.有两种方式,现在说的是比较灵活的方式.本文栗子使用的是IDEA,目录结构为maven项目的结构. 1.在pom.x ...

  10. Linux命令的那些事(三)

    回顾linux命令那些事,前面大致总结了常用的Linux命令 回顾Linux命令那些事(一) clear/mkdir/rmdir/ls/rm/pwd/cd/touch/tree/man/--help ...