oracle - SQL select statement union all with itself -
hi have complicated sql statement returns results.
of results in table same id.
have result set first plus duplicate of rows belong other table.
the code below wrong shows trying achieve:
select myrules.* (complicated sql statement) myrules union select myrules inner join table2 on myrules.id =table2.id;
is possible?
ps1. don't want touch complicated sql statement.
ps2. error myrules table or view not exist
edit: based on answers try create procedure returns cursor got error in line open cursor:
procedure get_rules(in_id in tablea.reconciliation_id%type, io_cursor in out t_ref_cursor) begin myrules ( complicated sql statement) open io_cursor -- errors here: missing select keyword select * myrules union select * myrules inner join table2 on myrules.id = table2.id; end get_rules;
yes, valid union all
query query on same table. better use with
in case:
with myrules ( complicated sql statement ) select * myrules union select * myrules inner join table2 on myrules.id = table2.id;
if want use with
in cursor, embed in cursor, not stored procedure:
procedure get_rules(in_id in tablea.reconciliation_id%type, io_cursor in out t_ref_cursor) begin open io_cursor myrules ( complicated sql statement ) select * myrules union select * myrules inner join table2 on myrules.id = table2.id; end get_rules;
Comments
Post a Comment