How to print a number of column 'break' in SQL * MORE?

Hello

I have a query that returns results similar to the following:

SQL> BREAK ON DEPTNO
SQL> SELECT DEPTNO, ENAME, SAL
  2  FROM EMP
  3  WHERE SAL < 2500
  4  ORDER BY DEPTNO;

    DEPTNO ENAME             SAL
---------- ----------- ---------
        10 CLARK            2450
           MILLER           1300

        20 SMITH             800
           ADAMS            1100

        30 ALLEN            1600
           JAMES             950
           TURNER           1500
           WARD             1250
           MARTIN           1250

9 rows selected.

I want to display the number of departments instead of "9 selected lines.

For example:

Number of departments = 3

Please advise!

Hello

Here is an example of how you can hide everything except a deptno by Department in the query, in SQL * Plus, so that SQL * Plus can count distinct values:

WE BREAK deptno on REPORT

CALCULATE COUNTING "separate deptnos" LABEL OF deptno on REPORT

SELECT "" AS ""

CASE

WHEN ROW_NUMBER () OVER (PARTITION BY deptno

ORDER BY ename

) = 1

THEN deptno

END AS deptno

ename

sal

FROM scott.emp

Sal WHERE<>

ORDER BY emp.deptno - in other words, the table, not an expression BOX

ename

;

In your original query, you don't care the order within each Department.  However, in this case, make sure that the line on which ROW_NUMEBR affects number 1 actually comes first in each Department.

Output:

DEPTNO ENAME SAL

---------------- ---------- ---------- ----------

10 CLARK 2450

1300 MILLER

20 ADAMS 1100

SMITH, 800

30 ALLEN 1600

JAMES 950

MARTIN 1250

TURNER 1500

WARD 1250

----------

Separate deptnos 3

My preference is always to do a separate query to get the number.

Tags: Database

Similar Questions

  • How to count the number of columns in an oracle table using sql

    How to count the number of columns in an oracle table using sql

    You must put the name of the table in capital letters

    As

    SELECT COUNT(1)
      FROM user_tab_columns
    WHERE table_name = 'EMP';
    
    or
    
    SELECT COUNT(1)
      FROM user_tab_columns
    WHERE table_name = UPPER('Emp');
    

    Concerning
    Arun

  • How to set the number of columns at runtime with the text layout component

    I couldn't work out how to use AS3 to set the number of columns in the text layout component. Any help?

    Oops. I discovered it:

    my_txt.textFlow.ColumnCount = 3;
    my_txt.textFlow.columnGap = 10;

  • the number of columns in dynamic sql

    Hello

    I was wondering if you could count the number of columns had a dynamic sql code.

    Very simple eg.

    Say I had a string 'select 1, 2,3,4,5,6 double' and I only immediate excute. Is it possible to count the number of column IE 6 columns.

    I know s/n | THE USER | ALL_TAB_COLUMNS, but it could be a few different columns columns, and it is not a view.

    Thanks for you advice/help.

    with the "immediate execution" option you cannot get metadata such as the number of columns for the executed query. Use rather dbms_sql...

    Research of DESCRIBE_COLUMNS string in the link below... It will give you an idea of how to make to get the same.
    http://www.morganslibrary.org/reference/DBMS_SQL.html

    Ravi Kumar

    Published by: ravikumar.sv on July 30, 2010 15:51

  • How to find the number of column under Basic forms

    Hi all

    There is the serial number in the pay_assignment_actions Table column
    Through basic shapes where can I find the serial number column
    Is someone can you please tell me what would be the navigation.

    Thanks in advance

    You need to check the correct recording-
    It would be visible only for those guys-

    Void Payment
    Ext/Manual payment
    Cheque writer
    Magnetic report
    
  • How to print a number in srintg format

    I want to print

    10527

    in this format

    ten thousand five hundred twenty-seven

    Thank you
    SQL> select to_char( to_date(10527,'J'),'Jsp') from dual;
    
    TO_CHAR(TO_DATE(10527,'J'),'JSP')
    --------------------------------------
    Ten Thousand Five Hundred Twenty-Seven
    

    To number greater then 5373484, use techniques mentioned in [url http://asktom.oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:1407603857650] this link.

  • How can I get number of columns for all tables in a schema?


    Hello

    Can someone help me with the code to retrieve any of the columns in each table of a master plan? I'm sorry if it sounds simple. I'm a newbie...

    Thank you

    Maybe:

    Select table_name

    count (*) col_count

    of user_tab_cols

    Table_name group

    order of table_name;

  • How to extract the names of columns in dynamic SQL

    Hi all

    Is it possible to extract all the names of columns in a dynamic query?

    In my case according to the user selections that my query will get changed (number of the column, column name and tables that everything can vary).

    So now, is it possible to retrieve all the column names of the dynamic query generated?

    I am using Oracle 11g (11.2.0.4)

    Thank you

    Shaz

    Re: Dynamic Extraction on dynamic Sql

  • OfficeJet 6500 more: how to print from a program back on Officejet 6500 more?

    On the old laserjet, I could open the printer as a file in a back program and send lines to print.  Is it possible to do it on the Officejet 6500 Plus?

    >> ... Is it possible to do it on the Officejet 6500 Plus? ...

    Not really.

    This model printer (like most peripheral inket consumers) do not understand plain text ASCII.

    The only way to send data to it is to imitate what does the printer driver, and convert text and images (the owner) encapsulated, compressed, raster image understood by the device format (which is unencapsulates and decompresses these images and prints the result 'points').

  • How to end program simultaneously on alert for a SQL * MORE

    Hello
    I want to conclude a sql * plus program contributing to the caveat. Given that we spend RETCODE contains, I don't know how to do this. But I know for sure that we can do this since I did sometimes return but could not find the code.

    Help, please.

    TIA.

    MetaLink/MOS Note 866194.1 can help you. It is specific to the host programs, but it uses the fnd_concurrent.set_completion_status program in a script from sqlplus.

    page 21-9 11i developers guide describes the function of set_completion_status.

    Published by: mcharchuk on December 11, 2009 08:42

  • How to print the Boolean variable?

    Hi gurus,

    How to print a Boolean variable in a pl/sql block?
    SQL> ed
    Wrote file afiedt.buf
    
      1  DECLARE
      2  l_test BOOLEAN:=TRUE;
      3  i boolean;
      4  BEGIN
      5  dbms_output.put_line(l_test);
      6* END;
    SQL> /
    dbms_output.put_line(l_test);
    *
    ERROR at line 5:
    ORA-06550: line 5, column 1:
    PLS-00306: wrong number or types of arguments in call to 'PUT_LINE'
    ORA-06550: line 5, column 1:
    PL/SQL: Statement ignored
    Kind regards
    Claudy
    DECLARE
    l_test BOOLEAN:=TRUE;
    BEGIN
    dbms_output.put_line(
       case
          when l_test then 'TRUE'
          when l_test is null then 'NULL'
          else 'FALSE'
       end
    );
    END;
    
  • How can I play files CSV lines with a different number of columns?

    Hi all

    I am trying to load CSV with DIAdem 2014 files, and I found there is a great tool, "use".

    However, with the CSV use tool, there are critical problem with my data files. (See photo)

    As you can see the CSV file attached, it includes a lot of lines with different columns.

    And here, use read the number of columns of 1st line (e.g.: 4 columns) and set it as the number of columns to read.

    So I can not load all of the data (e.g.: 53 columns) if first row data were lower than columns.

    Can anyone recommend any approach, please?

    Kind regards

    Young

    Admin 24/03/16 Note: files deleted by request of the user

    I just add a few lines of script and fix the related use. (I just added the code to get a direct look).

    The uri of the file will appear as a new kind of load in the dialog file tiara is intalled by double click

    Would be nice if you could provide some information, how the data was created. Maybe we can it add as official of our web page to use plugin.

    Option Explicit

    Void ReadStore (File)

    File.Formatter.Delimiters = «»
    File.Formatter.LineFeeds = \n
    File.Formatter.DecimalPoint = '. '.

    Dim startLine: startLine = file. GetNextLine()
    <>InStr (startLine, ' [Tenergy Bus Log Data] "" ") then
    call RaiseError()
    end if

    And that not File.Position = File.Size
    Dim groupName: groupName = file. GetNextStringValue (eString)
    If it isn't root. ChannelGroups.Exists (groupName) then
    root. ChannelGroups.Add (groupName)
    end if
    Dim grp: set grp = root. ChannelGroups (groupName)
    Dim i: i = 1
    do for real
    Dim val: val = file. GetNextStringValue (eR64)
    If isempty (val) then
    Exit
    end if
    < i="">
    dial the grp. Channels.Add ("Brand" & I, eR64)
    end if
    protected chObj: set chObj = grp. Channels (i)
    chObj.Values (chObj.Size + 1) = val
    i = i + 1
    loop
    Call File.SkipLine)
    Wend

    End Sub

  • How can I know the number of columns and lines on excel file

    How reading the number of columns and rows on an excel file after you open the file in excel with ActiveX.

    Using the example of excel200dem, I read that the file data is excellent.

    However, in this example, I just give the number of lines and columns.

    I want to know the number of lines and columns not giving those in C code automatically.

    Who knows this things? -?

    Help me please.

    Hello

    (1) this forum provides a search option, you must use in doing so, you will find this post

    (2) don't solve you your earlier questions? If so, you must mark responses that have helped you find a solution.

  • How to query the total number of columns and lines filled with data?

    How to get the number of rows and columns in Exel file data using Excel report?

    Since you have posted this question in the forum of LabWindows/CVI, I guess you want to know how to do with CVI.

    You need to know how to open and activate the Excel data file.

    Depending on the function returns the total number of columns and lines col_count row_count, respectively.

    -----------------------------------------------------------------------------------------------------------------------------------------

    int CountColumnsAndRows (void)
    {
    Error HRESULT = 0;
    CAObjHandle rangeCurrentRegionHandle = 0;
    CAObjHandle rangeColumnsHandle = 0;
    CAObjHandle rangeRowsHandle = 0;
      
    unsigned long col_count = 0, row_count = 0;
      
    Must use the 'A1' property and CruuentRegion count the total of columns and lines, including the drafts!
      
    error = CA_VariantSetCString (& MyCellRangeV, 'A1');
      
    error = Excel_WorksheetRange (ExcelWorksheetHandle, NULL, MyCellRangeV, CA_DEFAULT_VAL, & ExcelRangeHandle);
    If (error<0) goto="">
      
    error = Excel_GetProperty (ExcelRangeHandle, & ErrorInfo, Excel_RangeCurrentRegion, CAVT_OBJHANDLE, & rangeCurrentRegionHandle);
    If (error<0)  goto="" error="">
      
    error = Excel_GetProperty (rangeCurrentRegionHandle, & ErrorInfo, Excel_RangeColumns, CAVT_OBJHANDLE, & rangeColumnsHandle);
    If (error<0)  goto="" error="">
      
    error = Excel_GetProperty (rangeColumnsHandle, & ErrorInfo, Excel_RangeCount, CAVT_LONG, & col_count);
    If (error<0) goto="">
      
    error = Excel_GetProperty (rangeCurrentRegionHandle, & ErrorInfo, Excel_RangeRows, CAVT_OBJHANDLE, & rangeRowsHandle);
    If (error<0)  goto="" error="">
      
    error = Excel_GetProperty (rangeRowsHandle, & ErrorInfo, Excel_RangeCount, CAVT_LONG, & row_count);
    If (error<0) goto="">

    Error:

    CA_VariantClear (& MyCellRangeV);
    CA_VariantClear (& MyVariant);
    ClearObjHandle (& ExcelRangeHandle);
    ClearObjHandle (& rangeCurrentRegionHandle);
    ClearObjHandle (& rangeColumnsHandle);
    ClearObjHandle (& rangeRowsHandle);
      
     
    If (error<>
    ReportAppAutomationError (error);
      
    error return;
    }

  • How can I know the number of columns in a TYPE?

    Hello

    If we have a guy like below

    type vc_arr2 is table of the varchar2 (32767) index directory.

    How can I get the number of columns?

    Minoo.TK wrote:

    Hello

    If we have a guy like below

    type vc_arr2 is table of the varchar2 (32767) index directory.

    How can I get the number of columns?

    It is a type of associative array definition. A table has no columns. It is a collection of elements (variables or values). An array location is usually called a cell.

    The standard method Count() exist in Oracle for all table types.

    As for the definition of the table, as in structures, variables make the table contain - associative array is defined in the PL/SQL code and does not exist in the layer of metadata to the database as a new user-defined type. For the definition, you must read the declaration of PL/SQL defining the table.

    Note that there is very rarely the need for associative tables in PL/SQL - 99% of the time they are used without any idea as to what as a table associative is also.

Maybe you are looking for

  • Pavilion p6300 uk: Windows 10

    Hi, my name is Alan Sanders, I tried to upgrade to Windows 10, but get a compatibility report with the following text: -. NVIDIA GeForce 6150SE nForce 430 The manufacturer of the screen did not your screen compatible with Windows 10, audit to support

  • How to backup to external hard drive (removable) for windows home server 2011

    Your online help recommend ' to use several external hard drives and rotate the drives between onsite and offsite storage locations", but there is nothing that explains the procedures to be put in place. I have vascular 1 internal disk used as a serv

  • HP envy 6 - 1010sv: left hinge broke, about to break

    Hello! I have the 6-1010sv envy and the left hinge broke. From what I've read in the forums, this is a very common problem. Right now I'm looking for my repair options. I called the phone number, I found in the forums and they said since it is a guar

  • Deploy my Application via Desktop download instead of OTA

    I know how to deploy and have people download my app OTA but what files do I need for clients to download onto their desktop computer and then install via Blackberry Desktop Manager (why some people want to do this is beyond me...). Should I just the

  • Nikon D500 NAVE is not compatible with stand-alone (not CC) Lightroom 6.0 - how to upgrade to 6.5?

    I took off with my nice new D500 but I can't download the pictures to my standalone (not CC) 6.0 of Lightroom.  I see the update to 6.5 works with the NAVE D500 files, but how can I update my Lightroom for who?  I tried help > update, but it says it'