嗨我有一个非常复杂的SQL语句,返回一些结果。
某些结果在另一个具有相同Id的表中。
我想有一个结果集像第一个加上所有属于另一个表的行的副本。SQL选择语句联合所有本身
下面的代码是错误的,但显示了我想实现:
Select myRules.*
From (Complicated sql statement) myRules
Union All
Select from myRules
inner join Table2
on myRules.Id =Table2.Id;
这可能吗?
PS1。我不想触及复杂的sql语句。
PS2。我得到的错误是,myRules表或视图不存在
编辑:根据您的回答我尝试创建一个返回游标的过程,但我得到了在该行的错误我打开游标:
procedure Get_Rules(in_Id in tableA.Reconciliation_Id%type,
io_cursor in out t_ref_cursor) is
begin
With myRules as (
complicated sql statement)
open io_cursor for -- ERRORS here: missing SELECT keyword
select *
from myRules
union all
select *
from myRules
inner join Table2
on myRules.Id = Table2.Id;
end Get_Rules;
您是否尝试过的CTE? (公用表格表达。) – jarlh