从 from 子句的列中获取表名

fetch table name from a column for from clause(从 from 子句的列中获取表名)
本文介绍了从 from 子句的列中获取表名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个视图 t,其中有一列用于表名,另一列具有 where 子句条件.

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 | Sam | t1 | age = 22

    2 | John| t2 | age = 23 and sex = 'male'

等等...

现在,我已将记录放入游标中,并且我想运行每个查询.

Now, I have put the records in a cursor and I want to run each query.

    create or replace procedure create_cursor 
    is

    CURSOR v_records is
    select * from t ;

    begin

    FOR temp IN v_records LOOP
        INSERT INTO myTable (id, name)
        select temp.id, temp.name 
        from temp.table where temp.where_clause;

        END LOOP;


    end;
    /

myTable 是另一个表,我想在其中放置记录以备下次使用.

myTable is another table in which I want to put the records for next purpose.

推荐答案

@Akshay,

请在下面找到代码以供参考.

Please find the code below for your reference.

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 '||temp.id||','
   ||temp.name|| ' from ' || temp.table1 
   || ' where ' || temp.where_clause;

  execute immediate l_statement;
  end loop;
end;
/

这篇关于从 from 子句的列中获取表名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Execute complex raw SQL query in EF6(在EF6中执行复杂的原始SQL查询)
Hibernate reactive No Vert.x context active in aws rds(AWS RDS中的休眠反应性非Vert.x上下文处于活动状态)
Bulk insert with mysql2 and NodeJs throws 500(使用mysql2和NodeJS的大容量插入抛出500)
Flask + PyMySQL giving error no attribute #39;settimeout#39;(FlASK+PyMySQL给出错误,没有属性#39;setTimeout#39;)
auto_increment column for a group of rows?(一组行的AUTO_INCREMENT列?)
Sort by ID DESC(按ID代码排序)