为什么我在执行此脚本时遇到此错误(plsql oracle)

时间:2017-08-17 17:35:13

标签: sql oracle

我正在编写plsql脚本,当我使用 ROW_NUMBER()OVER(PARTITION BY ... )时,我在部件中执行时出错! 这个我的代码行给了我这个错误:不一致的数据类型:预期 - 获得CLOB

这是我的代码:

CREATE OR REPLACE VIEW "VW_APP_PU_LOCATION_CLUSTER" ("ID", "BATCH_ID", "PRODUCTION_SYSTEM_ID", "CODE", "URGENCY", "CURRENT_STATE", "VALUE", "ELEMENT_ID","VIEW_ID") AS 
  SELECT app.id AS id
    ,      app.batch_state AS batch_id
    ,      app.production_system_id AS production_system_id
    ,      atp.code AS code
    ,      app.urgency_code AS urgency
    ,      app.current_state AS current_state
    ,      dbms_lob.substr(el.value, 4000, 1) AS value
    ,      el.element_id AS element_id
    , ROW_NUMBER() OVER (PARTITION BY LOWER(el.value) ORDER BY loc.code) AS view_id    
    FROM   application app
    CROSS  JOIN application_type atp
    CROSS  JOIN location loc
    CROSS  JOIN application_order ord
    LEFT JOIN data_element el ON (app.id = el.application_id AND el.element_id = isexistsparam('Pu Generation','SORTING_DATA_ELEMENT'))
    WHERE  app.application_type_id = atp.id
    AND    app.location_id = loc.id
    AND    app.application_order_id = ord.id
    AND app.current_state in 
    (
      select distinct sd.state 
      from process_state_definition psd, 
      state_definition sd, 
      application_type appType, 
      application appli,
      process_definition pd
      Where 
      ((appType.code is null)or (appType.id = appli.application_type_id AND sd.id = psd.state_definition_id)
        AND psd.application_type_id = appType.id 
        AND psd.process_definition_id = pd.id 
        AND psd.state_type='START'
        AND pd.name = 'Pu Generation')
   )    
    ORDER  BY loc.code asc,
CASE WHEN isexistsparam('Pu Generation', 'SORTING_DATA_ELEMENT') != -1 
THEN dbms_lob.substr(el.value, 4000, 1) ELSE NULL
END
    ,      ord.date_ordered asc
    ,      app.application_number asc;

enter image description here

有人可以向我解释一下ROW_NUMBER()函数有什么问题谢谢

1 个答案:

答案 0 :(得分:1)

restriction

  

您不能在查询的ORDER BY子句中指定LOB列,或   在查询的GROUP BY子句中或在聚合函数中。

如果值小于4000个字符,您可以将CLOB转换为CHAR。

*我的解释或我的理解: ROW_NUMBER是分析函数。分析函数根据一组行计算聚合值。我们有PARTITION BY基于LOB列对数据进行分组。 所以,回到限制:

  

您无法在查询的GROUP BY子句中指定LOB列...

**抱歉我的英文。