动态数据plsql枢轴

时间:2019-01-23 13:58:32

标签: sql oracle pivot

由于我可以动态添加FOR子句的参数,以免将它们一一放置,所以在通过选择停止时,会出现以下错误:ORA-00936: missing expression

表格

 LOAN NUMBER   DOCUMENT_TYPE                DOCUMENT_ID
 992452533663  Voters ID                    XPD0355636
 992452533663  Pan card                     CHXPS5522D
 992452533663  Drivers licence              DL-0420110141769

静态参数

select * from (
   select LOAN_NUMBER, DOCUMENT_TYPE, DOCUMENT_ID
   from my_table t
)
pivot 
(
   MIN(DOCUMENT_ID)
   for DOCUMENT_TYPE in ('Voters ID','Pan card','Drivers licence')
)

动态参数

select * from (
   select LOAN_NUMBER, 
          DOCUMENT_TYPE, 
          DOCUMENT_ID
     from my_table t
)
pivot 
(
   MIN(DOCUMENT_ID)
   for DOCUMENT_TYPE in ((
                            select LOAN_NUMBER, 
                                   DOCUMENT_TYPE, 
                                   DOCUMENT_ID
                              from my_table t
   ))
)

0 个答案:

没有答案