collect语句中order by的语法错误

yi0zb3m4  于 2021-07-26  发布在  Java
关注(0)|答案(1)|浏览(468)

为什么我会在 order by 在本规范中:
oracle sql express和https://www.eversql.com/sql-syntax-check-validator/

select cast(collect(
   case
      when (1 = 1) then 
         'aaa'
      else 'bbb'
   end
order by mt.my_col) as t_varchar2_tab)
from my_table mt;
pu82cl6c

pu82cl6c1#

再加一个就行了 cast :

select cast(collect(
   cast(
     case
        when (1 = 1) then 
           'aaa'
        else 'bbb'
     end
     as varchar2(100)
    )
order by mt.my_col) as t_varchar2_tab)
from my_table mt;

完整示例:

with my_table as (select to_char(level,'000') my_col from dual connect by level<=10)
select cast(collect(
   cast(
     case
        when (1 = 1) then 
           'aaa'
        else 'bbb'
     end
     as varchar2(100)
    )
order by mt.my_col) as t_varchar2_tab)
 as res
from my_table mt;

RES
-------------------------------------------------------------------------------------
T_VARCHAR2_TAB('aaa', 'aaa', 'aaa', 'aaa', 'aaa', 'aaa', 'aaa', 'aaa', 'aaa', 'aaa')

另外,不要将eversql用于oraclesql。它只支持mysql

相关问题