我在尝试在Oracle中创建存储过程时遇到此错误, “ERROR第96行,第9栏,结尾第96行,结尾第13行,发现'PIVOT',期待:)......”
当我从存储过程模板中运行我的查询时没关系,我的过程不接受任何参数。
create table my_table (LOAN_NUMBER varchar2(20), DOCUMENT_TYPE varchar2(20),
DOCUMENT_ID varchar(20));
insert into my_table(LOAN_NUMBER,DOCUMENT_TYPE,DOCUMENT_ID) values
('992452533663','Voters ID','XPD0355636');
insert into my_table(LOAN_NUMBER,DOCUMENT_TYPE,DOCUMENT_ID) values
('992452533663','Pan card','CHXPS5522D');
insert into my_table(LOAN_NUMBER,DOCUMENT_TYPE,DOCUMENT_ID) values
('992452533663','Drivers licence','DL-0420110141769');
insert into my_table(LOAN_NUMBER,DOCUMENT_TYPE,DOCUMENT_ID) values
('692452533663','Voters ID','yPD0355636');
insert into my_table(LOAN_NUMBER,DOCUMENT_TYPE,DOCUMENT_ID) values
('692452533663','Pan card','dHXPS5522D');
insert into my_table(LOAN_NUMBER,DOCUMENT_TYPE,DOCUMENT_ID) values
('692452533663','Drivers licence','DLx-0420110141769');
CREATE OR REPLACE PROCEDURE my_procedure(pData OUT SYS_REFCURSOR)
IS
BEGIN
OPEN pData FOR
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')
);
end;
任何人都可以解释如何直接在存储过程中使用数据透视关键字吗? 如果不可能,这种情况背后的逻辑是什么?