我怎样才能使 pl/sql 动态化?
How can i make dynamic pl/sql?
我想在参数值中使用类型变量来动态 pl/sql。
参数值
>
类型 = {'name + place', 'resno', 'hpno', 'telno'};
例如
如果我得到参数值('resno','hpno')
需要两个组合查询(2 union all)
所以,这意味着查询次数取决于参数值。
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 通常不好),为什么不基于该语句创建一个 view?
create or replace view v_my_view as
select * from (
--repeatation
select * from
(select a.custnm
, 'name + place' as vtype
<snip>
完成后,您可以在任何地方使用它(包括 PL/SQL)。
我想在参数值中使用类型变量来动态 pl/sql。
参数值 > 类型 = {'name + place', 'resno', 'hpno', 'telno'};
例如 如果我得到参数值('resno','hpno') 需要两个组合查询(2 union all) 所以,这意味着查询次数取决于参数值。
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 通常不好),为什么不基于该语句创建一个 view?
create or replace view v_my_view as
select * from (
--repeatation
select * from
(select a.custnm
, 'name + place' as vtype
<snip>
完成后,您可以在任何地方使用它(包括 PL/SQL)。