如何在oracle中,定义对象数组,并调用

zhanlin 2007-06-03 03:18:01
如何在oracle中,用TYPE定义对象数组,然后用procedure进行调用?
传但个对象,我已经实现,不知道对象要怎么定义和调用,请各位高手指点,先谢谢了。
...全文
451 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
hongqi162 2007-06-03
  • 打赏
  • 举报
回复
我没有具体的试验过 既然在上面的demo中ProjectList可以做为create table 的数据类型在procedure中应该也是可以的,操作应该和上边的一样
hongqi162 2007-06-03
  • 打赏
  • 举报
回复
http://www.psoug.org/reference/varray.html


CREATE OR REPLACE TYPE Project AS OBJECT (
project_no NUMBER(2),
title VARCHAR2(35),
cost NUMBER(7,2));
/

desc project

SELECT type_name, typecode, instantiable
FROM user_types;
Define VARRAY of object type CREATE OR REPLACE TYPE ProjectList AS VARRAY(50) OF Project;
/

desc projectlist

SELECT type_name, typecode, instantiable
FROM user_types;
Create table based on VARRAY Create relational table department, which has a column of type ProjectList

CREATE TABLE department (
dept_id NUMBER(2),
name VARCHAR2(15),
budget NUMBER(11,2),
projects ProjectList);

desc department

set describe depth all linenum on indent on

desc department
Inserting into the VARRAY containing table Each item in column projects is a varray that will store
the projects scheduled for a given department.

Now, you are ready to populate relational table department.
In the following example, notice how varray constructor
ProjectList() provides values for column projects:

INSERT INTO department
VALUES(30, 'Accounting', 1205700,
ProjectList (Project(1, 'Design New Expense Report', 3250),
Project(2, 'Outsource Payroll', 12350),
Project(3, 'Evaluate Merger Proposal', 2750),
Project(4, 'Audit Accounts Payable', 1425)));

INSERT INTO department
VALUES(50, 'Maintenance', 925300,
ProjectList (Project(1, 'Repair Leak in Roof', 2850),
Project(2, 'Install New Door Locks', 1700),
Project(3, 'Wash Front Windows', 975),
Project(4, 'Repair Faulty Wiring', 1350),
Project(5, 'Winterize Cooling System', 1125)));

INSERT INTO department
VALUES(60, 'Security', 750400,
ProjectList (Project(1, 'Issue New Employee Badges', 13500),
Project(2, 'Find Missing IC Chips', 2750),
Project(3, 'Upgrade Alarm System', 3350),
Project(4, 'Inspect Emergency Exits', 1900)));

SELECT * FROM department;
Delete Record with VARRAY In the final example, you delete the Accounting Department
and its project list from table department:

DELETE FROM department WHERE dept_id = 30;

SELECT * FROM department;
CathySun118 2007-06-03
  • 打赏
  • 举报
回复
好像不行

3,491

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 高级技术相关讨论专区
社区管理员
  • 高级技术社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧