Home » SQL & PL/SQL » SQL & PL/SQL » Passing bind variables to a VIEW (Oracle 11g)
Passing bind variables to a VIEW [message #606265] |
Tue, 21 January 2014 16:30 |
|
ora4me
Messages: 1 Registered: August 2012
|
Junior Member |
|
|
I have a query like this:
with test1 as (
select emp.empno, emp.deptno, emp.name, emp.hiredate, dept.deptname
from emp, dept
where
emp.deptno = dept.deptno
and emp.deptno = 72
and emp.salary > 5000
)
select inner1.*
from (
select 'abc' as title,
1 emp_order,
name, hiredate, deptname
from test1
UNION ALL
select 'xyz' as title,
2 emp_order,
name, hiredate, deptname
from test1
) inner1
I am trying to remove the WITH clause completely and create a VIEW instead.The only problem I have is the dynamic value in the WITH clause.
I tried this:
CREATE VIEW testview as
select emp.empno, emp.deptno, emp.name, emp.hiredate, dept.deptname
from emp, dept
where
emp.deptno = dept.deptno
and emp.deptno = 72
and emp.salary > 5000
Updated query is:
select inner1.*
from (
select 'abc' as title,
1 emp_order,
name, hiredate, deptname
from testview
UNION ALL
select 'xyz' as title,
2 emp_order,
name, hiredate, deptname
from testview
) inner1
In this case how can I pass bind values for salary and deptno cols in the view?
|
|
|
|
Re: Passing bind variables to a VIEW [message #606275 is a reply to message #606266] |
Tue, 21 January 2014 22:27 |
|
Kevin Meade
Messages: 2103 Registered: December 1999 Location: Connecticut USA
|
Senior Member |
|
|
CREATE VIEW testview as
select EMP.SALARY, emp.empno, EMP.DEPTNO, emp.name, emp.hiredate, dept.deptname
from emp, dept
where emp.deptno = dept.deptno
This view should suffice. To apply values to a view, you need to expose the needed columns.
select 'abc' as title, 1 emp_order, name, hiredate, deptname
from testview
where emp.deptno = 72
and emp.salary > 5000
UNION ALL
select 'xyz' as title, 2 emp_order, name, hiredate, deptname
from testview
where emp.deptno = 72
and emp.salary > 5000
or
select *
from (
select deptno,salary,'abc' as title, 1 emp_order, name, hiredate, deptname
from testview
UNION ALL
select deptno,salary,'xyz' as title, 2 emp_order, name, hiredate, deptname
from testview
)
where deptno = 72
and salary > 5000
Notice where the columns you apply values against, move around in the different query formulations.
Kevin
|
|
|
Goto Forum:
Current Time: Fri Apr 19 05:39:07 CDT 2024
|