Need sql statement to refer back and concatenate

Hello All,
i'm stuck with a situation where I don't even know what term do I have to use to ask about my query.
I had a tabe employees and the columns and the data are
emp_name          emp_id            dept           Manager
john                231                15                Y
galkin               231                15              N
Chris                432                20                N
Jenn                4132                20                Y
Mike                4552                20                 NNow If I run a query I want the results as
emp_name             emp_id             dept             Manager            Employees
john                231                15                Y                2231
Jenn                4132                20                Y                432, 4552Here the extra column Employees should come with comma concatenated values of the corresponding "dept"
ex: Jenn is a manager in dept=20, so under the employees column I want empid of chris and mike with comma concatenated empid's
Can anybody please help me with this query
Thanks in advance.

Here you can find some example of what you are looking for :
http://www.oracle-base.com/articles/misc/StringAggregationTechniques.php
Nicolas.

Similar Messages

  • Need SQL statement to generate a sequence number in the output rows

    Hi folks. I need to create an SQL statement that generates a sequence number column in the output rows (records) such that the first returned row has this column set to 1, second returned row has the column set to 2, etc.
    For example, consider the query:
    SELECT income from employees WHERE income != 20000 ORDER BY income;
    If employees.income contains 60,000, 20,000, 35,000, and 19,000 for respective rows, the output would be this:
    19,000
    35,000
    60,000
    I would like the SQL to also return a sequence number that is computed across the returned rows, resulting in two output columns:
    1 19,000
    2 35,000
    3 60,000
    Is there a simple SQL function that generates the sequence number, in order, and only for the returned rows? Or is there another way?
    I'm stumped. Any help is appreciated! Thanks!
    - Jack Cochrane

    Hi,
    Welcome to the forum!
    Use ROWNUM, like (example):
    Connected to Oracle Database 10g Express Edition Release 10.2.0.1.0
    Connected as hr
    SQL> select rownum, first_name from (select e.first_name from employees e where e.first_name like 'J%' order by e.first_name);
        ROWNUM FIRST_NAME
             1 Jack
             2 James
             3 James
             4 Janette
             5 Jason
             6 Jean
             7 Jennifer
             8 Jennifer
             9 John
            10 John
            11 John
            12 Jonathon
            13 Jose Manuel
            14 Joshua
            15 Julia
            16 Julia
    16 rows selected
    SQL> But rememeber if you want to be sure of unique numbers in certain field is better to use sequences and use seq_name.nextval each time you need.
    Regards,

  • SQL statement to compare dates and return boolean (yes/no)

    I am looking for a SQL statement that can compare 2 dates and return a boolean. 1 (yes) if date 1 is => date2-threshold or 0 (No) if date < date2-threshold
    Ie
    date1=20130603
    threshold=2 days
    date2=sysdate-threshold
    if [ 20130603 > sysdate-$threshold ]
    then
    return 1
    else
    return 0
    fi
    Thanks to all that answer.

    Assumming I want to get "date1" from some other table instead of from
    dual will this syntax be valid
    I was going to invoke another SQLPLUS from my shell script and pass it in
    as a variable but if I can do it on one shot it would be better.
    In addition, if "no rows" are found for date1 from the below query, would
    I need code to handle that
    with xx as
        select TO_DATE(last_date','yyyymmdd') date1, from dba_audit_table where ...;
         select TO_DATE('20130603','yyyymmdd') date1, sysdate date2  from dual;
    Thanks to all who answer
    [/code1]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Need SQL statement for this logic....

    Hi,
    I want a SQL statement for updating the following changed last number .
    Cuurently its:
    SELECT * FROM TEST;
    LAST NUMBER     CHANGED LAST NUMBER
    123518          
    12355265     
    123674659     
    9087648970     
    After updating with the required SQL statement table should look like
    LAST NUMBER     CHANGED LAST NUMBER
    123518          0000123518
    12355265     0012355265
    123674659     0123674659
    9087648970     9087648970
    the last number should be appended with ZEROs and the length of changed last number should be 10 always. Hope its clear.
    Appreciate your help.
    Thanks in advance
    Devender

    select last_number, lpad(to_char(last_number), 10 , '0') FROM test

  • Does not open default site.Needs retry in favorites. Back and forward arrows do not work

    Facebook is the defaulkt address but, when I open Firefox thw scrren is blank (bar are present, though). This happens after last review
    In addition, back and forward arrows do not work (this has always happened since Firefox 4 beta)

    * First to prevent interferences between current and Beta versions, use a specific [[Managing profiles|profile]] for Firefox 4.0 Beta. In your new Beta profile, you can recover all your customizations from your 3.6 profile. See [[Recovering important data from an old profile]].
    * Then, if it is not fixed, see [[Back and forward or other toolbar items are missing]].

  • Where do I find the websites stored as my homepage and how do I select one of them if I need to get just it back and not all of them?

    I have three websites as my homepage, but often once I have worked within one tab for awhile and gone to other sites, I need to get back to the site that is there when my homepage tabs first pop up. I may not have even touched the other two tabs, but if I click on the Home button, I get three new tabs with the three websites that make up my homepage. I then have to delete three tabs to keep just what I want. In IE, the Home button has a pulldown, which allows me to select any one of my homepage websites, and loads that site on the current tab. Can this be done with FF?

    The only way I know to achieve this would be to create three separate bookmarks on the Bookmarks toolbar and click on a one that you want to load in the current tab. You can also try to right-click the Back arrow and click the entry at the bottom of the list to return to the first page.

  • Need SQl Query for Revenue Code and Revenue Amount in Receivables

    Hi,
    I need a SQL Query to develop data set for the following columns:
    Revenue Code,Revenue Code Description,Invoice Amount,Revenue Amount,Original Invoice Number,Original Invoice Date.
    Can i get from ra_cust_trx_line_gl_dist_all and ra_customer_trx_all and ra_customer_trx_lines_all by joining them.But for the columns whcih to take
    i am in dilemma.
    Kindly any help will be needful for me

    Hi,
    I need a SQL Query to develop data set for the following columns:
    Revenue Code,Revenue Code Description,Invoice Amount,Revenue Amount,Original Invoice Number,Original Invoice Date.
    Can i get from ra_cust_trx_line_gl_dist_all and ra_customer_trx_all and ra_customer_trx_lines_all by joining them.But for the columns whcih to take
    i am in dilemma.
    Kindly any help will be needful for me

  • My screen went completly yellow green color took forever to get it to power back on do i need to take the phone back and get a new one?

    Does any know why the screen turned completley yellow when my battery died??? I just got the phone today and wanna know do I need to return the phone I fixed it after I youtubed how to fix it! Will this keep happening??

    Just get it exchanged.
    Basic troubleshooting steps  
    17" 2.2GHz i7 Quad-Core MacBook Pro  8G RAM  750G HD + OCZ Vertex 3 SSD Boot HD 
    Got problems with your Apple iDevice-like iPhone, iPad or iPod touch? Try Troubleshooting 101

  • Need sql statement

    Hi,
    My requirement
    emp_table---table name
    ename empno
    ram 1
    sham 2
    using this select statemnt
    select * from emp_table where empno in (1,1)
    But it shows only one entry that is
    ename empno
    ram 1
    But i wnat to get the output in this format
    ename empno
    ram 1
    ram 1
    becasue i given the empno 1 in two times in the where caluse .. so i need to get the two entries. howto do that.

    Hi,
    Duplicate items count as one item with the IN operator; that is, IN returns TRUE or FALSE, depending on whether the item was found in the list or not. It has no way of telling you how many times the item was found (not that it tries to count them all, anyway).
    The easiest way for you to get the results you want would be to have a table (perhaps a global temporary table, or perhaps just the result set of a sub-query, like "table" t in Karthick's answer) that can have multiple duplicate rows.
    If you have a delimited string (like '1,1,1,1,1') you can generate a result set that has one row for every item in the list. Using the REGEXP_ functions introduced in Oracle 10, this is quite easy.
    Give more specifics about your problem (especially how you are getting the input, whether it is '1', '1,1' or '1,1,1,1,1') to get a more specific answer.

  • I cannot tell you how frustrated I am with Apple right now! I need hel getting my ipad back and so far I am not getting any. What do I do when restore on itunes does not work?

    I am so frustrated with Apple and my ipad2, which I have allways loved so much. While attempting to download and install the latest update, I got stuck on the itunes connect logo. I followed the directions listed here to restore using itunes on my laptop. It would not work and gave me several error messages. Now what do I do? I miss my little computer so much.

    Reading some older threads from 2012 and 2011 it appears the problem was present even then.  Part of the problem was due to people using multiple or different account id's on the various devices.  In my case, I only have one ID and it is the same on all devices yet the iPhone and iPad are still throwing the same error when I try turning on iTunes Match.  This is very frustrating . . . any help out there?  Thanks.

  • I seem to have lost the appointments in my Ipad2 calendar for the months of July, August and September.  I need to refer back to them, and there are only a few appointments reflected. What can I do to recover this info?

    My Ipad2 has recently lost the appointments on my calendar for the past 3 months.  I need that content to refer back to.  Wheredid it go and can I get it back?

    Are they still on your pc's calendar? If so, connect the ipad, go to 'info' scroll down to the calendar and change the setting of 'do not sync items older than....' as far back as you need it

  • I need help in sql statement

    Hello all,
    im working in hr schema
    i need sql statement to answer my question
    i need all employees information
    where average salary = average salary department 50
    sorry i can't speak english very well
    thank's all

    There is no need to do it in two queries. All you need is:
    select  *
      from  (
             select  e.*,
                     avg(case department_id when 50 then salary end) over() dept_50_avg_sal
               from  hr.employees e
      where salary <= dept_50_avg_sal
    EMPLOYEE_ID FIRST_NAME           LAST_NAME                 EMAIL                     PHONE_NUMBER         HIRE_DATE JOB_ID         SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID DEPT_50_AVG_SAL
            198 Donald               OConnell                  DOCONNEL                  650.507.9833         21-JUN-07 SH_CLERK         2600                       124            50      3475.55556
            199 Douglas              Grant                     DGRANT                    650.507.9844         13-JAN-08 SH_CLERK         2600                       124            50      3475.55556
            115 Alexander            Khoo                      AKHOO                     515.127.4562         18-MAY-03 PU_CLERK         3100                       114            30      3475.55556
            116 Shelli               Baida                     SBAIDA                    515.127.4563         24-DEC-05 PU_CLERK         2900                       114            30      3475.55556
            117 Sigal                Tobias                    STOBIAS                   515.127.4564         24-JUL-05 PU_CLERK         2800                       114            30      3475.55556
            118 Guy                  Himuro                    GHIMURO                   515.127.4565         15-NOV-06 PU_CLERK         2600                       114            30      3475.55556
            119 Karen                Colmenares                KCOLMENA                  515.127.4566         10-AUG-07 PU_CLERK         2500                       114            30      3475.55556
            125 Julia                Nayer                     JNAYER                    650.124.1214         16-JUL-05 ST_CLERK         3200                       120            50      3475.55556
            126 Irene                Mikkilineni               IMIKKILI                  650.124.1224         28-SEP-06 ST_CLERK         2700                       120            50      3475.55556
            127 James                Landry                    JLANDRY                   650.124.1334         14-JAN-07 ST_CLERK         2400                       120            50      3475.55556
            128 Steven               Markle                    SMARKLE                   650.124.1434         08-MAR-08 ST_CLERK         2200                       120            50      3475.55556
    EMPLOYEE_ID FIRST_NAME           LAST_NAME                 EMAIL                     PHONE_NUMBER         HIRE_DATE JOB_ID         SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID DEPT_50_AVG_SAL
            129 Laura                Bissot                    LBISSOT                   650.124.5234         20-AUG-05 ST_CLERK         3300                       121            50      3475.55556
            130 Mozhe                Atkinson                  MATKINSO                  650.124.6234         30-OCT-05 ST_CLERK         2800                       121            50      3475.55556
            131 James                Marlow                    JAMRLOW                   650.124.7234         16-FEB-05 ST_CLERK         2500                       121            50      3475.55556
            132 TJ                   Olson                     TJOLSON                   650.124.8234         10-APR-07 ST_CLERK         2100                       121            50      3475.55556
            133 Jason                Mallin                    JMALLIN                   650.127.1934         14-JUN-04 ST_CLERK         3300                       122            50      3475.55556
            134 Michael              Rogers                    MROGERS                   650.127.1834         26-AUG-06 ST_CLERK         2900                       122            50      3475.55556
            135 Ki                   Gee                       KGEE                      650.127.1734         12-DEC-07 ST_CLERK         2400                       122            50      3475.55556
            136 Hazel                Philtanker                HPHILTAN                  650.127.1634         06-FEB-08 ST_CLERK         2200                       122            50      3475.55556
            138 Stephen              Stiles                    SSTILES                   650.121.2034         26-OCT-05 ST_CLERK         3200                       123            50      3475.55556
            139 John                 Seo                       JSEO                      650.121.2019         12-FEB-06 ST_CLERK         2700                       123            50      3475.55556
            140 Joshua               Patel                     JPATEL                    650.121.1834         06-APR-06 ST_CLERK         2500                       123            50      3475.55556
    EMPLOYEE_ID FIRST_NAME           LAST_NAME                 EMAIL                     PHONE_NUMBER         HIRE_DATE JOB_ID         SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID DEPT_50_AVG_SAL
            142 Curtis               Davies                    CDAVIES                   650.121.2994         29-JAN-05 ST_CLERK         3100                       124            50      3475.55556
            143 Randall              Matos                     RMATOS                    650.121.2874         15-MAR-06 ST_CLERK         2600                       124            50      3475.55556
            144 Peter                Vargas                    PVARGAS                   650.121.2004         09-JUL-06 ST_CLERK         2500                       124            50      3475.55556
            180 Winston              Taylor                    WTAYLOR                   650.507.9876         24-JAN-06 SH_CLERK         3200                       120            50      3475.55556
            181 Jean                 Fleaur                    JFLEAUR                   650.507.9877         23-FEB-06 SH_CLERK         3100                       120            50      3475.55556
            182 Martha               Sullivan                  MSULLIVA                  650.507.9878         21-JUN-07 SH_CLERK         2500                       120            50      3475.55556
            183 Girard               Geoni                     GGEONI                    650.507.9879         03-FEB-08 SH_CLERK         2800                       120            50      3475.55556
            186 Julia                Dellinger                 JDELLING                  650.509.3876         24-JUN-06 SH_CLERK         3400                       121            50      3475.55556
            187 Anthony              Cabrio                    ACABRIO                   650.509.4876         07-FEB-07 SH_CLERK         3000                       121            50      3475.55556
            190 Timothy              Gates                     TGATES                    650.505.3876         11-JUL-06 SH_CLERK         2900                       122            50      3475.55556
            191 Randall              Perkins                   RPERKINS                  650.505.4876         19-DEC-07 SH_CLERK         2500                       122            50      3475.55556
    EMPLOYEE_ID FIRST_NAME           LAST_NAME                 EMAIL                     PHONE_NUMBER         HIRE_DATE JOB_ID         SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID DEPT_50_AVG_SAL
            194 Samuel               McCain                    SMCCAIN                   650.501.3876         01-JUL-06 SH_CLERK         3200                       123            50      3475.55556
            195 Vance                Jones                     VJONES                    650.501.4876         17-MAR-07 SH_CLERK         2800                       123            50      3475.55556
            196 Alana                Walsh                     AWALSH                    650.507.9811         24-APR-06 SH_CLERK         3100                       124            50      3475.55556
            197 Kevin                Feeney                    KFEENEY                   650.507.9822         23-MAY-06 SH_CLERK         3000                       124            50      3475.55556
    37 rows selected.
    SQL> SY.

  • Preparing Dynamic SQL statement for inserting in Pro*C

    Hi Friends,
    From quite some time i am struggling writing Dynamic SQL statement for dynamic insert and update in Pro*C.
    Can somebody go through my code and suggest me the rigth way of doing.
    Right now it throws an error saying " Error while updating ORA-00904: invalid column name "
    Please help me.
    Girish.
    int main()
    EXEC SQL BEGIN DECLARE SECTION;
    char *uid ="scott/tiger";
    static char sqlstmt[129];
    struct /* DEPT record */
    int dept_num;
    char dept_name[15];
    char location[14];
    } dept_rec;
    EXEC SQL END DECLARE SECTION;
    EXEC SQL WHENEVER SQLERROR DO sql_error();
    EXEC SQL CONNECT :uid;
    dept_rec.dept_num = 50;
    strcpy(dept_rec.dept_name,"ADMIN");
    strcpy(dept_rec.location,"IN");
    strcpy(sqlstmt,"UPDATE dept set DNAME = dept_rec.dept_name where DEPTNO = dept_rec.dept_num");
    EXEC SQL EXECUTE IMMEDIATE:sqlstmt;
    EXEC SQL COMMIT;
    exit(0);
    void sql_error()
    printf("\nError while updating %s",sqlca.sqlerrm.sqlerrmc);
    EXEC SQL ROLLBACK;
    }

    A bit rusty here but this is how I see it.
    Think of it this way ..
    all Oracle is going to see is:
    UPDATE dept set DNAME = dept_rec.dept_name where DEPTNO = dept_rec.dept_num
    Its NOT going to know what dept_rec.dept_name is or dept_rec.dept_num is ..
    it doesnt go back and fill in those values.
    You need something like
    strcpy(sqlstmt,"UPDATE dept set DNAME = \"");
    strcat(sqlstmt,dept_rec.dept_name);
    strcat(sqlstmt,"\" where DEPTNO = ");
    strcat(sqlstmt,dept_rec.dept_num);
    printf(sqlsmt); # Just to be sure the update statement look right during testing.

  • Batching SQL Statements - Return Long Raw

    I have been using the .NET Framework Data Provider for Oracle and have run into the following limitation.
    I need to batch several SQL statements at one time and return a datareader (or another object) with those values. The .NET Framework Data Provider for Oracle from Microsoft doesn't support batching up SQL statements in this manner. Additionally, the values I need to return include a LONGRAW field. From the research I've done PL-SQL can only return 32KB of data for a LONGRAW field if we were to try a different approach like using a stored procedure and a REF CURSOR.
    My questions are:
    1.) Will the ODP support batched SQL statements? For example, can I issue the following SQL statements and get a datareader?
    Select field1, field2 from table1;
    Select feild1, field2 from table2;
    Select feild1, field2 from table3;
    2.) Is there the 32 KB limitation on LONGRAW fields and PL-SQL in Oracle 8.1.7.2.0?
    3.) Any suggestions?

    1. With ODP.NET, you can batch your SQL statements using anonymous PL/SQL block. For example,
    begin
    open :1 for select * from emp;
    open :2 for select * from dept;
    open :3 for select col1 from test;
    end;
    You need to create three parameters with type OracleDbType.RefCursor and bind them as Output parameters. If you execute the above statement using OracleCommand's ExecuteNonQuery method, you would get three REF Cursors in the Value property of OracleParameter object. You can create an OracleDataReader or populate the Data Set using any or all of these REF Cursors in any order. If you execute the above statement using OracleCommand's ExecuteReader method, you would get OracleDataReader for the first REF Cursor and you would be able to get the OracleDataReader for other REF Cursors using OracleDataReader's NextResult method. Note that ODP.NET does not impose a limitation of closing the first OracleDataReader before opening the second one.
    2. Long/Long Raw 32K limitation is imposed by PL/SQL and one way to bypass that limitation is to use LOBs instead. Having LOBs in the stored procedure or anonymous PL/SQL blocks allow you to access data upto 4GB.

  • Batch executing SQL Statements stored in a file in SAP DB

    hi,
    I am using SAP DB as database in my j2ee application. As a part of the application purpose, i need to insert a large no. of records in to the database directly. I have created the SQL file which contains the insert statements for the records
    Now i need to execute this file sothat the insert statement which are inside the file get executed. I am using SQL Studio to access to the Database.
    I would like to know whether any options are available in SQL Studio to for executing a SQL File.
    Kindly help
    Best regards,
    Sudheesh...

    Hi,
    I believe that the solution to your problem lies in creating sql studio objects.Please refer to the link below.Select the link "sql dialog" on the page.
    The following options are available for sql dialog.
    The following options are available in the SQL dialog:
    ·        Creating and executing SQL statements
    ·        Setting parameters for SQL statements
    ·        Importing and exporting SQL statements
    Select the "Importing and exporting sql statements" link on this page to know more about it.This will tell you how to import sql statements from ascii files.
    Basically,what you need to do is From the context menu for the SQL dialog, choose Import File or Export File.
    The link I have provided,gives a lot of other information as well.
    http://help.sap.com/saphelp_nw04s/helpdata/en/ee/1c5bdfeba711d4aa2800a0c9430730/frameset.htm
    Hope this helps.
    Regards,
    Harish
    (Please award points for helpful answers)
    Message was edited by: HARISH SUBRAMANIAN

Maybe you are looking for

  • Broken xperia z 2 screen while cleaning

    I bought a xperia z 2 just a week ago and now the touch screen cracked while I was cleaning the glass. How is that even possible? It cracked as if I poured hot water in a layer of ice. Now that I went to claim the warranty to the mobile company. they

  • RE: PRICING

    Hi I have 2 questions. One of my condition type validity period will be ended after 3days. And I have created one sales order today but i will be billing it after 10 days.So my question is will this particular condition type will be reflected  in my

  • IP address Pool in ACS 5.1

    Hi, Does anyone knows if it is possible to configure IP Pools on ACS 5.1 so that we can assign those addresses to VPN users using the Policy Elements/Access Policies? I managed to configure static addresses for single users, but not a pool of address

  • Putting Album Art On By Album

    I'm putting the album art on the cd's i loaded myself and wanted to know if there was a way to do it by album instead of song-by-song. I know how to get the art and put it on for each song but it's so time comsuming. Is it possible to load it by albu

  • Converting between DefaultListModel to DefaultComboBoxModel

    Hi I was wondering is there any easy way to convert a DefaultListModel to a DefaultComboBoxModel. Or perhaps I can move all the elements from the ListModel to the ComboBoxModel. Any help would be appreciated