Oracle视图或表函数返回在另一个表中存储为文本的查询联合的函数
假设我有一个“规则”表,该表具有一个列,该列包含oracle查询中的varchar2列中:
行 | 查询 |
---|---|
1 | 选择'hardcoded_tablename_1'tablename,request_id table_1,其中state> = 4 and status_date_date< *一些日期数学到达这里* |
2 | 选择'table_2'tableName,t2.request_id table_2 t2 t2 t2 t2 table_1 t1 on t1.request_id = t2.parent_id whend t1.status> = 4 and t1.resolve_date_date_date_date_date_date_date_date_date_date_date_date_date_date_date < *一些日期数学到达这里* |
如果这永远不会改变,我只会通过这些查询的结合来查看。 我们的要求是,我们能够以领导力的兴趣添加或修改这些规则。
因此,我需要的是:
- 一个非常聪明的视图(我认为不可能)执行和工会所有这些存储的查询字符串
或
- 表函数,该函数返回这些存储的查询字符串的结合结果。 (我认为这是更有可能的解决方案)
它只会是这两个列:表格的硬编码名称和记录的ID。
有人可以帮我开始这个吗?
谢谢
Let's say that I have a "Rules" table that has a column that contains oracle queries in a varchar2 column:
Row | Query |
---|---|
1 | select 'Hardcoded_Tablename_1' tablename, request_id from table_1 where status >= 4 and resolve_date < *some date math goes here* |
2 | select 'Table_2' tablename, t2.request_id from table_2 t2 join table_1 t1 on t1.request_id = t2.parent_id where t1.status >= 4 and t1.resolve_date < *some date math goes here* |
If this were never going to change, I'd just make a view with a union of these queries.
Our requirement is that we be able to add to or to modify these rules on-the-fly at the whims of leadership.
So, what I need is either:
- a very smart view (I think impossible) that executes and unions all of these stored query strings
or
- a table function that returns the results of the union of these stored query strings. (I think this is the more likely solution)
It will only ever be those two columns: The hardcoded name of the table and the ID of the record.
Can someone help get me started on this?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
管道
函数。首先创建类型:
然后函数:
然后,如果您有示例数据:
那么您可以在表集合表达式中使用该函数:
输出:
db&lt;&gt; >在这里
You can use a
PIPELINED
function.First create the types:
Then the function:
Then, if you have the sample data:
Then you can use the function in a table collection expression:
Which outputs:
db<>fiddle here
一个选项可能是返回避难所的函数。
函数从
规则>表中创建所有查询的联合,并将其用作反驳器的 source :
测试:
One option might be a function that returns refcursor.
Function creates union of all queries from the
rules
table and uses it as a source for the refcursor:Testing: