In Oracle, if I have the following two tables
CREATE TABLE Test_Persons_A (
PersonID int,
LastName varchar(255),
FirstName varchar(255)
);
INSERT INTO Test_Persons_A
(PersonID,LastName,FirstName)
values(11,'LN_A1','FN_A1');
INSERT INTO Test_Persons_A
(PersonID,LastName,FirstName)
values(12,'LN_A2','FN_A2');
CREATE TABLE Test_Persons_B (
PersonID int,
LastName varchar(255),
FirstName varchar(255)
);
INSERT INTO Test_Persons_B
(PersonID,LastName,FirstName)
values(21,'LN_B1','FN_B1');
INSERT INTO Test_Persons_B
(PersonID,LastName,FirstName)
values(22,'LN_B2','FN_B2');
commit;
and I can do a query of a union as below:
with
UNIONED as
(
--block A to replaced by calling a function or stored proc---
select PersonID as PID, LastName as LN, FirstName as FN
from Test_Persons_A tp
where tp.LASTNAME like '%1%'
union
--block B to replaced by calling a function or stored proc---
select PersonID as PID, LastName as LN, FirstName as FN
from Test_Persons_B tp
where tp.LASTNAME like '%2%'
)
select * from UNIONED;
My question is how can i achieve something like the following:
with
UNIONED as
(
--block A replaced---
myFuncOrStoredProc('Test_Persons_A', '%1%');
union
--block B replaced---
myFuncOrStoredProc('Test_Persons_B', '%2%');
)
select * from UNIONED;
There has been a lot of post on 'how to return a table (or multiple rows of data) from a function or stored proc'. But because of the numerous answers, I feel more confused.
- Pipeline table function (https://stackoverflow.com/a/2830722/2041023)
- Bulk Collect (https://stackoverflow.com/a/2832735/2041023)
- Cursor (https://stackoverflow.com/a/46998148/2041023)
For such a small and simple (and I assume quite common) scenario and purpose, what could be the cleanest way to do it? (in particular, I prefer to avoid having to specify the type of each column for the returned table.)