fetch table name from a column for from clause

前端 未结 2 1836
无人及你
无人及你 2020-12-20 10:57

I have a view t with me which has a column for table name and another column which has where clause condition.

    id| name|table_in| where_clause

    1 | S         


        
2条回答
  •  生来不讨喜
    2020-12-20 11:23

    You need dynamic sql to do this:

    CREATE OR REPLACE PROCEDURE create_cursor
    IS
      l_statement VARCHAR2(32767);
      CURSOR v_records
      IS
        SELECT * FROM t;
    BEGIN
      FOR temp IN v_records
      LOOP
        l_statement := 'INSERT INTO myTable (id, name)
              select id, name from ' || temp.table || 
              ' where ' || temp.where_clause;
        EXECUTE immediate l_statement;
      END LOOP;
    END;
    /
    

提交回复
热议问题