Oracle sqlplus查询

时间:2017-12-31 09:31:32

标签: oracle sqlplus

我收到“无效号码”

任何人都可以指导我在这里做错了吗?

select TO_CHAR(a.START_TIME,'YY-MON-DD HH24') as START_TIME, 
        count(*) AS NbOperations,
        SUM(CASE WHEN OPERATION_RESULT=0 THEN 1 ELSE 0 END) AS Success,
        SUM(CASE WHEN OPERATION_RESULT=200 THEN 1 ELSE 0 END) AS Cancel,
        SUM(CASE WHEN OPERATION_RESULT=203 THEN 1 ELSE 0 END) AS AppletInternalError,
        SUM(CASE WHEN OPERATION_RESULT=406 THEN 1 ELSE 0 END) AS TimeoutWaitForCard,
        SUM(CASE WHEN OPERATION_RESULT=413 THEN 1 ELSE 0 END) AS BillingError,
        SUM(CASE WHEN OPERATION_RESULT=1000 THEN 1 ELSE 0 END) AS ABANDONNED,
        SUM(CASE WHEN OPERATION_RESULT=1004 THEN 1 ELSE 0 END) AS ABANDON_FOR_NEW_OPERATION,
        SUM(CASE WHEN OPERATION_RESULT NOT IN (0,200,203,406,413,1000,1004) THEN 1 ELSE 0 END) AS NbOthers
from MyTable1 a, 
      MyTable2 b 
where OPERATION_TYPE in (2,3,4,5) 
and a.OPERATION_TYPE=b.OPERATION_ID 
and a.START_TIME >= to_timestamp('&1', 'YYYY-MM') 
and a.START_TIME < to_timestamp('&2', 'YYYY-MM') + interval '1' month
group by TO_CHAR(a.START_TIME,'YY-MON-DD HH24')
order by TO_CHAR(START_TIME,'YY-MON-DD HH24');

2 个答案:

答案 0 :(得分:0)

检查输入格式&amp; 1和&amp; 2可能与日期掩码不匹配:&#39; YYYY-MM&#39;。另一个可能的原因是表的内容:OPERATION_TYPE和OPERATION_RESULT都是数字数据类型?可能存在与数字不同的东西。

答案 1 :(得分:0)

我可以使用以下SQL代码解决问题:

select TO_CHAR(a.START_TIME,'YY-MON-DD HH24') as Hourly, count(*) AS NbOperations,
SUM(CASE WHEN OPERATION_RESULT=0 THEN 1 ELSE 0 END) AS Success,
SUM(CASE WHEN OPERATION_RESULT=200 THEN 1 ELSE 0 END) AS Cancel,
SUM(CASE WHEN OPERATION_RESULT=203 THEN 1 ELSE 0 END) AS AppletInternalError,
SUM(CASE WHEN OPERATION_RESULT=406 THEN 1 ELSE 0 END) AS TimeoutWaitForCard,
SUM(CASE WHEN OPERATION_RESULT=413 THEN 1 ELSE 0 END) AS BillingError,
SUM(CASE WHEN OPERATION_RESULT=1000 THEN 1 ELSE 0 END) AS ABANDONNED,
SUM(CASE WHEN OPERATION_RESULT=1004 THEN 1 ELSE 0 END) AS ABANDON_FOR_NEW_OPERATION,
SUM(CASE WHEN OPERATION_RESULT NOT IN (0,200,203,406,413,1000,1004) THEN 1 ELSE 0 END) AS NbOthers
from gsg3_invocation_history a, GSG3_OPERATION_TYPE b where START_TIME >= to_timestamp('&1', 'YYYY-MM')
and START_TIME < to_timestamp('&2', 'YYYY-MM') + interval '1' month and OPERATION_TYPE in (2,3,4,5) and a.OPERATION_TYPE=b.OPERATION_ID
group by TO_CHAR(a.START_TIME,'YY-MON-DD HH24') order by TO_CHAR(START_TIME,'YY-MON-DD HH24');