oracle order by date 子句以顶点表格形式

oracle order by date clause in apex tabular form

我有一个带有以下区域查询的 oracle apex 表格形式

select APEX_ITEM.DATE_POPUP2(1,sysdate,'DD-MM-YYYY') DIV_DATE, 
       APEX_ITEM.TEXT(2,null ,10,15,'style="width:100px;text-align:right"') CREDIT 
   from dual 
                             union 
select APEX_ITEM.DATE_POPUP2(1,DIV_DATE,'DD-MM-YYYY') DIV_DATE,
       APEX_ITEM.TEXT(2,CREDIT,10,15,'style="width:100px;text-align:right"') CREDIT
   from DIVIDENT_REG
   where code=:MCODE and memno=:MEMNO and brcode=:BRCODE
   order by  DIV_DATE desc

我希望结果按列 DIV_DATE 的降序排列。但是上面的 order by 子句不起作用。所以我使用了代码

order by to_date(DIV_DATE) desc

但是显示错误

ORA-01785: ORDER BY item must be the number of a SELECT-list expression

有没有人有解决这个问题的想法?

编辑:我无法选择

select div_date,credit from(    
select APEX_ITEM.DATE_POPUP2(1,sysdate,'DD-MM-YYYY') DIV_DATE, 
       APEX_ITEM.TEXT(2,null ,10,15,'style="width:100px;text-align:right"') CREDIT 
   from dual 
                             union 
select APEX_ITEM.DATE_POPUP2(1,DIV_DATE,'DD-MM-YYYY') DIV_DATE,
       APEX_ITEM.TEXT(2,CREDIT,10,15,'style="width:100px;text-align:right"') CREDIT
   from DIVIDENT_REG
   where code=:MCODE and memno=:MEMNO and brcode=:BRCODE
   order by  DIV_DATE desc    )

因为它会删除我的 apex_item

的属性

试试这个:

SELECT   TB.*
    FROM (SELECT APEX_ITEM.DATE_POPUP2 (1,
                                        SYSDATE,
                                        'DD-MM-YYYY') DIV_DATE,
                 APEX_ITEM.TEXT (2,
                                 NULL,
                                 10,
                                 15,
                                 'style="width:100px;text-align:right"')
                                                                       CREDIT
            FROM DUAL
          UNION
          SELECT APEX_ITEM.DATE_POPUP2 (1,
                                        DIV_DATE,
                                        'DD-MM-YYYY') DIV_DATE,
                 APEX_ITEM.TEXT (2,
                                 CREDIT,
                                 10,
                                 15,
                                 'style="width:100px;text-align:right"')
                                                                       CREDIT
            FROM DIVIDENT_REG
           WHERE CODE = :MCODE
                 AND MEMNO = :MEMNO
                 AND BRCODE = :BRCODE) TB
ORDER BY TB.DIV_DATE DESC

这些选项有帮助吗?

首先,ORDER BY 1 DESC,其中“1”表示查询返回的第一列:

select APEX_ITEM.DATE_POPUP2(1,sysdate,'DD-MM-YYYY') DIV_DATE, 
       APEX_ITEM.TEXT(2,null ,10,15,'style="width:100px;text-align:right"') CREDIT 
from dual 
union 
select APEX_ITEM.DATE_POPUP2(1,DIV_DATE,'DD-MM-YYYY') DIV_DATE,
       APEX_ITEM.TEXT(2,CREDIT,10,15,'style="width:100px;text-align:right"') CREDIT
from DIVIDENT_REG
where code=:MCODE and memno=:MEMNO and brcode=:BRCODE
order by 1 desc;

或者,使用您的 "original" 查询作为内联视图,然后 "normally" 按 DIV_DATE:

排序
select div_date, credit
from (select APEX_ITEM.DATE_POPUP2(1,sysdate,'DD-MM-YYYY') DIV_DATE, 
             APEX_ITEM.TEXT(2,null ,10,15,'style="width:100px;text-align:right"') CREDIT 
      from dual 
      union 
      select APEX_ITEM.DATE_POPUP2(1,DIV_DATE,'DD-MM-YYYY') DIV_DATE,
             APEX_ITEM.TEXT(2,CREDIT,10,15,'style="width:100px;text-align:right"') CREDIT
      from DIVIDENT_REG
      where code=:MCODE and memno=:MEMNO and brcode=:BRCODE
     )
order by div_date desc;