[英]Oracle SQL to retrieve blank values, nulls, not nulls,distinct values of all columns in a table
I had picked this code from a previous post and tried tweaking the sql to count the blank count of records for the column.. however I am encountering the error below.. i am unable to resolve the error.. please can you help 我从之前的帖子中选择了这个代码并尝试调整sql来计算列的记录的空白计数..但是我遇到了以下错误..我无法解决错误..请帮助你
select owner, table_name, column_name,
to_number(xmlquery('/ROWSET/ROW/C/text()'
passing xmltype(dbms_xmlgen.getxml(
'select count(distinct "' || column_name || '") as c '
|| 'from "' || owner || '"."' || table_name || '"'))
returning content)) as distinct_count,
to_number(xmlquery('/ROWSET/ROW/C/text()'
passing xmltype(dbms_xmlgen.getxml(
'select count(case when (' || column_name || ' = ' ' ) then 0 end) as c '
|| 'from "' || owner || '"."' || table_name || '"'))
returning content)) as null_count,
to_number(xmlquery('/ROWSET/ROW/C/text()'
passing xmltype(dbms_xmlgen.getxml(
'select count(case when "' || column_name || '" is not null then 1 end) as c '
|| 'from "' || owner || '"."' || table_name || '"'))
returning content)) as notnull_count
from all_tab_columns
where owner = 'JAMES'
and table_name = 'TEST'
and data_type in ('NUMBER', 'DATE', 'TIMESTAMP', 'CHAR', 'VARCHAR2',
'NCHAR', 'NVARCHAR2');
ORA-00907: missing right parenthesis 00907. 00000 - "missing right parenthesis" *Cause: ORA-00907:缺少右括号00907. 00000 - “缺少右括号”*原因:
*Action: Error at Line: 9 Column: 58 *动作:行错误:9列:58
try this out: 试试这个:
select owner, table_name, column_name,
to_number(xmlquery('/ROWSET/ROW/C/text()'
passing xmltype(dbms_xmlgen.getxml(
'select count(distinct "' || column_name || '") as c '
|| 'from "' || owner || '"."' || table_name || '"'))
returning content)) as distinct_count,
to_number(xmlquery('/ROWSET/ROW/C/text()'
passing xmltype(dbms_xmlgen.getxml(
'select count(case when (''' || column_name || ''' = '' ) then 0 end) as c from ' || owner || '''.''' || table_name || ''''))
returning content)) as null_count,
to_number(xmlquery('/ROWSET/ROW/C/text()'
passing xmltype(dbms_xmlgen.getxml(
'select count(case when "' || column_name || '" is not null then 1 end) as c '
|| 'from "' || owner || '"."' || table_name || '"'))
returning content)) as notnull_count
from all_tab_columns
where owner = 'JAMES'
and table_name = 'TEST'
and data_type in ('NUMBER', 'DATE', 'TIMESTAMP', 'CHAR', 'VARCHAR2',
'NCHAR', 'NVARCHAR2');
It seems no need a null length string( ''
), and to provide one more quote per each inside a quoted string. 似乎不需要空长字符串(
''
),并且在引用的字符串中为每个字符串提供一个以上的引号。 So, you need to convert the string ''
at Line: 9 Column: 58 to ''''
in your code as 所以,你需要将字符串转换
''
的行:9栏:58 ''''
在你的代码
select owner,
table_name,
column_name,
to_number(xmlquery('/ROWSET/ROW/C/text()' passing
xmltype(dbms_xmlgen.getxml('select count(distinct "' ||
column_name ||
'") as c ' || 'from "' ||
owner || '"."' ||
table_name || '"'))
returning content)) as distinct_count,
to_number(xmlquery('/ROWSET/ROW/C/text()' passing
xmltype(dbms_xmlgen.getxml('select count(case when (' ||
column_name || ' = '''' ) then 0 end)
as c '||
--^^^^ these quotes
'from "' || owner ||
'"."' || table_name || '"'))
returning content)) as null_count,
to_number(xmlquery('/ROWSET/ROW/C/text()' passing
xmltype(dbms_xmlgen.getxml('select count(case when "' ||
column_name ||
'" is not null then 1 end) as c ' ||
'from "' || owner ||
'"."' || table_name || '"'))
returning content)) as notnull_count
from all_tab_columns
where owner = 'JAMES'
and table_name = 'TEST'
and data_type in ('NUMBER','DATE','TIMESTAMP','CHAR','VARCHAR2','NCHAR','NVARCHAR2');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.