Since 2010, OraERP is a Oracle Forums, Community of Oracle Professionals including Fusion/Cloud Application Consultants, Enterprise Architects, ERP Cloud, HCM Cloud, CX Cloud and OCI Experts, ERP Experts, Oracle Apps Functional Consultants, Apps DBAs, DBAs, Cloud DBAs, Digital Architect, PaaS Experts, IaaS, OCI Architects, Technical Consultants, Fusion Middleware Experts, SQL, PL/SQL Developers and Project Managers. Welcome to OraERP.com Social Community, a friendly and active community of Oracle Technology Professionals who believe that technology can ‘make the world a better place’. By joining Oracle ERP Community you will have the ability to Post Topics, Receive our Newsletter, subscribe to threads and access many other special features. Registration is Quick and Simple. Get unlimited access to Oracle Tutorials, Articles, eBooks, Tools and Tips .
Oracle Forum - The Knowledge Center for Oracle Professionals - Looking Beyond the Possibilities
›
Platform as a Service (PaaS)
›
Oracle Technology
›
SQL & PL/SQL
Query to find filled rows only
Query to find filled rows only
Query to find filled rows only
|
07-22-2015, 03:42 AM,
|
|||
|
|||
Query to find filled rows only
I have a following situation: table1 col1 col2 1 50 2 70 3 null 4 null null 8 null 9 null 10 5 11 6 12 7 14 I want to write query that count rows which are not null, i have more than 100 colums so dont want to use select count(col1),count(col2) and so on. Replace EMP with your table name. The result will be a colum containing complete select statement with count function for all columns. Query: SELECT 'SELECT ' || LTRIM(MAX(SYS_CONNECT_BY_PATH(COLS, ',')) KEEP(DENSE_RANK LAST ORDER BY NEW1), ',') || ' FROM EMP' AS STRING FROM (SELECT COLUMN_NAME, COLS, ROW_NUMBER() OVER(PARTITION BY COLUMN_NAME ORDER BY COLS) AS NEW1, ROW_NUMBER() OVER(PARTITION BY COLUMN_NAME ORDER BY COLS) - 1 AS PREV FROM (SELECT 1 COLUMN_NAME, 'COUNT(DISTINCT ' || COLUMN_NAME || ')' AS COLS FROM user_tab_columns WHERE TABLE_NAME = 'EMP')) GROUP BY COLUMN_NAME CONNECT BY PREV = PRIOR NEW1 AND COLUMN_NAME = PRIOR COLUMN_NAME START WITH NEW1 = 1; Result: SELECT COUNT(DISTINCT COMM),COUNT(DISTINCT DEPTNO),COUNT(DISTINCT EMPNO),COUNT(DISTINCT ENAME),COUNT(DISTINCT HIREDATE),COUNT(DISTINCT JOB),COUNT(DISTINCT MGR),COUNT(DISTINCT SAL) FROM EMP |
|||
« Next Oldest | Next Newest »
|
Possibly Related Threads… | |||||
Thread | Author | Replies | Views | Last Post | |
Oracle SQL Developer not able to find Java Virtual Machine | Justen Kegan | 1 | 3,866 |
11-05-2014, 04:14 PM Last Post: Balin Chakra |
Users browsing this thread: 1 Guest(s)
Current time: 11-22-2024, 12:16 PM
Powered By MyBB, © 2002-2024 MyBB Group.