如何在oracle上运行groupby,在其表中有一个Long作为数据类型的表 - 非法使用LONG数据类型

时间:2018-04-25 16:01:28

标签: oracle constraints listagg

SELECT ac.owner, ac.table_name, LISTAGG(column_name ,',' ) WITHIN GROUP(ORDER BY ac.constraint_name) AS "ABC" , ac.constraint_name, ac.constraint_type, ac.search_condition
        (SELECT ac2.table_name FROM all_cons_columns ac2 WHERE AC2.CONSTRAINT_NAME = AC.R_CONSTRAINT_NAME) fK_to_table, 
        (SELECT ac2.column_name FROM all_cons_columns ac2 WHERE AC2.CONSTRAINT_NAME = AC.R_CONSTRAINT_NAME) fK_to_column 
        FROM all_cons_columns acc, all_constraints ac WHERE     acc.constraint_name = ac.constraint_name AND acc.table_name = ac.table_name 
        AND CONSTRAINT_TYPE IN ('P', 'R', 'C', 'U') group by ac.owner, ac.table_name, ac.constraint_name, ac.constraint_type, ac.search_condition;

返回 -

ORA-00997: illegal use of LONG datatype
00997. 00000 -  "illegal use of LONG datatype"
*Cause:    
*Action:

我尝试过没有。有什么建议吗?

注 - 1.更改表数据类型不是一个选项。        2. ac.search_condition似乎是Long类型        3.当然需要查询中的ac.search_condition

1 个答案:

答案 0 :(得分:1)

有一个search_condition_vc列,请尝试使用它,它是一个varchar2

您的任何搜索条件> 4000个字符,如果这样可能会导致问题,但可能你可以弄清楚

一旦我这样做,它就会因为缺少一个组而给出错误,所以这个新的sql在组中有r_constraint_name

SELECT ac.owner, ac.table_name, LISTAGG(column_name ,',' ) WITHIN GROUP(ORDER BY ac.constraint_name) AS "ABC" , ac.constraint_name, ac.constraint_type, ac.search_condition_vc,
        (SELECT ac2.table_name FROM all_cons_columns ac2 WHERE AC2.CONSTRAINT_NAME = AC.R_CONSTRAINT_NAME) fK_to_table, 
        (SELECT ac2.column_name FROM all_cons_columns ac2 WHERE AC2.CONSTRAINT_NAME = AC.R_CONSTRAINT_NAME) fK_to_column 
        FROM all_cons_columns acc, all_constraints ac WHERE     acc.constraint_name = ac.constraint_name AND acc.table_name = ac.table_name 
        AND CONSTRAINT_TYPE IN ('P', 'R', 'C', 'U') group by ac.owner, ac.table_name, ac.constraint_name, ac.constraint_type, ac.search_condition_vc, ac.r_constraint_name;