Home » SQL & PL/SQL » SQL & PL/SQL » Row Count as End of the Row (Oracle 11g)
Row Count as End of the Row [message #621965] Wed, 20 August 2014 03:51 Go to next message
Genesys
Messages: 45
Registered: August 2010
Member
Hi,

Have emp table,select empno from emp display 14 records and need one row show the total number of rows.

ex:
1)1234
2)1235
3)4567
4)8901
5)4 need to display the count of rows as one row.

have tried the by using UNION all but I need in one single query.

Thanks
Genesys
Re: Row Count as End of the Row [message #621968 is a reply to message #621965] Wed, 20 August 2014 04:03 Go to previous messageGo to next message
John Watson
Messages: 8922
Registered: January 2010
Location: Global Village
Senior Member
What did you try?

Using UNION would create a single compound query.
Re: Row Count as End of the Row [message #621969 is a reply to message #621965] Wed, 20 August 2014 04:03 Go to previous messageGo to next message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
Genesys wrote on Wed, 20 August 2014 14:21

have tried the by using UNION all but I need in one single query.


Then put those rows in an Excel sheet and look at the row count in the end Razz

Else, there shouldn't be any issue with UNION ALL. Use count(*) or num_rows from user_tables where table_name='EMP';
Re: Row Count as End of the Row [message #621971 is a reply to message #621969] Wed, 20 August 2014 04:10 Go to previous messageGo to next message
Littlefoot
Messages: 21806
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Lalit Kumar B

... or num_rows from user_tables where table_name='EMP';


Which is, of course, wrong unless statistics is gathered.
Re: Row Count as End of the Row [message #621972 is a reply to message #621971] Wed, 20 August 2014 04:16 Go to previous messageGo to next message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
Littlefoot wrote on Wed, 20 August 2014 14:40
Lalit Kumar B

... or num_rows from user_tables where table_name='EMP';


Which is, of course, wrong unless statistics is gathered.


Yes... But you can take it easy for scott.emp table with 14 rows /forum/fa/917/0/
Re: Row Count as End of the Row [message #621974 is a reply to message #621972] Wed, 20 August 2014 04:21 Go to previous messageGo to next message
Littlefoot
Messages: 21806
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
For any of default Scott's tables you don't need any counters. I suspect that Genesys used/mentioned Scott as a schema we are all familiar with (so that he doesn't have to provide test case). A real problem probably uses tables different from SCOTT.EMP.
Re: Row Count as End of the Row [message #621987 is a reply to message #621965] Wed, 20 August 2014 05:26 Go to previous messageGo to next message
Michel Cadot
Messages: 68625
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

GROUP BY ROLLUP is also an option.
You can find a more complex example there.

Re: Row Count as End of the Row [message #622019 is a reply to message #621965] Wed, 20 August 2014 08:42 Go to previous messageGo to next message
Solomon Yakobson
Messages: 3269
Registered: January 2010
Location: Connecticut, USA
Senior Member
You can also use MODEL:

SELECT  empno,ename,job,mgr,hiredate,sal,comm,deptno
  FROM  emp
  MODEL
    DIMENSION BY(rownum rn)
    MEASURES(empno,ename,job,mgr,hiredate,sal,comm,deptno,count(*) over() cnt)
    RULES(
          empno[cnt[1] + 1] = cnt[1]
         )
/

     EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- ----------
      7369 SMITH      CLERK           7902 17-DEC-80        800                    20
      7499 ALLEN      SALESMAN        7698 20-FEB-81       1600        300         30
      7521 WARD       SALESMAN        7698 22-FEB-81       1250        500         30
      7566 JONES      MANAGER         7839 02-APR-81       2975                    20
      7654 MARTIN     SALESMAN        7698 28-SEP-81       1250       1400         30
      7698 BLAKE      MANAGER         7839 01-MAY-81       2850                    30
      7782 CLARK      MANAGER         7839 09-JUN-81       2450                    10
      7788 SCOTT      ANALYST         7566 19-APR-87       3000                    20

     EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- ----------
      7839 KING       PRESIDENT            17-NOV-81       5000                    10
      7844 TURNER     SALESMAN        7698 08-SEP-81       1500          0         30
      7876 ADAMS      CLERK           7788 23-MAY-87       1100                    20
      7900 JAMES      CLERK           7698 03-DEC-81        950                    30
      7902 FORD       ANALYST         7566 03-DEC-81       3000                    20
      7934 MILLER     CLERK           7782 23-JAN-82       1300                    10
        14

15 rows selected.

SQL> 


SY.
Re: Row Count as End of the Row [message #622020 is a reply to message #622019] Wed, 20 August 2014 08:50 Go to previous messageGo to next message
Genesys
Messages: 45
Registered: August 2010
Member
Thank you soo much
Re: Row Count as End of the Row [message #622081 is a reply to message #622020] Wed, 20 August 2014 16:19 Go to previous message
Bill B
Messages: 1971
Registered: December 2004
Senior Member
if you are using sqlplus you can always use


break on report
compute count of empno on report

SELECT empno,ename,job,mgr,hiredate,sal,comm,deptno
FROM emp;


which will work with any version from oracle 7 forward

[Updated on: Wed, 20 August 2014 16:20]

Report message to a moderator

Previous Topic: Compare and update Stored proc
Next Topic: SP2-0552: Bind variable "5" not declared.
Goto Forum:
  


Current Time: Thu Mar 28 14:38:05 CDT 2024