create or replace view mcerp_v_waitstockin asselect nvl(flngsaleorderid,1) flngsaleorderid,fchrsaleorderno,fdtmdate,flngaudit,flngcustomerid, fchrcustomername, fchrphone,flngpositionid, fchrpositioncode,fchrpositionname, fchrpositionfullname,flngdepartmentid, fchrdepartmentfullname,flngemployeeid,fchremployeecode, fchremployeename,flotquantity,fchrnote,flngreceipttypeid,fchrreceipttypefrom(select mp.flngpurchaseorderid flngsaleorderid,mp.fchrpurchaseorderno fchrsaleorderno,mp.fdtmdate,mp.flngaudit,-----待入庫資料mp.flngsupplyid flngcustomerid, c.strcustomername fchrcustomername,mp.fchrphone,mp.flngpositionid,p.strpositioncode fchrpositioncode, p.strpositionname fchrpositionname,p.strfullname fchrpositionfullname,mp.flngdepartmentid, d.strfullname fchrdepartmentfullname,mp.flngemployeeid, e.stremployeecode fchremployeecode, e.stremployeename fchremployeename,mp.flotquantity,mp.fchrnote,mp.flngreceipttypeid,case when flngreceipttypeid=1 then '採購入庫' when flngreceipttypeid=2 then '採購退貨' end fchrreceipttypefrom mcerp_purchaseorder mpinner join department d on mp.flngdepartmentid = d.lngdepartmentidinner join employee e on mp.flngemployeeid = e.lngemployeeidinner join position p on mp.flngpositionid=p.lngpositionidleft join supplypreapp s on mp.flngsupplyid=s.lngsupplypreappidleft join customerex c on mp.flngsupplyid = c.lngcustomeridwhere mp.flngaudit=1 and (mp.flngstock=0 or mp.flngstock=1)and mp.fbitclose=0union all-------------調撥入庫select a.flngallocateid flngsaleorderid,a.fchrallocateno fchrsaleorderno,a.fdtmdate,a.flngaudit,----申請單ID,申請單號,單據日期,審核狀態,0 flngcustomerid, '' fchrcustomername,'' fchrphone,------客戶id,客戶名,客戶電話a.flnginpositionid flngpositionid,pp.strpositioncode fchrpositioncode,pp.strpositionname fchrpositionname,pp.strfullname fchrpositionfullname,----倉庫0 flngdepartmentid, '' fchrdepartmentfullname,-----部門a.flngemployeeid,e.stremployeecode fchremployeecode,e.stremployeename fchremployeename,-----業務員a.flotquantity,a.fchrnote,21 flngreceipttypeid,'調撥單' fchrreceipttype ----數量,備忘,單據類型ID,單據類型strfrom mcerp_allocate ainner join position pp on pp.lngpositionid=a.flnginpositionidleft join employee e on e.lngemployeeid=a.flngemployeeidwhere a.flnginid<=0 and a.flngoutid>0union all------其他入庫,其他入庫退select a.flngotherinoutid flngsaleorderid,a. fchrotherinoutno,a.fdtmdate,a.flngaudit,a.flngcustomerid, c.strcustomername fchrcustomername,c.strmovephone fchrphone,a.flngpositionid,pp.strpositioncode fchrpositioncode,pp.strpositionname fchrpositionname,pp.strfullname fchrpositionfullname,a.flngdepartmentid, d.strfullname fchrdepartmentfullname,a.flngemployeeid,e.stremployeecode fchremployeecode,e.stremployeename fchremployeename,a.flotquantity,a.fchrnote,flngreceipttypeid,case when flngreceipttypeid=31 then '其他入庫申請' when flngreceipttypeid=32 then '其他入庫退回' end fchrreceipttypefrom mcerp_otherinout ainner join department d on a.flngdepartmentid = d.lngdepartmentidinner join position pp on pp.lngpositionid=a.flngpositionidleft join employee e on e.lngemployeeid=a.flngemployeeidleft join customerex c on a.flngcustomerid = c.lngcustomeridwhere a.flngstock<>2 and a.flngauditid>0 and (a.flngreceipttypeid=31 or a.flngreceipttypeid=32)
以上為Oracle中的視圖,添加幾次該視圖總是添加不進去
點完成後視圖並沒有添加進去
原因是視圖sql中有 union all 關鍵字 EF無法推斷出哪個是主鍵。
解決:
先將 union all下面的SQL刪除掉,只留一個表的查詢。然後更新視圖。
更新視圖後再在把union all加進SQL然後執行SQL語句。這樣就可以再程式中直接查詢調用這個視圖了。