Assign value to a field of rowtype where `field name` is a string

前端 未结 2 1348
遥遥无期
遥遥无期 2021-02-06 13:23

I want to assign a value to a rowtype\'s field but I don\'t know how to do it.

Suppose that I have a table X inside my database.

Suppose also that I hav

2条回答
  •  名媛妹妹
    2021-02-06 13:45

    try this:

    CREATE OR REPLACE PROCEDURE ROW_CHANGER(
        tRow            IN MyTable%ROWTYPE,
        col_name        IN VARCHAR,
        nValue          IN NUMBER) 
       AS
        dynamic_request VARCHAR(300);
    BEGIN 
        dynamic_request := 'BEGIN  :t_row.'||COL_NAME ||':= :n_value; END;';
        EXECUTE IMMEDIATE dynamic_request
             USING IN OUT  TROW, IN nValue;
    END;
    

    this is because in your EXECUTE IMMEDIATE the tRow MyTable%ROWTYPE is not defined,

    so we defined it with using statement.

提交回复
热议问题