ORACLE PL/SQL 记录(Record)学习笔记(二)
二、以形参的形式定义和使用记录、对象类型
在用作形式参数时,记录类型和对象类型有很多相同之处。在将它们作为游标、函数或过程的形式参数以前,事先都必须定义一个记录类型或者对象类型。
如下例所示:
记录
DECLARE
-- Define a record type.
TYPE individual_record IS RECORD
(individual_id INTEGER
,first_name VARCHAR2(30 CHAR)
,middle_initial VARCHAR2(1 CHAR)
,last_name VARCHAR2(30 CHAR));
-- Define a record type.
TYPE address_record IS RECORD
(address_id INTEGER
,individual_id INTEGER
,street_address1 VARCHAR2(30 CHAR)
,street_address2 VARCHAR2(30 CHAR)
,street_address3 VARCHAR2(30 CHAR)
,city VARCHAR2(20 CHAR)
,state VARCHAR2(20 CHAR)
,postal_code VARCHAR2(20 CHAR)
,country_code VARCHAR2(10 CHAR));
-- Define a record type of two user defined record type variables.
TYPE individual_address_record IS RECORD
(individual INDIVIDUAL_RECORD
,address ADDRESS_RECORD);
-- Define a variable of a user defined compound record type.
individual_address INDIVIDUAL_ADDRESS_RECORD;
-- Define a local procedure to manage addresses inserts.
PROCEDURE insert_address
(address_in ADDRESS_RECORD) IS
BEGIN
-- Insert the values into the target object.
INSERT
INTO addresses
VALUES
(address_in.address_id
,address_in.individual_id
,address_in.street_address1
,address_in.street_address2
,address_in.street_address3
,address_in.city
,address_in.state
,address_in.postal_code
,address_in.country_code);
END insert_address;
-- Define a local procedure to manage addresses inserts.
PROCEDURE insert_individual
(individual_in INDIVIDUAL_RECORD) IS
BEGIN
-- Insert the values into the table.
INSERT
INTO individuals
VALUES
(individual_in.individual_id
,individual_in.first_name
,individual_in.middle_initial
,individual_in.last_
相关文档:
select decode('X','Q','变量1','变量2') from dual
select sysdate,to_char(sysdate,’yyyy-mm-dd hh24:mi:ss’) from dual
select to_date(’2003-10-17 21:15:37’,’yyyy-mm-dd hh24:mi:ss’) from dual
日期格式参数 含义说明
D 一周中的星期几
DAY 天的名 ......
建表
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
转载
------------------- ......
执行顺序:从左到右,变量优先,逐行更新
摘自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 ......