Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Can you pass a table name into a stored procedure?
Well, I could get the method above to work, if there were no more than
1 record in the expand route tables. As soon as the tables held more
than one record, the usual oracle "returns more than one row for single
row query" exception is thrown.
However, I did try you method Malcolm, in fact I had in mind to try a union at some point anyway, and it does work. However, although its fast enough doing counts, I think we would lose all indexes on individual tables if we we try joining to them. This works, anyway:
CREATE OR REPLACE PROCEDURE "ACT_JUN"."ZAP"
(TABLE_NUN in number := 1)
IS
BEGIN
insert into A (B) select CNT from
(
with CURRENT_EXPAND_ROUTE_TABLE as
(
select * from ( select TRAIN_EXPANDED_ROUTE_I, train_i, p_version_i from TRAIN_EXPANDED_ROUTE_001 where TABLE_NUN = 1 union all select TRAIN_EXPANDED_ROUTE_I, train_i, p_version_i from TRAIN_EXPANDED_ROUTE_002 where TABLE_NUN = 2 union all select TRAIN_EXPANDED_ROUTE_I, train_i, p_version_i from TRAIN_EXPANDED_ROUTE_003 where TABLE_NUN = 3 union all select TRAIN_EXPANDED_ROUTE_I, train_i, p_version_i from TRAIN_EXPANDED_ROUTE_004 where TABLE_NUN = 4 union all select TRAIN_EXPANDED_ROUTE_I, train_i, p_version_i from TRAIN_EXPANDED_ROUTE_005 where TABLE_NUN = 5 )