赋予参考变量值oracle

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了赋予参考变量值oracle相关的知识,希望对你有一定的参考价值。

hHey,我想在node_ty的方法中设置赋值的值,但是我得到的错误是不允许通过Ref变量导航或者我想赋值的类型不正确。但是我得到的错误是不允许通过Ref变量导航,或者我想赋值的类型不正确。所以我真的不知道该怎么做。你能帮我解决这个问题吗?

CREATE OR REPLACE TYPE property_ty AS OBJECT(
name VARCHAR2(100)
);
/

CREATE OR REPLACE TYPE assignment_ty AS OBJECT(
value VARCHAR2(100),
property REF property_ty
);
/

CREATE OR REPLACE TYPE property_tty AS TABLE OF property_ty;
/


CREATE OR REPLACE TYPE node_ty AS OBJECT(
x NUMBER,
y NUMBER,
assignment REF assignment_ty,
property property_tty,
MEMBER PROCEDURE set_assignment (name VARCHAR2, value VARCHAR2)
);
/
CREATE OR REPLACE TYPE BODY node_ty AS
    MEMBER PROCEDURE set_assignment (name VARCHAR2, value VARCHAR2) AS
    prop_not_added EXCEPTION;
    prop_exists BOOLEAN := FALSE;
    assig_test assignment_ty;
    prop property_ty;
    BEGIN
        FOR i IN 1..self.property.COUNT
        LOOP
            IF property(i).name = name THEN
               prop.name :=name;
               assig_test.value :=value;
               assig_test.property := prop;
               assignment := assig_test;
               prop_exists := TRUE;

            END IF;
        END LOOP;

        IF prop_exists = FALSE THEN
            RAISE prop_not_added;
        END IF;

        EXCEPTION
            WHEN prop_not_added THEN
            DBMS_OUTPUT.PUT_LINE('Property cannot be set');
    END;
END;
/
答案

你必须创建必要的设置,然后从设置中查询数据.我只给出了与你不同的设置,其余的你可以保持与你的设置相同。

   create table t00 of property_ty;
   insert into t00 values('san');

   create table t0 of assignment_ty;
   insert into t0 select 'xxx',REF(p) from t00 p;

   CREATE OR REPLACE TYPE node_ty AS OBJECT(
    x NUMBER,
    y NUMBER,
    assignment REF assignment_ty,
    property property_tty,
    MEMBER PROCEDURE set_assignment (p_name VARCHAR2, p_value VARCHAR2)
    );

   create or replace TYPE BODY node_ty AS
MEMBER PROCEDURE set_assignment (p_name  VARCHAR2, p_value  VARCHAR2) AS
prop_not_added EXCEPTION;
prop_exists BOOLEAN := FALSE;
assig_test REF  assignment_ty;
prop1 property_ty;
prop REF property_ty;
BEGIN

    FOR i IN 1..self.property.COUNT
    LOOP
        IF property(i).name = p_name THEN

         SELECT REF(a) INTO assignment FROM t0 a,t00 b where a.value=p_value and b.name=p_name
         and ref(b)=property;

           prop_exists := TRUE;

        END IF;
    END LOOP;

    IF prop_exists = FALSE THEN
        RAISE prop_not_added;
    END IF;

    EXCEPTION
        WHEN prop_not_added THEN
        DBMS_OUTPUT.PUT_LINE('Property cannot be set');
END;
END;

以上是关于赋予参考变量值oracle的主要内容,如果未能解决你的问题,请参考以下文章

从活动中更改片段的变量值

无法减去 oracle 形式的变量值

如何为每个片段保存一个变量值以重用它? [关闭]

TypeScript: switch enum

python使用oracle查询数据库,查询语句中使用变量值

oracle中如何获取最后执行的SQL语句并绑定变量值