- 浏览: 68476 次
- 性别:
- 来自: 海南-临高
最新评论
下文为plsql编程中高级特性的应用实例。以供大家在编程时参考。
sql 代码
- /*********************************************************
- Author:qinyangzhao
- describe:PL/SQL记录记录 (type is record)
- *********************************************************/
- set serveroutput on--打开显示模式
- declare
- type cust_record_type is record(--定义记录类型
- name customer.name%type,--声明标量变量
- total ord.total%type--声明记录变量
- );
- cust_record cust_record_type;
- begin
- select a.name ,b.total ,into cust_record
- from customer a ,ord b
- where a.customer_id=b.customer_id and b.ord_id=&id;
- dbms_output.put_line('客户名'||cust_record.name);
- dbms_output.put_line('订单总额:'||cust_record.total);
- end;
- /*********************************************************
- Author:qinyangzhao
- describe:%rowtype属性(rowtype)
- *********************************************************/
- delcare
- product_record product%rowtype;
- begin
- product_record.product_id:=&id;
- product_record.description:='&description';
- insert into product values product_record;
- end;
- /*********************************************************
- Author:qinyangzhao
- describe:索引表(table)
- *********************************************************/
- declare
- type item_table_type is table of item.ename%type
- index by pls_integer;
- item_table item_table_type;
- begin
- select * bulk collect into item_table(-1)
- from item where ord_id=&id;
- dbms_output.put_line('条款编号:'||item_table(-1));
- end;
- /*********************************************************
- Author:qinyangzhao
- describe:嵌套表(table)
- *********************************************************/
- declare
- type item_table_type is table of item.ename%type;
- item_table item_table_type;
- begin
- item_table:=item_table_type('mary','mary','mary');
- select ename into item_table(2) from item
- where empno=&no;
- dbms_output.put_line('雇员名:'||item_table(2));
- end;
- /*********************************************************
- Author:qinyangzhao
- describe:变长数组(array)
- *********************************************************/
- declare
- type name_array_type is varray(20) of varchar2(30);
- type city_array_type is varray(20) of varchar2(30);
- name_array name_array_type;
- city_array city_array_type;
- begin
- select name ,city bulk collect
- into name_array,city_array from customer;
- for i in 1..name_array.count loop
- dbms_output.put_line('客户名:'||name_array(i)||',所在城市:'||city_array(i));
- end loop;
- end;
- /*********************************************************
- Author:qinyangzhao
- describe:记录表(table)
- *********************************************************/
- declare
- type item_table_type is table of item%rowtype
- index by pls_integer;
- item_table item_table_type;
- begin
- select * bulk collect into item_table
- from item where ord_id=&id;
- for i in 1..item_table.count loop
- dbms_output.put_line('条款编号:'||item_table(i).item_id||',总价:'||
- item_table(i).total);
- end loop;
- end;
- /*********************************************************
- Author:qinyangzhao
- describe:多级(varray)
- *********************************************************/
- declare
- type al_varray_type is varray(10) of int;--定义一维varray
- type nal_varray_type is varray(10) of al_varray_type;--定义二维varrary集合
- --初始化二维集合变量
- nvl nal_varrary_type:=nal_varrary_type(
- al_varray_type(58,100,102),
- al_varray_type(55,6,73),
- al_arrary_type(2,4));
- begin
- dbms_output.put_line('显示二维数组所有元素');
- for i in 1..nvl.count loop
- for j in 1..nvl(i).count loop
- dbms_output.put_line('nvl('||i||','||j||')='||nvl(i,j));
- end loop;
- end loop;
- end;
- /*********************************************************
- Author:qinyangzhao
- describe:多级(嵌套)
- *********************************************************/
- declare
- type al_table_type is table of int;--定义一维嵌套表
- type nal_table_type is table of al_table_type;--定义二维嵌套表集合
- --初始化二维集合变量
- nvl nal_varrary_type:=nal_varrary_type(
- al_varray_type(58,100,102),
- al_varray_type(55,6,73),
- al_arrary_type(2,4));
- begin
- dbms_output.put_line('显示二维数组所有元素');
- for i in 1..nvl.count loop
- for j in 1..nvl(i).count loop
- dbms_output.put_line('nvl('||i||','||j||')='||nvl(i,j));
- end loop;
- end loop;
- end;
- /*********************************************************
- Author:qinyangzhao
- describe:多级(索引表)
- *********************************************************/
- declare
- type al_table_type is table of int
- index by binary_integer;--定义一维table
- type nal_table_type is table of al_table_type
- index by binary_integer;--定义二维table集合
- nvl nal_varrary_type;
- begin
- --初始化二维集合变量
- nvl(1)(1):=10;
- nvl(1)(2):=5;
- nvl(2)(1):=32;
- nvl(2)(2):=88;
- dbms_output.put_line('显示二维数组所有元素');
- for i in 1..nvl.count loop
- for j in 1..nvl(i).count loop
- dbms_output.put_line('nvl('||i||','||j||')='||nvl(i,j));
- end loop;
- end loop;
- end;
- /*********************************************************
- Author:qinyangzhao
- describe:处理多行查询语句
- *********************************************************/
- declare
- type empcurtyp is ref cursor;
- emp_cv empcurtyp;
- emp_record emp%rowtype;
- sql_stat varchar2(100);
- begin
- sql_stat:='select * from emp where deptno:=dno';
- open emp_cv for sql_stat using &dno;
- loop
- fetch emp_cv into emp_record;
- exit when emp_cv%notfound ;
- dbms_output.put_line('雇员名:'||emp_record.ename||',工资:'||emp_record.sal);
- end loop;
- close emp_cv;
- end;
- /*********************************************************
- Author:qinyangzhao
- describe:使用bulk子句处理dml语句返回子句
- *********************************************************/
- declare
- type ename_table_type is table of emp.ename%type
- index by binary_integer;
- type sal_table_type is table of emp.sal%type
- index by binary_integer;
- ename_table ename_table_type;
- sal_table sal_table_type;
- sql_stat varchar2(100);
- begin
- sql_stat:='update emp set sal=sal*(1+:percent/100)'
- ||'where deptno=:dno'
- ||'returning ename,sal into :name,:salary';
- execute immediate sql_stat using &percen ,&dno returning bulk collect into ename_table,sal_table;
- for i in 1..ename_table.count loop
- dbms_output.put_line('雇员:'||ename_table(i)
- ||',的新工资为'|| sal_table(i));
- end loop;
- end;
- /*********************************************************
- Author:qinyangzhao
- describe:使用bulk子句处理多行查询
- *********************************************************/
- declare
- type ename_table_type is table of emp.ename%type
- index by binary_integer;
- ename_table ename_table_type;
- sql_stat varchar2(100);
- begin
- sql_stat:='select ename from emp where deptno+:dno';
- execute immediate sql_stat bulk collect into ename_table using &dno;
- for i in 1..ename_table.count loop
- dbms_output.put_line(ename_table(i));
- end loop;
- end;
- /*********************************************************
- Author:qinyangzhao
- describe:在fetch语句中使用bulk子句
- *********************************************************/
- declare
- type empcurtyp is ref cursor;
- emp_cv empcurtyp ;
- type ename_table_type is table of emp.ename%type
- index by binary_integer;
- ename_table ename_table_type;
- sql_stat varchar2(100);
- begin
- sql_stat:='select ename from emp where job:title';
- open emp_cv for sql_stat using '&job';
- fetch emp_cv bulk collect into ename_table;
- for i in 1..ename_table.count loop
- dbms_output.put_line(ename_table(i));
- end loop;
- close emp_cv;
- end;
- /*********************************************************
- Author:qinyangzhao
- describe:在forall语句中使用bulk子句
- *********************************************************/
- declare
- type ename_table_type is table of emp.ename%type;
- type sal_table_type is table of emp.sal%type;
- ename_table ename_table_type;
- sal_table sal_table_type;
- sql_stat varchar2(100);
- begin
- ename_table:=name_table_type('scott','smith','clark');
- sql_stat:='update emp set sal=sal*1.1 where ename=:1'
- ||'returning sal into :2';
- forall i in 1..ename_talbe.count
- execute immediate sql_stat using ename_table(i)
- returing bulk collect into sal_table ;
- for j in 1..ename_table.count loop
- dbms_output.put_line('雇员'||ename_table(j)
- ||'的新工资为'||sal_table(j));
- end loop;
- end;
发表评论
-
何时需要索引
2009-03-01 08:46 13191)与全表扫描相比,索 ... -
索引匹配
2009-02-26 23:01 988索引匹配索引匹配:对于单一列的索引,如果列单独出现,没有函数或 ... -
oracle监听器失效解决方案
2007-10-14 09:03 6436问题1:dos内部或外部命令失效时。 解决1:在path变量中 ... -
sql 调优方式1
2007-10-08 22:19 1347sql 代码 连接到: Oracl ... -
dos下启动监听及服务
2007-10-08 21:11 2160用惯了pl/sql.突然在公司里让我在dos下来启动oracl ... -
SQL调优
2007-10-07 09:06 1366sql 代码 SQL>create tab ... -
SQL PLUS命令的使用大全
2007-09-11 17:34 4549sql 代码 SQL*PLUS命令的使用大全 ... -
在函数中如何调用存储
2007-07-14 13:44 10181.创建实体表及初始化数据 create table PR ... -
对象类型及对象类型表(只含有简单的类型)
2007-07-14 13:43 10261.如何创建对象类型 语法: CREATE TYPE t ...
相关推荐
《Oracle PL/SQL程序设计(第5版)》基于Oracle数据库11g,从PL/SQL编程、PL/SQL程序结构、PL/SQL程序数据、PL/SQL中的SQL、PL/SQL应用构建、高级PL/SQL主题这6个方面详细系统地讨论了PL/SQL以及如何有效地使用它。...
PL/SQL本身涉及的知识点浩瀚、庞杂...当然,最为重要的还是内容本身,本书首先对PL/SQL的理论基础进行了全面的介绍,其次详细讲解PL/SQL开发的所有功能模块、方法和技巧,最后对它的各种高级特性也进行了深入探讨。
《Oracle PL/SQL程序设计(第5版)》基于Oracle数据库11g,从PL/SQL编程、PL/SQL程序结构、PL/SQL程序数据、PL/SQL中的SQL、PL/SQL应用构建、高级PL/SQL主题这6个方面详细系统地讨论了PL/SQL以及如何有效地使用它。...
对于PL/SQL开发人员,可能已经非常熟悉PL/SQL的基本开发方法,但可能对PL/SQL高级内容(集合类型,对象类型,LOB对象处理)和oracle9i/oracle10g的PL/SQL新特性知之较少,本书对于这些高级知识和新特性有非常详尽的介绍....
ORACLE数据库除了提供SQL和PL/SQL来访问数据库外,还提供了一个第三代程序设计语言的接口,用户可以通过C、COBOL、FORTRAN等第三代语言来编程访问数据库。OCI就是为了实现高级语言访问数据库而提供的接口。OCI允许...
5.2 基本PL/SQL编程结构 5.3 定义PL/SQL数据类型 5.3.1 有效字符集 5.3.2 算术操作符 5.3.3 varchar2类型 5.3.4 数字类型 5.3.5 日期类型 5.3.6 布尔类型 5.4 在SQL*Plus中编写PL/SQL程序, 5.4.1 PL/SQL程序中...
该资料是《Oracle SQL高级编程》的源代码 对应的书籍资料见: Oracle SQL高级编程(资深Oracle专家力作,OakTable团队推荐) 基本信息 原书名: Pro Oracle SQL 原出版社: Apress 作者: (美)Karen Morton Kerry ...
本书内容包括Oracle数据库的基本概念;Oracle数据库结构和实用程序;...高级SQL特性;用interMedia、基于C的外部过程、Java存储过程和对象关系特性实现Oracle数据库功能的扩展;Oracle数据库安全管理的实现方式等。
5.2 基本PL/SQL编程结构 123 5.3 定义PL/SQL数据类型 124 5.3.1 有效字符集 124 5.3.2 算术操作符 125 5.3.3 varchar 2类型 126 5.3.4 数字类型 127 5.3.5 日期类型 127 5.3.6 布尔类型 128 5.4 在SQL*Plus...
此外还有大量案例:Where In List问题解析,数据库设计和大数据量处理、数据审核、号段选取应用、分析SQL执行计划的关注点、Oracle开发误区探索、提升PL/SQL开发性能漫谈、管道函数的学习与实战应用、巧用锁特性避免...
此外还有大量案例:Where In List问题解析,数据库设计和大数据量处理、数据审核、号段选取应用、分析SQL执行计划的关注点、Oracle开发误区探索、提升PL/SQL开发性能漫谈、管道函数的学习与实战应用、巧用锁特性避免...
此外还有大量案例:Where In List问题解析,数据库设计和大数据量处理、数据审核、号段选取应用、分析SQL执行计划的关注点、Oracle开发误区探索、提升PL/SQL开发性能漫谈、管道函数的学习与实战应用、巧用锁特性避免...
此外还有大量案例:Where In List问题解析,数据库设计和大数据量处理、数据审核、号段选取应用、分析SQL执行计划的关注点、Oracle开发误区探索、提升PL/SQL开发性能漫谈、管道函数的学习与实战应用、巧用锁特性避免...
此外还有大量案例:Where In List问题解析,数据库设计和大数据量处理、数据审核、号段选取应用、分析SQL执行计划的关注点、Oracle开发误区探索、提升PL/SQL开发性能漫谈、管道函数的学习与实战应用、巧用锁特性避免...
此外还有大量案例:Where In List问题解析,数据库设计和大数据量处理、数据审核、号段选取应用、分析SQL执行计划的关注点、Oracle开发误区探索、提升PL/SQL开发性能漫谈、管道函数的学习与实战应用、巧用锁特性避免...
此外还有大量案例:Where In List问题解析,数据库设计和大数据量处理、数据审核、号段选取应用、分析SQL执行计划的关注点、Oracle开发误区探索、提升PL/SQL开发性能漫谈、管道函数的学习与实战应用、巧用锁特性避免...
此外还有大量案例:Where In List问题解析,数据库设计和大数据量处理、数据审核、号段选取应用、分析SQL执行计划的关注点、Oracle开发误区探索、提升PL/SQL开发性能漫谈、管道函数的学习与实战应用、巧用锁特性避免...
此外还有大量案例:Where In List问题解析,数据库设计和大数据量处理、数据审核、号段选取应用、分析SQL执行计划的关注点、Oracle开发误区探索、提升PL/SQL开发性能漫谈、管道函数的学习与实战应用、巧用锁特性避免...