且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Oracle SQL Developer:如何使用PIVOT函数将行转置为列

更新时间:2023-11-18 21:47:16

在声明之后,您的语句中使用了分号:

You have a stray semi-colon in your statement, after:

    WHERE partyId = 100; 

删除该链接即可

SELECT * FROM 
  ( 
    SELECT partyId, contacttext, contacttypecd 
    FROM CONTACT 
    WHERE partyId = 100
  ) 
  PIVOT ( 
    MAX(contacttext) 
  FOR contacttypecd in (1 Phone, 2 Fax, 3 Mobile, 4 Email));

   PARTYID PHONE        FAX          MOBILE       EMAIL      
---------- ------------ ------------ ------------ ------------
       100 0354441010   0355551010   0428105789   abc@home.com

它被视为多个语句;第一个是不完整的,因为它缺少右括号(因此得到ORA-00907),第二个从该括号开始并得到了您报告的错误,然后每行都得到相同的错误.您似乎只是在查看上一次报告的错误-从第一个错误开始,将其清除,然后在下一个仍然存在的情况下移至下一个错误通常会更有帮助.

It's being seen as multiple statements; the first is incomplete because it's missing a closing parenthesis (so gets ORA-00907), the second starts with that parenthesis and gets the error you reported, and then each subsequent line gets the same error. You only seem to be looking at the last reported error - it's usually much more helpful to start with the first error, clear that, and then move onto the next if it still exists.