我尝试使用TO_LOB()函数来解决长类型的问题。但是出了问题,我得到了这个错误:
ORA-00932: inconsistent datatypes: expected - got LONG
00932. 00000 - "inconsistent datatypes: expected %s got %s"
有一个SQL查询,我想用它来选择一些关于数据库中列的信息。
SELECT
cols.table_name,
cols.column_name,
TO_LOB(cols.data_default) AS data_by_default,
MAX(CASE WHEN cols.nullable = 'N' OR cons.constraint_type = 'P' THEN 'Y' ELSE 'N' END) AS is_required,
MAX(CASE WHEN cons.constraint_type = 'P' THEN 'Y' ELSE 'N' END) AS is_primary_key,
MAX(CASE WHEN cons.constraint_type = 'R' THEN 'Y' ELSE 'N' END) AS is_foreign_key,
comm.comments
FROM user_tab_columns cols
LEFT JOIN user_cons_columns cons_cols
ON cols.table_name = cons_cols.table_name
AND cols.column_name = cons_cols.column_name
LEFT JOIN user_constraints cons
ON cons_cols.constraint_name = cons.constraint_name
LEFT JOIN user_col_comments comm
ON cols.table_name = comm.table_name
AND cols.column_name = comm.column_name
GROUP BY cols.table_name, cols.column_name, cols.data_default, cols.data_length, cols.nullable, comm.comments
ORDER BY cols.table_name;
3条答案
按热度按时间31moq8wy1#
As described in the documentation,
long
column cannot be part of any expression in a standaloneselect
statement.One of possible ways to overcome this restriction in SQL statement is to wrap an access to such table with
dbms_xmlgen
functions, which will serializelong
column values into XML that may be consumed byXMLTable
function.Setup:
Any expression with
long
fails:But it may be serialized in XML:
fiddle
nwwlzxa72#
你不能像这样处理LONG......它们不会以这种方式转换成CLOB。你必须在PL/SQL中给它们赋值。如果值的长度小于32 K,这真的很容易:
我已经为我们的数据库编写了一组丰富的字典视图,其中一项功能就是消除LONG。下面是我的dba_tab_columns扩展:
您明白了,但是,如果您必须使用dba_views.text或dba_triggers.trigger_body或其他超过4000个字符的LONG来执行此操作(如果在SQL中需要)或32767字符(如果您只在PL/SQL中需要它),那么您将不幸地不得不使用
dbms_sql.column_value_long
过程,这将需要对dbms_sql
游标进行相当冗长和复杂的配置,并在dbms_sql.column_value_long
上进行迭代,直到提取完整的值,并在执行时附加到临时CLOB。但是,对于dba_columns.data_default、dba_tab_partitions.high_value等较短的LONG,不需要这样做。不要尝试将这些值放入CLOB,只需使用varchar 2(4000)输出即可。vc9ivgsu3#
您还可以使用sys_dburigen并决定要从CLOB中提取的大小: