如何在Oracle中修改Collection类型的变量。
2007-11-23 12:00
405 查看
在如何在JAVA程序中使用Struct一次传入多条数据给Oracle的存储过程中我介绍了如何通过定义Struct和Array在JAVA程序中一次传入多条数据给Oracle的存储过程。
步骤一:定义对象类型。
CREATE TYPE department_type AS OBJECT (
DNO NUMBER (10),
NAME VARCHAR2 (50),
LOCATION VARCHAR2 (50)
);
步骤二:定义一个对象类型的数组对象。
CREATE TYPE dept_array AS TABLE OF department_type;
步骤三:定义存储过程来插入数据。
CREATE OR REPLACE PACKAGE objecttype AS
PROCEDURE insert_object (d dept_array);
END objecttype;
CREATE OR REPLACE PACKAGE BODY objecttype
AS
PROCEDURE insert_object (d dept_array)
AS
BEGIN
FOR i IN d.FIRST..d.LAST
LOOP
INSERT INTO department_teststruct
VALUES (d(i).dno,d(i).name,d(i).location);
END LOOP;
END insert_object;
END objecttype;
如果我们需要对dept_array类型的d进行的更新的话,那么直接使用下面的语句系统会提示错误。
CREATE OR REPLACE PACKAGE objecttype AS
PROCEDURE insert_object (d dept_array);
END objecttype;
CREATE OR REPLACE PACKAGE BODY objecttype
AS
PROCEDURE insert_object (d dept_array)
AS
BEGIN
FOR i IN d.FIRST..d.LAST
LOOP
d(i).location := 'New Loc'||i;
INSERT INTO department_teststruct
VALUES (d(i).dno,d(i).name,d(i).location);
END LOOP;
END insert_object;
END objecttype;
错误提示: PLS-00363: expression 'D.LOCATION' cannot be used as an assignment target
正确的方法是:
CREATE OR REPLACE PACKAGE BODY objecttype
AS
procedure insert_object(d in out dept_array)
is
begin
for i in 1..d.count loop --与FOR i IN d.FIRST..d.LAST 功能相同
d(i).location := 'New Loc'||i;
INSERT INTO department_teststruct
VALUES (d (i).dno,d (i).name,d (i).location);
end loop;
end insert_object;
END objecttype;
关键问题是:d 必须是output类型(代码中红色粗体标记部分)。
参考内容:http://forums.oracle.com/forums/thread.jspa?messageID=2208830
步骤一:定义对象类型。
CREATE TYPE department_type AS OBJECT (
DNO NUMBER (10),
NAME VARCHAR2 (50),
LOCATION VARCHAR2 (50)
);
步骤二:定义一个对象类型的数组对象。
CREATE TYPE dept_array AS TABLE OF department_type;
步骤三:定义存储过程来插入数据。
CREATE OR REPLACE PACKAGE objecttype AS
PROCEDURE insert_object (d dept_array);
END objecttype;
CREATE OR REPLACE PACKAGE BODY objecttype
AS
PROCEDURE insert_object (d dept_array)
AS
BEGIN
FOR i IN d.FIRST..d.LAST
LOOP
INSERT INTO department_teststruct
VALUES (d(i).dno,d(i).name,d(i).location);
END LOOP;
END insert_object;
END objecttype;
如果我们需要对dept_array类型的d进行的更新的话,那么直接使用下面的语句系统会提示错误。
CREATE OR REPLACE PACKAGE objecttype AS
PROCEDURE insert_object (d dept_array);
END objecttype;
CREATE OR REPLACE PACKAGE BODY objecttype
AS
PROCEDURE insert_object (d dept_array)
AS
BEGIN
FOR i IN d.FIRST..d.LAST
LOOP
d(i).location := 'New Loc'||i;
INSERT INTO department_teststruct
VALUES (d(i).dno,d(i).name,d(i).location);
END LOOP;
END insert_object;
END objecttype;
错误提示: PLS-00363: expression 'D.LOCATION' cannot be used as an assignment target
正确的方法是:
CREATE OR REPLACE PACKAGE BODY objecttype
AS
procedure insert_object(d in out dept_array)
is
begin
for i in 1..d.count loop --与FOR i IN d.FIRST..d.LAST 功能相同
d(i).location := 'New Loc'||i;
INSERT INTO department_teststruct
VALUES (d (i).dno,d (i).name,d (i).location);
end loop;
end insert_object;
END objecttype;
关键问题是:d 必须是output类型(代码中红色粗体标记部分)。
参考内容:http://forums.oracle.com/forums/thread.jspa?messageID=2208830
相关文章推荐
- 如何在Oracle中向Collection类型的变量中逐条插入数据。
- Oracle 如何修改列的数据类型
- Oracle 如何修改列的数据类型
- Oracle 如何修改列的数据类型
- Oracle 如何修改列的数据类型
- Oracle 如何修改列不为空的时候的数据类型
- Oracle 如何修改列的数据类型
- 如何修改oracle字段类型
- oracle中修改已有字段数据类型为clob的方法以及ssh框架中如何保存clob字段
- Oracle 如何修改列的数据类型
- Oracle 如何修改列的数据类型
- Oracle 如何修改列的数据类型 (不积跬步,无以至千里)
- Oracle 如何修改表名, Oracle 如何修改列名 ,Oracle 如何修改字段类型语句
- 【原】Oracle 如何修改列的数据类型
- 【原】Oracle 如何修改列的数据类型
- Oracle 如何修改列的数据类型
- Oracle 如何修改列的数据类型
- R 如何给因子的类型变量修改元素
- Oracle 如何修改列的数据类型
- Oracle 如何修改列的数据类型