oracle order by date子句以apex表格形式

时间:2018-01-02 06:46:53

标签: oracle plsql sql-order-by oracle-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项必须是SELECT列表表达式的编号

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

编辑:我无法选择

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的属性

2 个答案:

答案 0 :(得分:1)

试试这个:

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

答案 1 :(得分:1)

这些选项中的任何一个都有帮助吗?

首先,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;

或者,使用您的"原创"查询作为内联视图,然后"通常"订单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;