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
相关文档:
数据字典dict总是属于Oracle用户sys的。
1、用户:
select username from dba_users;
改口令
alter user spgroup identified by spgtest;
2、表空间:
select * from dba_data_files;&nbs ......
关于存储过程和函数的定义网上一搜一大把,这里就不特殊介绍了,这里就只对我自己写的几种格式的存储过程和函数做一些总结,希望对大家有点帮助。
一:存储过程
1:最普通的一种。(传参,查询游标,执行,循环游标做插入动作)。
create or replace procedure zy2040_sirole(rolekey in varchar2) ......
建表
create table users(
id number(4) primary key,
username varchar2(10),
password varchar2(10)
)
查询表并解锁表(即可以点击输入框下面的"锁"图标工具, 即"Edit data")
select * from users for update
删除表中多余的列
alter table mobilephone drop column mobiletype
转载
------------------- ......
二、以形参的形式定义和使用记录、对象类型
在用作形式参数时,记录类型和对象类型有很多相同之处。在将它们作为游标、函数或过程的形式参数以前,事先都必须定义一个记录类型或者对象类型。
如下例所示:
记录
DECLARE
-- Define a record type.
TYPE individual_record IS RECORD
(individual_id ......