Parameterized views -vs- views with where conditions
Hi Tom, I am a long time reader of asktom.oracle.com and delighted to see 'submit a new question' enabled after a very long time. Which of the following would be a better choice from scalability, performance, ease of development, ease of maintenance. First option:- --------------- Develop a view and have where clause embeded in different queries (JDBC/Reporting layers etc). <i>Example: -------- SELECT ... FROM EMPLOYEE_VW WHERE HIRE_DATE BETWEEN <p_min_date> AND <p_max_date> </i> Second option:- --------------- Develop a parameterized view using sys_context. Have client set the parameters using sys_context. <i>Example: -------- -- Set the context for Min and max dates. DBMS_SESSION.set_context (namespace => 'CTX_SLR_PARAMS', ATTRIBUTE => 'min_date', VALUE => p_min_date ); DBMS_SESSION.set_context(namespace => 'CTX_SLR_PARAMS', ATTRIBUTE => 'max_date', VALUE => p_max_date );</i> <i>-- Query the generic view. SELECT ... FROM EMPLOYEE_PARAM_VIEW;</i> <i>-- View is built like this. SELECT ... FROM EMPLOYEE WHERE hire_date BETWEEN SYS_CONTEXT ('CTX_SLR_PARAMS', 'min_date') AND SYS_CONTEXT ('CTX_SLR_PARAMS', 'max_date')</i> I tried bench marking (trace & Explain Plan) with simple tables and i didn't see any difference between above. It would be great if you could provide when would a parameterized view make sense. Thank you, Giri.
Parameterized views -vs- views with where conditions