簡體   English   中英

如何制作動態pl / sql?

[英]How can i make dynamic pl/sql?

我想在參數值中使用類型變量來創建動態pl / sql。

參數值>類型= {'名稱+位置','resno','hpno','telno'};

例如,如果我得到了參數值('resno','hpno'),則需要兩個組合查詢(全部2個並集),因此,這意味着查詢數量取決於參數值。

select * from (
--repeatation
select * from
(select a.custnm
     , 'name + place' as vtype
     , a.custnm || '-' || c.pjtcd || '-' || c.dong || '-' || c.ho as con
     , count(a.custid) as nodup 
from   custtable a
     , thng c 
where a.custid = c.custid(+)
group by a.custnm, c.pjtcd, c.dong, c.ho
having count(a.custid) > 1) x
--/repeatation
union all
--repeatation
select * from
(select a.custnm
     , 'resno' as vtype
     , a.resno as condup
     , count(a.custid) as nodup 
from   custtable a
group by a.custnm, a.resno
having count(a.custid) > 1) x2
--repeatation
union all
--repeatation
select * from
(select a.custnm
     , 'hpno' as vtype
     , a.hpno as condup
     , count(a.custid) as nodup 
from   custtable a
group by a.custnm, a.hpno
having count(a.custid) > 1) x3
--repeatation
union all
--repeatation
select * from
(select a.custnm
     , 'telno' as vtype
     , a.telno as condup
     , count(a.custid) as nodup 
from   custtable a
group by a.custnm, a.telno
having count(a.custid) > 1) x4
--repeatation
) 
order by decode(vtype, 'name +`enter code here` place', 1 ,'resno', 2 ,'hpno', 3,  'telno', 4), nodup desc

請讓我知道如何用參數值制作plsql

這是一個SELECT語句。 現在的編寫方式是SQL,而不是PL / SQL,我的建議是這樣 與其編寫可怕的PL / SQL(動態SQL通常不是很好),不如不基於該語句創建視圖

create or replace view v_my_view as
select * from (
--repeatation
select * from
(select a.custnm
     , 'name + place' as vtype
<snip>

完成后,可在任何需要的地方使用它(包括PL / SQL)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM