删除在过程中创建的表,获取过程的编译错误 [英] Table created in a procedure is dropped, Getting compilation error for procedure

查看:87
本文介绍了删除在过程中创建的表,获取过程的编译错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

创建过程的第一步是检查表XYZ是否存在.如果确实如此,则继续在表XYZ上进行进一步的计算,但如果不存在,则创建该表,然后继续进行计算(在表中插入新记录).

The first step of created procedure is to check if table XYZ exist. If it does then go ahead with further calculation on the table XYZ but if it does not exist create the table and then go ahead with the calculation(inserting new records in the table).

因此出于测试目的,我放下了桌子.我放下表格的那一刻,我从程序中得到编译错误,说该表格不存在.

So for testing purpose I dropped the table. The moment I dropped the table I am getting compilation error from the procedure saying that table does not exist.

我应该如何解决此问题.我无法更改逻辑.

How should I solve this issue.I can not change the logic.

推荐答案

需要检查表是否存在的代码表明软件体系结构不良.无需动态创建表.这是一种反模式(至少在Oracle中是这样).但是,我们经常会在这个问题上看到很多变化,因此很明显,这种反模式正在蓬勃发展.

Code which needs to check whether a table exists indicates bad software architecture. There should be no need to create tables on the fly. It's an anti-pattern (at least in Oracle). However, we see variations on this problem often enough, so it's obvious that this anti-pattern is thriving in the wild.

如果您确实需要实施这种解决方案(无论出于何种原因),则正确的方法是使用代码将表构建代码与表分开.为他们准备单独的包裹.

If you really need to implement such a solution (for whatever reason) the correct approach is to separate table building code from the table using code. Have separate packages for them.

begin
    pkg_ddl.build_table_xyz;
    pkg_calc.run_xyz_job;
end;

如果表XYZ不存在,则pkg_calc.run_xyz_job()无效.但是,它的无效不会阻止pkg_ddl.build_table_xyz()执行.然后,当外部程序调用pkg_calc.run_xyz_job()时,它将编译该过程.

If table XYZ doesn't exist pkg_calc.run_xyz_job() is invalid. However it's invalidity won't prevent pkg_ddl.build_table_xyz() from executing. Then, when the outer program calls pkg_calc.run_xyz_job() it will compile the procedure.

这篇关于删除在过程中创建的表,获取过程的编译错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆