简体   繁体   English

PL / SQL动态表名称

[英]PL/SQL Dynamic Table Names

I'm pretty new to Oracle so not entirely sure this is possible, or if perhaps I'm going about it the wrong way but here goes ... 我对Oracle还是很陌生,因此不能完全确定是否有可能,或者如果我采用错误的方式进行操作,但是这里...

Part of an old feeder script I'm fixing is looping through ~ 20 tables (could change anytime) to populate relevant staging tables. 我正在修复的旧的供稿器脚本的一部分正在遍历〜20个表(可以随时更改)以填充相关的登台表。 This part is currently very basic: 这部分目前非常基础:

...

INSERT INTO staging_tbl_1(
     SELECT *
     FROM source_tbl_1    
);

INSERT INTO staging_tbl_2(
         SELECT *
         FROM source_tbl_2    
);

...

Some of the fields in the source database have different constraints etc which means that every now and then it will throw an exception and the feeder will stop. 源数据库中的某些字段具有不同的约束等,这意味着它会不时地抛出异常,并且供稿器将停止。 What I'm hoping to do is create a procedure within the existing feeder package to loop through each row in each record before it is inserted and simply wrap it in an exception block. 我希望做的是在现有的Feeder程序包中创建一个过程,以在插入记录之前遍历每条记录中的每一行,并将其简单地包装在异常块中。 This way it can be logged without causing the feeder to stop. 这样就可以记录它,而不会导致进纸器停止。

Essentially I'm chasing something like this: 本质上,我正在追逐这样的东西:

BEGIN procedure_x(source_record, staging_record)

  -- Perform validation to ensure records exit

  -- Loop through all record rows
  FOR row IN (SELECT * FROM source_record) LOOP

     -- Wrap in exception block

     -- Insert into staging record

     -- Log exception if it occurs
  END LOOP;         
END

I've attempted ref cursors however in order to get them to work I would also need to know the rowtype in advance (from my limited understanding). 我尝试了ref游标,但是为了使它们工作,我还需要提前了解行类型(根据我的有限理解)。 I've also tried execute immediate however I cannot find a way to loop this in an appropriate way. 我也尝试立即执行,但是我找不到合适的方式来循环执行。 Are there any other ways to tackle this? 还有其他解决方法吗?

Additional: 额外:

I realise that we really should be fixing the source of the problem rather than going about it like this, unfortunately it is far outside my area of influence. 我意识到我们确实应该解决问题的根源,而不是像这样去解决,不幸的是,这远远超出了我的影响范围。

It is possible to do this without making a separate procedure and just wrap all of the table references in a loop, however I'd like to leave this as a last resort. 可以执行此操作而无需执行单独的过程,而只需将所有表引用包装在一个循环中即可,但是我想把它留作最后的选择。

Oracle has functionality for logging of DML errors. Oracle具有记录DML错误的功能。 Use it with single SQL statements. 与单个SQL语句一起使用。 Don't go row-by-row and make your processes crawl. 不要一行一行地进行,以使您的进程爬行。

http://docs.oracle.com/cd/B19306_01/server.102/b14231/tables.htm#ADMIN10261 http://docs.oracle.com/cd/B19306_01/server.102/b14231/tables.htm#ADMIN10261

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM