1

这个 sql 给出了一个错误,比如

ORA-01733: 此处不允许使用虚拟列。

没有GET_PROPERTY函数,SQL 就可以工作。如何解决?

UPDATE (SELECT VALUE, GET_PROPERTY (ORG.ID, 'BenefOperationCode') AS OPERATION_CODE
      FROM ORGANIZATION ORG, PROPERTY P
     WHERE ORG.EXTERNALKEY = '111' AND P.ID = ORG.ID AND P.IDX = 4)
SET VALUE = 123, OPERATION_CODE = 234;
4

1 回答 1

3

Edit: Below update won't work due to ORA-01776 error (thanks Vincent). See end of post for new method.

You are trying to update a function result. This is not possible. I presume you are trying to update the underlying value that is retrieved by the function. To do this you will need to combine the function code with the join between Organization and Property.

Let's say GET_PROPERTY is:

CREATE OR REPLACE FUNCTION GET_PROPERTY
(
    objectID_in NUMBER,
    propertyName_in VARCHAR
)
AS
    v_returnValue VARCHAR(32);
BEGIN
    SELECT
        PropertyValue INTO v_returnValue 
    FROM
        PropertyTable
    WHERE
        ObjectID = objectID_in
    AND PropertyName = propertyName_in;

    RETURN v_returnValue;
END

Your update would become:

--This wouldn't have worked.

Edit: Best to write a procedure to do it.

CREATE PROCEDURE UpdateMyTwoTables
(
    orgExternalKey_in in VARCHAR,
    propertyIdx_in in NUMBER,
    propertyName_in in VARCHAR,
    newValue_in in VARCHAR,
    newPropertyValue_in in VARCHAR
)
AS
BEGIN
    UPDATE
    (SELECT
        ORG.Value
    FROM
        ORGANIZATION ORG, 
        PROPERTY P
    WHERE 
        ORG.EXTERNALKEY = orgExternalKey_in 
        AND P.ID = ORG.ID AND 
        P.IDX = propertyIdx_in)
    SET
        Value = newValue_in;

    UPDATE
    (SELECT
        PropertyValue
    FROM
        PropertyTable,
        ORGANIZATION ORG,
        PROPERTY P
    WHERE
        PropertyTable.objectID = ORG.ID
    AND ORG.ID = P.ID
    AND ORG.EXTERNALKEY = orgExternalKey_in
    AND P.Idx = propertyIdx_in
    AND PropertyTable.PropertyName = propertyName_in)
    SET
        PropertyValue = newPropertyValue_in;


END;
于 2012-09-21T10:16:38.340 回答