Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. SQL to retrieve record count for each column of a table with blank, not null, null and distinct count in oracle sql

SQL to retrieve record count for each column of a table with blank, not null, null and distinct count in oracle sql

Scheduled Pinned Locked Moved Database
databasehelporacle
4 Posts 2 Posters 9 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Member 14229943
    wrote on last edited by
    #1

    I am trying retrieve record count for each column of a table with blank, not null, null and distinct count in oracle sql with query below.. however I am encountering below.. unable to find the missing paranethesis 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:
    *Action:
    Error at Line: 9 Column: 58

    Please can u help

    L 1 Reply Last reply
    0
    • M Member 14229943

      I am trying retrieve record count for each column of a table with blank, not null, null and distinct count in oracle sql with query below.. however I am encountering below.. unable to find the missing paranethesis 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:
      *Action:
      Error at Line: 9 Column: 58

      Please can u help

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Start with the first left parenthesis and find its matching right one. Then go on to the next left, and so on until you find the missing one. It should not take more than a couple of minutes. You would also probably be better using less complex queries.

      M 1 Reply Last reply
      0
      • L Lost User

        Start with the first left parenthesis and find its matching right one. Then go on to the next left, and so on until you find the missing one. It should not take more than a couple of minutes. You would also probably be better using less complex queries.

        M Offline
        M Offline
        Member 14229943
        wrote on last edited by
        #3

        I am still unable to resolve

        L 1 Reply Last reply
        0
        • M Member 14229943

          I am still unable to resolve

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Maybe you should rewrite this query into its separate clauses so you can see the breaks more clearly. You have a number of parts where you are concatenating text and variable fields so it may be that you have unbalanced quote characters.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups