ORA-00936,Java和SQL

时间:2015-07-28 13:23:26

标签: java sql oracle

我知道我有一个缺失的表情,但我不知道它在哪里?

这是我发送给解析器的字符串:

#macro(intervals $startDate $endDate)   SELECT #bind($startDate 'TIMESTAMP') - 1 + LEVEL interv,         1+EXTRACT(DAY FROM #bind($endDate 'TIMESTAMP')-#bind($startDate 'TIMESTAMP')) days_in_period   FROM dual   CONNECT BY LEVEL <= 1+EXTRACT(DAY FROM #bind($endDate 'TIMESTAMP')- #bind($startDate 'TIMESTAMP'))#end
#macro(tagSeries $dso $includeSetInfo)     SELECT DISTINCT t.tag_group    #if($includeSetInfo) , t.set_id tag_set_id, t.name tag_set_name #end           , tsi.tag_id       FROM TRANSPONDER_SET t, TRANSPONDER_SET_ID TSI     WHERE t.set_id IN (     #if($TAG_SET_ID) #bind($TAG_SET_ID 'VARCHAR') #else        #foreach($transponderSet in $dso.getTransponderSet() )         #if($velocityCount > 1) , #end         #bind($transponderSet.getSetId() 'VARCHAR')       #end     #end     )     AND t.set_id = tsi.set_id#end
#set( $data_opt = $data_selection) 
WITH 
     intervals AS (#intervals($PERIOD_START_DATE $PERIOD_END_DATE)),
     tags AS (#tagSeries($data_opt false)),
     ag_regions AS (    SELECT /* materialize */
                               node_id, CONNECT_BY_ROOT ag2.name region_name
                          FROM area_group ag2
                          START WITH ag2.parent_node_id = 1
                          CONNECT BY NOCYCLE PRIOR ag2.node_id = ag2.parent_node_id),
     stations AS (SELECT distinct ag.abbreviation,
                         ag.node_id,
                         rp.station_key,
                         ag.sorting
                         , CASE s.equipment_type_key WHEN 2 THEN s.station_name ELSE NULL END pk_number
                         ,(SELECT region_name
                             FROM ag_regions
                            WHERE node_id = ag.node_id) region
                    FROM reg_point_view rp, area_group ag, station s
                   WHERE rp.area_group_node_id = ag.node_id  
          #if($station_region_options.isStations())
              AND rp.station_key IN (#bind($station_region_options.getEntries() 'NUMERIC'))
          #elseif($station_region_options.isPartitionNodes())
              AND ag.node_id IN (#bind($station_region_options.getEntries() 'NUMERIC'))
          #elseif($station_region_options.isTreeNodes())
              AND ag.node_id IN (SELECT node_id
                                   FROM area_group 
                                 START WITH NODE_ID IN (#bind($station_region_options.getEntries() 'NUMERIC')) 
                                 CONNECT BY PRIOR NODE_ID = PARENT_NODE_ID 
                                    AND NODE_ID <> PARENT_NODE_ID)
          #end 
              AND (
                   rp.ant_ikraft_dato <= #bind($PERIOD_END_DATE 'TIMESTAMP') -- period end date 
                   and (rp.ant_udlobs_dato is null
                        or rp.ant_udlobs_dato >= #bind($PERIOD_START_DATE 'TIMESTAMP') -- period start date
                       )
                  ) 
              AND rp.station_key = s.station_key 
    ),
    pre_aggregation AS  
    (SELECT TRUNC(vd.reg_time) day, s.abbreviation, s.node_id, s.pk_number, s.region, count(*) regs, s.sorting
       FROM stations s, validated_data vd, tags t
      WHERE vd.station_key = s.station_key
        AND vd.tag_id = t.tag_id
        AND vd.tag_group = t.tag_group
        AND vd.reg_time BETWEEN #bind($PERIOD_START_DATE 'TIMESTAMP') AND #bind($PERIOD_END_DATE 'TIMESTAMP')
   GROUP BY TRUNC(vd.reg_time), s.abbreviation, s.node_id,s.pk_number, s.region, s.sorting)
    SELECT abbreviation, node_id, pk_number, region, 100*sum(days_read)/(select count(*) from intervals) utilization from (
      SELECT abbreviation, node_id, pk_number, region, sorting, sum(decode(regs,0,0,1)) days_read FROM pre_aggregation
       GROUP BY abbreviation, node_id, pk_number, region, sorting, regs
      UNION ALL SELECT DISTINCT abbreviation, node_id, pk_number, region, sorting,0 days_read FROM stations)
    GROUP BY abbreviation, pk_number, region, node_id, sorting
    -- Just to test
    ORDER BY utilization desc, sorting
你能找到吗?我的cmd写下以下内容

    ORDER BY utilization desc sorting]; nested exception is java.sql.SQLSyntaxErrorException: ORA-00936: missing expression

from my cmd I get the following: 

Class: class org.springframework.jdbc.BadSqlGrammarException
        Message: StatementCallback; bad SQL grammar [WITH 
     intervals AS (   SELECT to_timestamp('01-01-2013 00:00:00','dd-mm-yyyy hh24:mi:ss') - 1 + LEVEL interv,         1+EXTRACT(DAY FROM to_timestamp('30-01-2013 23:59:59','dd-mm-yyyy hh24:mi:ss')-to_timestamp('01-01-2013 00:00:00','dd-mm-yyyy hh24:mi:ss')) days_in_period   FROM dual   CONNECT BY LEVEL <= 1+EXTRACT(DAY FROM to_timestamp('30-01-2013 23:59:59','dd-mm-yyyy hh24:mi:ss')- to_timestamp('01-01-2013 00:00:00','dd-mm-yyyy hh24:mi:ss'))),
     tags AS (     SELECT DISTINCT t.tag_group               , tsi.tag_id       FROM TRANSPONDER_SET t, TRANSPONDER_SET_ID TSI     WHERE t.set_id IN (                       )     AND t.set_id = tsi.set_id),
     ag_regions AS (    SELECT /* materialize */
                               node_id, CONNECT_BY_ROOT ag2.name region_name
                          FROM area_group ag2
                          START WITH ag2.parent_node_id = 1
                          CONNECT BY NOCYCLE PRIOR ag2.node_id = ag2.parent_node_id),
     stations AS (SELECT distinct ag.abbreviation,
                         ag.node_id,
                         rp.station_key,
                         ag.sorting
                         , CASE s.equipment_type_key WHEN 2 THEN s.station_name ELSE NULL END pk_number
                         ,(SELECT region_name
                             FROM ag_regions
                            WHERE node_id = ag.node_id) region
                    FROM reg_point_view rp, area_group ag, station s
                   WHERE rp.area_group_node_id = ag.node_id  
                        AND rp.station_key IN (1549)
                        AND (
                   rp.ant_ikraft_dato <= to_timestamp('30-01-2013 23:59:59','dd-mm-yyyy hh24:mi:ss') -- period end date 
                   and (rp.ant_udlobs_dato is null
                        or rp.ant_udlobs_dato >= to_timestamp('01-01-2013 00:00:00','dd-mm-yyyy hh24:mi:ss') -- period start date
                       )
                  ) 
              AND rp.station_key = s.station_key 
    ),
    pre_aggregation AS  
    (SELECT TRUNC(vd.reg_time) day, s.abbreviation, s.node_id, s.pk_number, s.region, count(*) regs, s.sorting
       FROM stations s, validated_data vd, tags t
      WHERE vd.station_key = s.station_key
        AND vd.tag_id = t.tag_id
        AND vd.tag_group = t.tag_group
        AND vd.reg_time BETWEEN to_timestamp('01-01-2013 00:00:00','dd-mm-yyyy hh24:mi:ss') AND to_timestamp('30-01-2013 23:59:59','dd-mm-yyyy hh24:mi:ss')   GROUP BY TRUNC(vd.reg_time), s.abbreviation, s.node_id,s.pk_number, s.region, s.sorting)
    SELECT abbreviation, node_id, pk_number, region, 100*sum(days_read)/(select count(*) from intervals) utilization from (
      SELECT abbreviation, node_id, pk_number, region, sorting, sum(decode(regs,0,0,1)) days_read FROM pre_aggregation
       GROUP BY abbreviation, node_id, pk_number, region, sorting, regs
      UNION ALL SELECT DISTINCT abbreviation, node_id, pk_number, region, sorting,0 days_read FROM stations)
    GROUP BY abbreviation, pk_number, region, node_id, sorting
    --Dette er lige lidt test kode!
    ORDER BY utilization desc sorting]; nested exception is java.sql.SQLSyntaxErrorException: ORA-00936: missing expression

我看过:java.sql.SQLException: ORA-00936: missing expression&amp; ORA-00936: missing expression oracle

但是我似乎无法弄清楚是否存在逗号或者拼写错误。

1 个答案:

答案 0 :(得分:1)

这部分:

SELECT DISTINCT t.tag_group, tsi.tag_id
FROM TRANSPONDER_SET t, TRANSPONDER_SET_ID TSI
WHERE t.set_id IN (   ) AND t.set_id = tsi.set_id

您没有指定t.set_id的值,IN()无效。