易截截图软件、单文件、免安装、纯绿色、仅160KB

ORACLE PL/SQL 集合学习笔记(二)

三、嵌套表的使用方法
 
1、将嵌套表定义为PL/SQL的程序构造块
 
TYPE type_name IS TABLE OF element_type[NOT NULL];
 
如下例所示:
DECLARE

-- Define a nested table of variable length strings.
TYPE card_table IS TABLE OF VARCHAR2(5 CHAR);

-- Declare and initialize a nested table with three rows.
cards CARD_TABLE := card_table(NULL,NULL,NULL);
BEGIN

-- Print title.
dbms_output.put_line(
'Nested table initialized as nulls.');
dbms_output.put_line(
'----------------------------------');

-- Loop through the three records.
FOR i IN 1..3 LOOP

-- Print the contents.
dbms_output.put ('Cards Varray ['||i||'] ');
dbms_output.put_line('['||cards(i)||']');

END LOOP;

-- Assign values to subscripted members of the varray.
cards(1) := 'Ace';
cards(2) := 'Two';
cards(3) := 'Three';

-- Print title.
dbms_output.put (CHR(10)); -- Visual line break.
dbms_output.put_line(
'Nested table initialized as Ace, Two and Three.');
dbms_output.put_line(
'-----------------------------------------------');

-- Loop through the three records to print the varray contents.
FOR i IN 1..3 LOOP

dbms_output.put_line('Cards ['||i||'] '
|| '['||cards(i)||']');

END LOOP;
END;
/
 
 
2、将嵌套表类型定义和用作PL/SQL的对象类型
CREATE OR REPLACE TYPE type_name
AS TABLE OF element_type [NOT NULL];
 
如下例所示:
-- Define a varray of four rows of variable length strings.
CREATE OR REPLACE TYPE card_unit_varray
AS VARRAY(13) OF VARCHAR2(5 CHAR);
/

-- Define a varray of four rows of variable length strings.
CREATE OR REPLACE TYPE card_suit_varray
AS VARRAY(4) OF VARCHAR2(8 CHAR);
/

-- Define a table of variable length strings.
CREATE OR REPLACE TYPE card_deck_table
AS TABLE OF VARCHAR2(17 CHAR);
/

DECLARE

-- Define a counter to manage 1 to 52 cards in a deck.
counter INTEGER


相关文档:

Oracle系统表查询

 数据字典dict总是属于Oracle用户sys的。  
  1、用户:  
   select username from dba_users;  
  改口令  
   alter user spgroup identified by spgtest;   
  2、表空间:  
   select * from dba_data_files;&nbs ......

oracle :存储过程和函数的几种写法

关于存储过程和函数的定义网上一搜一大把,这里就不特殊介绍了,这里就只对我自己写的几种格式的存储过程和函数做一些总结,希望对大家有点帮助。
 一:存储过程
  
1:最普通的一种。(传参,查询游标,执行,循环游标做插入动作)。
create or replace procedure zy2040_sirole(rolekey in varchar2) ......

Oracle存储过程的执行

declare
msg varchar(1000);    --定义一个变量用于显示传出的信息
begin
PRO_TACCOUNT_RECOUNT ('B9D2B59A955541298D59EA8C35668CFD',msg);   --执行存储过程
dbms_output.put_line(msg);   --输出变量
end; ......

SQL Update语句的执行顺序

执行顺序:从左到右,变量优先,逐行更新
 摘自CSDN的例子(http://topic.csdn.net/u/20091030/16/7fd75fa6-bdb9-4516-9b27-48aef69703ba.html
http://topic.csdn.net/u/20090904/16/e5dad9c7-fb59-41b9-b28d-e3b71c3e8420.html)
1.变量优先
create table #t (field1 varchar(10),field2 varchar(10))
insert #t sel ......

ORACLE PL/SQL 记录(Record)学习笔记(一)

在PL/SQL程序设计中,有三种定义记录类型的方法:一种是使用%ROWTYPE属性;另一种是在PL/SQL程序的声明部分显示定义记录类型;最后一种方法是将记录类型定义为数据库结构或对象类型。
我先简单的介绍一个下面要用到的表的结构(黑体标明的字段为主键):
INDIVIDUALS表
 
INDIVIDUAL ID
FIRST NAME
MIDDLE_INITI ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号