如何在plsql中执行类似简单数组的操作?最好用例子来解释。
让我们看看我有什么
PROCEDURE MyProcedure(name varchar2 := '', father varchar2 := '', description varchar2 := '') IS
BEGIN
UPDATE BC_ACTIONTYPEGROUP SET
ColumnName = name,
ColumnFather = father,
ColumnDecription = description
WHERE
ColumnName = name;
IF SQL%ROWCOUNT = 0 THEN
INSERT INTO TableNames (ColumnName, ColumnFather, ColumnDescription)
VALUES (name, description, father);
END IF;
END;
/
MyProcedure('John', '', 'Little John has three brothers');
MyProcedure('George', 'YES', 'George is father of John');
我需要这样的东西
MyProcedure(name=>'John', description=>'Little John has three brothers');
MyProcedure(name=>'George', father=>'YES', description=>'George is father of John');
有可能吗?或者在程序中如何使用这样的东西最简单的方法是什么。
我是IT的新生,所以感谢任何建议。
答案 0 :(得分:1)
我不确定您是否在寻找数组或哈希表(关联数组)。
阵列很简单:
declare
TYPE names IS VARRAY(6) OF VARCHAR2(20) ;
name names;
name names.extend(1);
begin
name(1) := 'John Doe';
end;
参考:
http://docs.oracle.com/cd/B10500_01/appdev.920/a96624/05_colls.htm
对于关联数组,您必须定义一个类型,如:
TYPE my_type IS TABLE OF VARCHAR2(256) INDEX BY VARCHAR2(5);
-- Declare actual associative array using new data type.
my_array my_type;
my_key VARCHAR2(5);
看看这个:
http://javaconfessions.com/2008/08/associative-arrays-hashtables-for-plsql.html
http://tylermuth.wordpress.com/2008/02/21/plsql-associative-arrays/
然后按照以下步骤将数组传递给函数或过程: