How to make the lines dynimac columns in Oracle PL/SQL?

I have this request:
select cso.branch,
  decode(NVL(cso.YES,0)+ NVL(cso.NO,0)+ NVL(cso.NA,0),0,'N','Y') ||' - '|| NVL(cso.officer,0) AS CSO_YN
from (
SELECT A.BRAN_CODE_PK as branch, a.emp_code_pk as officer, 
   COUNT(CASE WHEN D.STATUS = 1 THEN D.STATUS ELSE NULL END) YES,
   COUNT(CASE WHEN D.STATUS = 2 THEN D.STATUS ELSE NULL END) NO,
   COUNT(CASE WHEN D.STATUS = 3 THEN D.STATUS ELSE NULL END) NA
FROM sales_team_accounts A, users U LEFT OUTER JOIN daily_check_lists D ON (D.USER_ID_PK = U.EMP_OFFICER_CODE
                                                                and to_date(D.CHECK_LIST_DATE, 'DD-MON-YYYY') = '08-JUL-2010' ) -- date should be the parameter date)
WHERE 1=1
AND A.EMP_OFFICER_CODE = U.EMP_OFFICER_CODE
AND A.sale_type_fk = 101 -- CSO
AND A.SUPV_EMP_CODE_FK != 0
and a.BRAN_CODE_PK = 1001
group by A.BRAN_CODE_PK, a.emp_code_pk
) cso;
The result of this query is the following:
BRANCH     CSO_YN
--------------------------------------
1001             Y - 321
1001             N - 335
1001             Y - 90050
1001             N - 303
The scenario is, there could be maximum 7 officers in a branch,
the total number of columns must therefore 7, and employee Y or N must be shaped in these 7 columns.

So for each branch, it will always be 1 row to have 7 columns:
So I want that it resembles the following:
BRANCH     CSO1      CSO2      CSO3         CSO4       CSO5     CSO6     CSO7
-----------------------------------------------------------------------------------------------------------
1001        Y - 321    N - 335    Y - 90050    N - 303
Need to do using only the PL/SQL query

Published by: imation3m on October 22, 2010 12:21

http://asktom.Oracle.com/pls/Apex/f?p=100:11:0:P11_QUESTION_ID:766825833740
http://asktom.Oracle.com/pls/Apex/f?p=100:11:0:P11_QUESTION_ID:15151874723724
http://asktom.Oracle.com/pls/Apex/f?p=100:11:0:P11_QUESTION_ID:7644594042547

Tags: Database

Similar Questions

  • How to make the lines for writing?

    How to create lines for writing?

    Tablet notebook =

    Make the paragraph style, as mentioned above. Adjust the space after you, the thickness of line for the rule below. Press enter for each paragraph.

    Mike

  • How to view the line of columns without using the pivot keyword

    Hello
    could someone help me how to display lines in columns without using the keyword pivot and actuall is my scenario, iam having two tables with names and examples of data is shown below

    MIDDLE MINAME TASKID TASKNAME IDENTIFICATION PROJECT

    1 PROJ1 1 AA 100 PR1_TASK1
    1 PROJ1 3 CC PR1_TASK3 102
    1 PROJ1 DD 4 103 PR1_TASK4
    1 PROJ1 EE 5 104 PR1_TASK5
    1 PROJ1 6 105 FF PR1_TASK6
    2 PROJ2 EE 5 114 PR2_TASK1
    2 PROJ2 6 115 FF PR2_TASK2
    2 PROJ2 GG 7 116 PR2_TASK3
    2 PROJ2 HH 8 117 PR2_TASK4
    2 PROJ2 9 118 PR2_TASK5 JJ
    2 PROJ2 KK 10 119 PR2_TASK6
    2 PROJ2 1 AA PR2_TASK7 120


    The output should show the project and County of tasks at a given stage as shown below

    project AA BB CC DD EE FF GG HH JJ KK
    1 2 0 1 5 3 2 0 2 1 0
    2 1 2 0 2 1 0 2 4 3 1


    Thanks in advance,
    VVR
    CREATE TABLE pivot_test (
    ID           NUMBER,
    PROJECT      VARCHAR2(10),
    MID          NUMBER,
    MINAME       VARCHAR2(5),
    TASKID       NUMBER,
    TASKNAME     VARCHAR2(10)
    );
    
    INSERT INTO pivot_test VALUES (1, 'PROJ1', 1,  'AA', 100, 'PR1_TASK1');
    INSERT INTO pivot_test VALUES (1, 'PROJ1', 3,  'CC', 102, 'PR1_TASK3');
    INSERT INTO pivot_test VALUES (1, 'PROJ1', 4,  'DD', 103, 'PR1_TASK4');
    INSERT INTO pivot_test VALUES (1, 'PROJ1', 5,  'EE', 104, 'PR1_TASK5');
    INSERT INTO pivot_test VALUES (1, 'PROJ1', 6,  'FF', 105, 'PR1_TASK6');
    INSERT INTO pivot_test VALUES (2, 'PROJ2', 5,  'EE', 114, 'PR2_TASK1');
    INSERT INTO pivot_test VALUES (2, 'PROJ2', 6,  'FF', 115, 'PR2_TASK2');
    INSERT INTO pivot_test VALUES (2, 'PROJ2', 7,  'GG', 116, 'PR2_TASK3');
    INSERT INTO pivot_test VALUES (2, 'PROJ2', 8,  'HH', 117, 'PR2_TASK4');
    INSERT INTO pivot_test VALUES (2, 'PROJ2', 9,  'JJ', 118, 'PR2_TASK5');
    INSERT INTO pivot_test VALUES (2, 'PROJ2', 10, 'KK', 119, 'PR2_TASK6');
    INSERT INTO pivot_test VALUES (2, 'PROJ2', 1,  'AA', 120, 'PR2_TASK7');
    
    SELECT ID as PROJECT,
           SUM(DECODE(miname, 'AA', 1, 0)) AS AA,
           SUM(DECODE(miname, 'BB', 1, 0)) AS BB,
           SUM(DECODE(miname, 'CC', 1, 0)) AS CC,
           SUM(DECODE(miname, 'DD', 1, 0)) AS DD,
           SUM(DECODE(miname, 'EE', 1, 0)) AS EE,
           SUM(DECODE(miname, 'FF', 1, 0)) AS FF,
           SUM(DECODE(miname, 'GG', 1, 0)) AS GG,
           SUM(DECODE(miname, 'HH', 1, 0)) AS HH,
           SUM(DECODE(miname, 'JJ', 1, 0)) AS JJ,
           SUM(DECODE(miname, 'KK', 1, 0)) AS KK
    FROM   pivot_test
    GROUP BY ID;
    
    PROJECT AA BB CC DD EE FF GG HH JJ KK
    ------- -- -- -- -- -- -- -- -- -- --
          1  1  0  1  1  1  1  0  0  0  0
          2  1  0  0  0  1  1  1  1  1  1 
    
  • How to make the lines selectable listfield, when the list has been added to a dialog box

    Hello

    I added a listfield to a dialog box. Now I want that when I click on a line any of this list field, I should get a menu (i.e. something should be available for me so that I can perform an action on the selected line). But when I click on the line, nothing happens.

    Help, please

    Create your own screen, its less than the actual display dimensions to make it look like a pop-up screen. When a line is selected/clicked, call makeMenu.

  • How to convert the lines into columns dynamically

    HII
    I have a 'report_line' with the following data table

    location_code line_code value
    LOC1 L1 12
    loc2 L1 13
    LOC1 L2 15
    loc2 L3 11
    LOC3 L1 9

    Now I want the o/p by converting the line_codes in clumns as below

    L1 L2 L3
    LOC1 12 15
    13 11 loc2
    LOC3 9

    How can I do this dynamically. Line codes are not constatnt, they can change for each scenario.

    Thank you
    Sandeep

    I want just a sql for this query and no. columns ' maximum of are 6.

    In this case you can do.

    --sample data
    with t
    as
    (
    select 'loc1' location_code, 'L1' line_code, 12 value from dual union all
    select 'loc2', 'L1', 13 from dual union all
    select 'loc1', 'L2', 15 from dual union all
    select 'loc2', 'L3', 11 from dual union all
    select 'loc3', 'L1', 9 from dual
    )
    --end of sample data
    select location_code,
           max(decode(line_code, 'L1', value, null)) L1,
           max(decode(line_code, 'L2', value, null)) L2,
           max(decode(line_code, 'L3', value, null)) L3,
           max(decode(line_code, 'L4', value, null)) L4,
           max(decode(line_code, 'L5', value, null)) L5,
           max(decode(line_code, 'L6', value, null)) L6
      from t
     group by location_code
    

    Here I used the WITH clause as an example of table. You can replace the "t" table name in the select statement with your actual table and remove the WITH clause.

  • How to make the line as doodle art in illustrator?

    139_121120_035927_poler-camping-stuff.jpgPS_02_Lgr.jpg

    I try my line using roughen effect, try smooth and any amount of combination, but sound more like wavy line

    I want that something looks than doodle art.

    is a method to achieve this result?

    or can only achieve by downloading the custom right bruh?

    Thank you!

    Make a stroke

    Apply the effect > path > course Outline (this has no visible effect)

    Apply butcher

    In panel appearance, contour line must be less than the race and rough must be under the contour line. You must move in order to achieve this.

  • How to make the line break in the Validation Script Message

    Hello

    Declaration of im trying to write a multi-line error message in the Validation Script Message to a textfield, but every time that I hit, I find myself at the front of the current line instead of a new line.  I also tried \n with no luck.  The only way I have found is by entering the text in Notepad, then cut + paste into the Message of Script of Validation box.  Is this a bug with the Designer?  I have Designer ES 8.2.1.3158.1.475346.

    ValScriptMesgEd.JPG

    I know how to do scripted ex.  this.validationMessage = "line1\nline2" but what I want is store Section and the field name in the Script of selection Message box and then generate the error message ontop via the script.

    ex.

    this.validationMessage = this.validationMessage + ' Validation has no reason of...» » ;

    Just tested this and it looks like ctrl - enter in the works.

  • How to make the default text size and line spacing in small Sticky Notes?

    How to make the default text size and line spacing in small Sticky Notes

    Hello

    I suggest that you try the method below and check if it helps.

    Method 1: analysis of auditor of file system (CFS)

    System File Checker is a Windows utility that allows users to find corruptions in Windows system files and restore the damaged files. To perform a scan of the SFC, check out the link: https://support.microsoft.com/en-us/kb/929833.

    Note: the steps for Windows 8/8.1, works perfectly with Windows 10.

    Method 2: clean boot

    A clean boot is executed to start Windows by using a minimal set of drivers and startup programs. This will eliminate software conflicts that occur when you install a program, an update or when you run a program in Windows. Follow the link to perform the clean boot: https://support.microsoft.com/en-us/kb/929135.

    Kind regards

    Angelo bar

    Microsoft community

  • When I export my file to generate a .pdf file, the text box is literally a box around it! How to make this line disappear?

    When I export my file to generate a .pdf file, the text box is literally a box around it! How to make this line disappear?

    Looks like you have a line on it. Select the image and the race set to None.

  • How to make reference to a column name in the domain constraint

    When specify us a constraint check (for SQL Server) in a field, we need to enter an expression in the syntax, for example

    Len (Phone) > 7

    Later, the Modeler will exactly this expression in the SQL code. But it would be wrong as a constraint to refer to a column name in the table (which would not be 'phone').
    So, how to make the data name Modeler to a real column in the constraint domain?

    Hello

    Use the % COLUMN as a placeholder column name - len (%COLUMN%) > 7

    Philippe

  • How to make the transition to digital in 10g

    Hi all


    We have 10g database of primary and standby, I have never worked before sleep, customer wants me start switch, can you please let me know how to make the transition to digital in 10g.


    Thank you very much.

    It's the way I'm following passage in the
    ------------------------------------------------------------

    (1) check that there is no active users connected to databases.
    (2) select message from v$ dataguard_status;
    (3) select protection_mode from database v$.

    Step 1 check if it is possible to perform a failover.

    SQL > select database_role, db_unique_name, SWITCHOVER_STATUS, v database name $;

    DATABASE_ROLE DB_UNIQUE_NAME SWITCHOVER_STATUS NAME
    ---------------- ------------------------------ -------------------- ---------
    PRIMARY OFMSREGT_SIM UNAUTHORIZED OFMSREGT

    SQL >

    If you get NO allow status for SWITCHOVER_STATUS, verify that the standby database is connectivity.

    If the SWITCHOVER_STATUS column displays ACTIVE SESSIONS, you can successfully achieve a failover by adding the WITH clause LOGOFF to the statement ALTER DATABASE COMMETTRE through PHYSICAL standby

    Step 2 open the passage on the primary database.

    SQL > SHUTDOWN IMMEDIATE;
    SQL > STARTUP MOUNT;
    SQL > ALTER DATABASE COMMIT TO SWITCH STANDBY MODE PHYSICAL;

    Step 4, check the transition state in the view V$ DATABASE.

    SQL > SELECT SWITCHOVER_STATUS FROM V$ DATABASE;
    SWITCHOVER_STATUS
    -----------------
    TO_PRIMARY
    1 selected line

    Step 5 place yourself in the role of physical standby database target the main role.

    You can switch a standby database physical role ensures the primary role
    When the standby database instance is mounted mode redo apply or open
    for read-only access

    SQL > ALTER DATABASE COMMIT AT THE GRADE CROSSING;

    Step 6 complete the transition of the database ensures the main role.

    If the physical standby database has not been opened in read-only mode since the
    the last time it was started, run the SQL ALTER DATABASE OPEN to open
    the new primary database:

    SQL > ALTER DATABASE OPEN;

    If the physical database was opened read only since the last
    time it was launched, you must close the database waiting for target and restart:

    SQL > SHUTDOWN IMMEDIATE;
    SQL > STARTUP;

    Note: There is no need to close and restart other bases before (not involved in the digital switchover) who are online at the time of the failover. These databases on hold will continue to
    function normally once the failover is completed.

    Step 7 if necessary, restart log apply services on standby databases.
    He must deliver the command FRO repeat apply as:
    SQL > change database recovery managed standby database disconnect from the session.
    or
    And stop repeating applies to give
    SQL > alter database recover managed standby database cancel;

    Step 3 Shut down and restart the former primary instance.

    SQL > SELECT OPEN_MODE FROM V$ DATABASE;

    Step 9 check the synchronization between the primary and standby:

    Primary
    SQL > select thread #, max(sequence#) in v$ archived_log where archived = 'YES' group by thread #;

    Sleep mode
    SQL > select thread #, max(sequence#) in v$ archived_log in case of application = 'YES' group by thread #;

    Stop the former primary instance and restart and mount the database:

    Sense of SWITCHOVER_STATUS
    --------------------------------------------
    The column SWITCHOVER_STATUS of v$ database can have the following values:

    NOT ALLOWED - this is a database of pending and the primary database has
    not been first switched, or it's a back-end database and there is no data pending.

    ACTIVE SESSIONS - indicates that there are active sessions of SQL attached to
    the primary database or emergency that must be disconnected before the
    failover operation is allowed.

    Transition to THE PENDING - this is a database of relief and the primary database
    application of the digital switchover has been received but untreated.

    LATENT pass - the digital switchover has been waiting mode, but has not completed
    and I went back to the primary database.

    Primary SCHOOL - this is a database of pending, any sessions active, i.e.
    allows to switch to a primary database.

    In STANDBY mode - this is a primary database, any sessions active, i.e.
    allows to switch to a standby database.

    RECOVERY NEEDED - this is a database of pending that has not received the
    application of the digital switchover.

  • How to make the top sites page appears when I open a new tab? Why have I not of "buttons" to pin a top site of the page tab?

    When I open a new tab, NO best sites don't show up... shows just a search engine box. I have Firefox 33.0. Why is there no 'pin' button when I opened a new page? How to make the top sites page appears when I open a new tab?

    Here is some additional information on the configuration of the new tab page:

    (1) in a new tab, type or paste Subject: config in the address bar and press ENTER. Click on the button promising to be careful.

    (2) in the search above the list box, type or paste newtab and make a pause so that the list is filtered

    (3) double-click the preference browser.newtab.url and enter your favorite page:

    • (Default) page thumbnails = > subject: newtab
    • Blank tab = > subject: empty
    • Built-in Firefox homepage = > topic: welcome
    • Any other page = > full URL of the page

    Press Ctrl + t to open a new tab and check that it worked. Fixed?

    Some traps:

    If Firefox will not let you change this setting: you can have what is called SearchProtect on your system.

    Firefox if allows you to save your changes, but he doesn't know: one of your extensions may be the substitution of her. You can consult, disable and/or remove extensions on the addons page:

    "3-bar" menu button (or tools) > Add-ons > in the left column click on Extensions

    If the modification works during your session, but during the next startup is leads to: you could have a user.js file in your personal settings Firefox (your Firefox profile folder). This article describes how to track down and delete the file: How to fix preferences that will not save.

    A little luck?

  • How to make the snow fall go far in the background that I've recently added a newsletter on your part?

    How to make the snow fall go far in the background that I've recently added a newsletter of mozilla to? It appears on things, I feel.

    I can't talk about it. What is an extension?

    You can disable or remove unwanted page extensions modules. Either:

    • CTRL + SHIFT + a
    • Firefox orange (or the Tools menu) button > Add ons

    In the left column, click Extensions. If you don't it spot, perhaps in the appearance section?

  • How to make a line intersect with a path at random angles?

    How to make a line intersect with the anchor point of a half circle when you want the line to continue beyond the anchor point of the half circle at an angle to randomly?

    Now that I saw your picture, I understand the problem. You must make the careful construction work.

    Take a look at this:

    Start by drawing your circle. Drag the ruler guides (here dotted lines) so that they snap into its Center C.

    Drag another landmark of rule to your point of origin O.

    With the Pen or line tool Segment a line of O to T A. setting by the eye as precisely as possible with the end of it A directly selected.

    A copy of the line OA rotate 90 °. Using smart guides, drag the new line until it crosses the center of the Circle C.

    Direct, select the end of your original line and move it to T until the smart guides say "cross".

    Now, with the selected OA line use the scale tool. O-click and drag to 45 degrees by holding the Shift key. Your line will extend over its own length.

    In order to take account of the OA line across the circle just use the Reflect tool. Select the line, an Option, click the horizontal guide and copy reflect across the horizontal axis through the dialog box.

  • How to set the size of column sqlplus.exe?

    SQL> select * from dba_cons_columns where user='USER1' and table_name='PARENT1';
    
    OWNER                          CONSTRAINT_NAME
    ------------------------------ ------------------------------
    TABLE_NAME
    ------------------------------
    COLUMN_NAME
    --------------------------------------------------------------------------------
      POSITION
    ----------
    USER1                          PARENT1_PK
    PARENT1
    COL2
             2
    
    
    OWNER                          CONSTRAINT_NAME
    ------------------------------ ------------------------------
    TABLE_NAME
    ------------------------------
    COLUMN_NAME
    --------------------------------------------------------------------------------
      POSITION
    ----------
    USER1                          PARENT1_PK
    PARENT1
    COL1
             1
    It seems little ugly to see these data. Why the length of the column is so long? Please tell how to set the length of columns and other settings so that the displayed data should come out in the form of a well managed and beautiful way.
    Like this:
    OWNER     CONSTRAINT_NAME     TABLE_NAME       COLUMN_NAME   POSITION
    -----------     ----------------------------     ------------------        ---------------------    --------------
    USER1        PARENT1_PK              PARENT1             COL2                  2
    USER1        PARENT1_PK              PARENT1             COL1                  1
    I wrote this by hand. How do I get the display to sqlplus.exe?

    Easiest would be to use the command column format and also the linesize option.

    sql>column column_name format a30
    sql>set linesize 300
    

    The order of column would make the display limited to 30 characters only. Also the linesize enlarge the display. Try it and see what it looks like?

    HTH
    Aman...

Maybe you are looking for