Create VIEW retrieving from dynamically configured table/queries [message #638430] |
Thu, 11 June 2015 09:13 |
gtriant
Messages: 42 Registered: September 2006
|
Member |
|
|
Hello,
I am looking for the following.
To create a VIEW but to specify the source tables based on some parameter.
Something like:
CREATE OR REPLACE FORCE VIEW CCS3.NON_BILLABLE_ACCOUNTS2
(
fname,
lname
)
AS
SELECT *
FROM (CASE when get_flag('switch_table')=0
(
SELECT fname,
lname
FROM T1 t1, T2 t2
WHERE t1.t1_id = t2.t2_id
)
else
(
SELECT fname,
lname
FROM P1 p1, P2 p2
WHERE p1.p1_id = p2.p2_id
)
);
Is this possible in general at all?
Thank you
|
|
|
|
|
|
|
|
Re: Create VIEW retrieving from dynamically configured table/queries [message #638440 is a reply to message #638434] |
Thu, 11 June 2015 12:34 |
gtriant
Messages: 42 Registered: September 2006
|
Member |
|
|
Both are more or less correct.
The second is better phrasing of the idea.
The code of the dummy function is not significant. It would return a flag indicating which tables to use. This flag would be set/modified by the procedure that performs MERGE on the tables in question, so that upon merging the other set of tables would be used. Something like that.
If the idea is now more clear, would someone now if it is feasible?
|
|
|
Re: Create VIEW retrieving from dynamically configured table/queries [message #638441 is a reply to message #638440] |
Thu, 11 June 2015 12:43 |
|
Michel Cadot
Messages: 68641 Registered: March 2007 Location: Nanterre, France, http://...
|
Senior Member Account Moderator |
|
|
Quote:This flag would be set/modified by the procedure that performs MERGE on the tables in question, so that upon merging the other set of tables would be used.
Do you mean a select on the view will modify the data in the tables it is currently querying?
So, yes, the code of the functional is not only significant but mandatory to give an accurate and appropriate answer.
[Updated on: Thu, 11 June 2015 12:43] Report message to a moderator
|
|
|
|
|
|
|
|
Re: Create VIEW retrieving from dynamically configured table/queries [message #638568 is a reply to message #638559] |
Mon, 15 June 2015 08:21 |
gtriant
Messages: 42 Registered: September 2006
|
Member |
|
|
Hello,
The function that would check the flag indicating which set of tables to use is looking a name/value table called FLAGS, to retrieve the current value:
CREATE OR REPLACE FUNCTION "GET_FLAG" ( IN_FLAG_NAME IN FLAGS.NAME%TYPE ) RETURN FLAGS.VALUE%TYPE IS
l_RESULT FLAGS.VALUE%TYPE;
BEGIN
SELECT VALUE INTO l_RESULT FROM FLAGS WHERE NAME = IN_FLAG_NAME;
RETURN l_RESULT;
END;
/
The value would be set by some other event not related to the main question.
Thank you.
|
|
|
|
|
|
|
|
Re: Create VIEW retrieving from dynamically configured table/queries [message #638591 is a reply to message #638588] |
Mon, 15 June 2015 11:50 |
|
Michel Cadot
Messages: 68641 Registered: March 2007 Location: Nanterre, France, http://...
|
Senior Member Account Moderator |
|
|
gtriant wrote on Mon, 15 June 2015 17:48Hello.
Parameter name would be "SWITCH_TABLE" always, parameter value would be "0" or "1" (or could be any two different values, even the table name to use).
The session changing these values as stated before is not the same.
I still don't see the significance of this, but not important.
Thank you very much.
I advice you to create a global context and use a view similar to the one John posted:
create view twotab as
select ename from emp where sys_context('MyAppCtx','SWITCH_TABLE') != '0'
union all
select dname from dept where sys_context('MyAppCtx','SWITCH_TABLE') = '0';
You have to set the context at instance startup from the value inside the table.
When you modify the value in the table you also modify the value in the context.
A global context variable is a variable inside the SGA and so request no table access and cost almost nothing to get.
The view is defined with exclusive conditions, the optimizer knows it has to access one table or the other one but not both.
[Updated on: Wed, 17 June 2015 01:30] Report message to a moderator
|
|
|
|