2014-02-28 62 views
-1

查詢視圖在Oracle與非列我創建了一個視圖如何鑑於

create or replace view view_emp as 
    select empno, ename, job 
    from emp; 

,我想查詢view_query有鑑於非列。

select empno, ename 
    from view_emp 
where deptno=10; 

當我試着去查詢這個樣子是給我一個錯誤說

ORA-00904: "TEST_EMP"."DEPTNO": invalid identifier 

我有這樣的例子的要求。任何人都可以爲我的要求提供解決方案。


其實我在ERP解決方案庫存模塊上工作。

我有一個要求,要求在日期範圍內找到單位明智的,prodct明智的股票期初餘額和期末餘額。

我要像

create view stk_bal 
    as 
    select unit_code,prod_code, sum(opening_bal) opening_bal, sum(closing_bal) closing_bal 
    from 
    (
    select unit_code, prod_code, ob_qty opeing_bal, 0 closing_bal 
    from (table 1) join (table 1.1) 
    where crtd_date between '02-feb-2013' and '02-mar-2013' 
    union all 
    select unit_code, prod_code, 0 , grn_qty 
    from (table 2) join (table 2.1) 
    where grn_date between '02-feb-2013' and '02-mar-2013' 
    union all 
    select unit_code, prod_code, 0, stk_transfer_in_qty 
    from (table 3) join (table 3.1) 
    where stk_trnin_date between '02-feb-2013' and '02-mar-2013' 
    ) 
    group by unit_code, prod_code; 

的景色,我創建的視圖通過使聯盟所有3組在那裏我有硬編碼的日期 表,但我想查詢它有沒有日期的日期範圍內的視圖列中。

現在我想查詢日期範圍中的視圖stk_bal。

+2

但是當它在視圖的定義中不存在時,它應該從哪裏得到DeptNo?一個視圖不是它的定義PLUS的表格。這只是它的定義。您沒有在「從emp選擇empno,ename,job 」中選擇「您爲什麼需要在此處查看? – tgkprog

+0

回答你的問題 - 你不能。 – tgkprog

+1

您應該使用google.com來閱讀視圖並查看一些示例。並在這個問題上添加你真正的目標是否仍然不明確。 – tgkprog

回答

0

您需要在您的視圖定義添加deptno

create or replace view view_emp as 
    select empno, ename, job 
     ,DEPTNO 
    from emp; 

但當然,真正的問題是:究竟是你的要求,你爲什麼需要一個視圖。