Merge multiple rows to get single row result

Hi,
Below is the sample data from my table USERINFO-
personid userid username orgid
1234 1235 TOM 1
2345 2346 HARRY 1
1111 2222 BOND     2
3333 4444 BERY 2
Now I want a query which can give me the following result-
personid userid username personid userid username orgid
1234 1235 TOM 2345 2346 HARRY     1
1111 2222 BOND     3333 4444 BERY 2
i.e., two records belonging to the same orgid should be merged into a single row resulset.
Please let me know the SQL query to get the desired result.
Thanks

SQL> select * from test_otn;
  PERSONID     USERID USERNAME                  ORGID
      1234       1235 TOM                           1
      2345       2346 HARRY                         1
      1111       2222 BOND                          2
      3333       4444 BERY                          2
SQL> select max(decode(rn, 1, personid, null)) person_id1,
  2        max(decode(rn, 2, personid, null)) person_id2,
  3        max(decode(rn, 1, userid, null)) user_id1,
  4        max(decode(rn, 2, userid, null)) user_id2,
  5        max(decode(rn, 1, username, null)) username1,
  6        max(decode(rn, 2, username, null)) username2,
  7        orgid
  8  from
  9  (select row_number() over (partition by orgid order by orgid) rn,
10         personid, userid, username, orgid from test_otn)
11  group by orgid
12  /
PERSON_ID1 PERSON_ID2   USER_ID1   USER_ID2 USERNAME1            USERNAME2                 ORGID
      1234       2345       1235       2346 TOM                  HARRY                         1
      1111       3333       2222       4444 BOND                 BERY                          2
Thx,
SriDHAR

Similar Messages

  • Multiple rows in a single row.

    I want to know how can I store the values of multiple rowe in a single row.for an example..
    machine name    manchine no  frequency   month
    Lathe                  MOO1          yearly         jan
    Lathe                  MOO1          halfyearly   feb
    Lathe                  MOO1         weekly       march and so on
    I want this in a single row..
    like                        jan       feb             march
    Lathe       M001   yearly     halfyearly   weekly.
    and in a single row I want this as per the month specified .
    In my report I have 12 months distribution for each machine.

    Taruna,
    Just make sure understand the scenario correctly. Would you like to store the row in DB like this:
    Lathe MOO1 yearly jan,feb,mar
    then you expect to show in the report like this:
    Lathe MOO1 yearly jan
    Lathe MOO1 yearly feb
    Lathe MOO1 yearly mar
    Yes, you can do it this way, but somehow break the 1st principle of DB schema design - Atomic
    Of course, you need to convert jan,feb,mar into list and display for each row.
    string monthStr = "jan,feb,mar";
    string [] months = monthStr.Split(",");
    Kind Regards
    -Yatsea

  • Merging two rows into a single row

    Hi ,
    I wish to merge few columns of tow rows into a single row.
    if i use union it gives two rows as o/p.
    What is the exact sql statement for that?
    Thanks

    Hi Sridhar,
    This is my code for merging and i used union.
    Suggest me good solution.
    CREATE OR REPLACE VIEW INSPECTINT.INSPECT_LOC_TRACKING_RPT_VIEW AS
    SELECT
    VEN_COMPANY_NAME VEN_COMPANY_NAME,
    VEN_COMPANY_NAME_2 VEN_COMPANY_NAME_2,
    VEN_CONTACT_FIRST_NAME VEN_CONTACT_FIRST_NAME,
    VEN_CONTACT_MIDDLE_NAME VEN_CONTACT_MIDDLE_NAME,
    VEN_CONTACT_LAST_NAME VEN_CONTACT_LAST_NAME,
    VEN_ADDRESS_LINE_1 VEN_ADDRESS_LINE_1,
    VEN_ADDRESS_LINE_2 VEN_ADDRESS_LINE_2,
    VEN_CITY VEN_CITY,
    VEN_CNT_COUNTY_CODE VEN_CNT_COUNTY_CODE,
    VEN_STC_STATE_CODE VEN_STC_STATE_CODE,
    VEN_ZIP_CODE VEN_ZIP_CODE,
    VEN_PHONE_NO_1 VEN_PHONE_NO_1,
    VEN_PHONE_EXTN_1 VEN_PHONE_EXTN_1,
    VEN_PHONE_NO_2 VEN_PHONE_NO_2,
    VEN_PHONE_EXTN_2 VEN_PHONE_EXTN_2,
    VEN_FAX_NO_1 VEN_FAX_NO_1,
    VEN_VENDOR_NO VEN_VENDOR_NO,
    VEN_APV_AP_VENDOR_ID VEN_APV_AP_VENDOR_ID,
    VEN_EMAIL_ADDRESS VEN_EMAIL_ADDRESS,
    --all these should be null
    to_number(NULL) PHY_LCN_PARAMETER_ID,
    to_char(NULL) PHY_LCN_CURRENT_ADDRESS_IND,
    to_char(NULL) PHY_LCN_STATUS_CODE,
    to_char(NULL) PHY_LCN_LTY_LOCATION_TYPE,
    to_char(NULL) PHY_LCN_ADT_ADDRESS_TYPE,
    to_char(NULL) PHY_LCN_HOUSE_NO,
    to_char(NULL) PHY_LCN_ADDRESS_LINE_1,
    to_char(NULL) PHY_LCN_ADDRESS_LINE_2,
    to_char(NULL) PHY_LCN_CITY,
    to_char(NULL) PHY_LCN_STC_STATE_CODE,
    to_char(NULL) PHY_LCN_ZIP_CODE,
    to_char(NULL) PHY_LCN_CNT_COUNTY_CODE,
    to_date(NULL) PHY_END_DATE,
    to_number(NULL) PHY_LCN_VEN_VENDOR_ID_GTA,
    to_char(NULL) PHY_LCN_SUB_LOCATION_GTA,
    to_char(NULL) PHY_LCN_DIRECTION_GTA,
    ---all these should be null
    to_char(NULL) LOW_LCN_PARAMETER_ID,
    to_char(NULL) LOW_LCN_CURRENT_ADDRESS_IND,
    to_char(NULL) LOW_LCN_STATUS_CODE,
    to_char(NULL) LOW_LCN_LTY_LOCATION_TYPE,
    to_char(NULL) LOW_LCN_ADT_ADDRESS_TYPE,
    to_char(NULL) LOW_LCN_HOUSE_NO,
    to_char(NULL) LOW_LCN_ADDRESS_LINE_1,
    to_char(NULL) LOW_LCN_ADDRESS_LINE_2,
    to_char(NULL) LOW_LCN_CITY,
    to_char(NULL) LOW_LCN_STC_STATE_CODE,
    to_char(NULL) LOW_LCN_ZIP_CODE,
    to_char(NULL) LOW_LCN_CNT_COUNTY_CODE,
    to_char(NULL) LOW_LCN_LANDLORD,
    to_number(NULL) LOW_LCN_LANDLORD_PHONE,
    to_date(NULL) LOW_END_DATE,
    to_char(NULL) LOW_LCN_SUB_LOCATION_GTA,
    to_char(NULL) LOW_LCN_DIRECTION_GTA
    FROM LOCATIONS LOC , VENDORS VEN
    WHERE LOC.LCN_VEN_VENDOR_ID_GTA IS NOT NULL
    AND LOC.LCN_VEN_VENDOR_ID_GTA = VEN_VENDOR_ID
    AND LOC.LCN_LTY_LOCATION_TYPE ='AS'
    UNION ALL
    SELECT
    to_char(NULL) VEN_COMPANY_NAME,
    to_char(NULL) VEN_COMPANY_NAME_2,
    to_char(NULL) VEN_CONTACT_FIRST_NAME,
    to_char(NULL) VEN_CONTACT_MIDDLE_NAME,
    to_char(NULL) VEN_CONTACT_LAST_NAME,
    to_char(NULL) VEN_ADDRESS_LINE_1,
    to_char(NULL) VEN_ADDRESS_LINE_2,
    to_char(NULL) VEN_CITY,
    to_char(NULL) VEN_CNT_COUNTY_CODE,
    to_char(NULL) VEN_STC_STATE_CODE,
    to_char(NULL) VEN_ZIP_CODE,
    to_number(NULL) VEN_PHONE_NO_1,
    to_number(NULL) VEN_PHONE_EXTN_1,
    to_number(NULL) VEN_PHONE_NO_2,
    to_number(NULL) VEN_PHONE_EXTN_2,
    to_number(NULL) VEN_FAX_NO_1,
    to_char(NULL) VEN_VENDOR_NO,
    to_char(NULL) VEN_APV_AP_VENDOR_ID,
    to_char(NULL) VEN_EMAIL_ADDRESS,
    decode(lcn_adt_address_type,'P',to_number(LCN_PARAMETER_ID),to_number(NULL)) PHY_LCN_PARAMETER_ID,
    decode(lcn_adt_address_type,'P',LCN_CURRENT_ADDRESS_IND,to_char(NULL)) PHY_LCN_CURRENT_ADDRESS_IND,
    decode(lcn_adt_address_type,'P',LCN_STATUS_CODE,to_char(NULL)) PHY_LCN_STATUS_CODE,
    decode(lcn_adt_address_type,'P',LCN_STATUS_CODE,to_char(NULL)) PHY_LCN_LTY_LOCATION_TYPE,
    decode(lcn_adt_address_type,'P',LCN_ADT_ADDRESS_TYPE,to_char(NULL)) PHY_LCN_ADT_ADDRESS_TYPE,
    decode(lcn_adt_address_type,'P',LCN_HOUSE_NO,to_char(NULL)) PHY_LCN_HOUSE_NO,
    decode(lcn_adt_address_type,'P',LCN_ADDRESS_LINE_1,to_char(NULL)) PHY_LCN_ADDRESS_LINE_1,
    decode(lcn_adt_address_type,'P',LCN_ADDRESS_LINE_2,to_char(NULL)) PHY_LCN_ADDRESS_LINE_2,
    decode(lcn_adt_address_type,'P',LCN_CITY,to_char(NULL)) PHY_LCN_CITY,
    decode(lcn_adt_address_type,'P',LCN_STC_STATE_CODE,to_char(NULL)) PHY_LCN_STC_STATE_CODE,
    decode(lcn_adt_address_type,'P',LCN_ZIP_CODE,to_char(NULL)) PHY_LCN_ZIP_CODE,
    decode(lcn_adt_address_type,'P',LCN_CNT_COUNTY_CODE,to_char(NULL)) PHY_LCN_CNT_COUNTY_CODE,
    decode(lcn_adt_address_type,'P',END_DATE,to_char(NULL)) PHY_END_DATE,
    decode(lcn_adt_address_type,'P',LCN_VEN_VENDOR_ID_GTA,to_char(NULL)) PHY_LCN_VEN_VENDOR_ID_GTA,
    decode(lcn_adt_address_type,'P',LCN_SUB_LOCATION_GTA,to_char(NULL)) PHY_LCN_SUB_LOCATION_GTA,
    decode(lcn_adt_address_type,'P',LCN_DIRECTION_GTA,to_char(NULL)) PHY_LCN_DIRECTION_GTA,
    decode(LCN_ADT_ADDRESS_TYPE,'D',LCN_PARAMETER_ID,to_char(NULL)) LOW_LCN_PARAMETER_ID,
    decode(LCN_ADT_ADDRESS_TYPE,'D',LCN_CURRENT_ADDRESS_IND,to_char(NULL)) LOW_LCN_CURRENT_ADDRESS_IND,
    decode(LCN_ADT_ADDRESS_TYPE,'D',LCN_STATUS_CODE,to_char(NULL)) LOW_LCN_STATUS_CODE,
    decode(LCN_ADT_ADDRESS_TYPE,'D',LCN_LTY_LOCATION_TYPE,to_char(NULL)) LOW_LCN_LTY_LOCATION_TYPE,
    decode(LCN_ADT_ADDRESS_TYPE,'D',LCN_ADT_ADDRESS_TYPE,to_char(NULL)) LOW_LCN_ADT_ADDRESS_TYPE,
    decode(LCN_ADT_ADDRESS_TYPE,'D',LCN_HOUSE_NO,to_char(NULL)) LOW_LCN_HOUSE_NO,
    decode(LCN_ADT_ADDRESS_TYPE,'D',LCN_ADDRESS_LINE_1,to_char(NULL)) LOW_LCN_ADDRESS_LINE_1,
    decode(LCN_ADT_ADDRESS_TYPE,'D',LCN_ADDRESS_LINE_2,to_char(NULL)) LOW_LCN_ADDRESS_LINE_2,
    decode(LCN_ADT_ADDRESS_TYPE,'D',LCN_CITY,to_char(NULL)) LOW_LCN_CITY,
    decode(LCN_ADT_ADDRESS_TYPE,'D',LCN_STC_STATE_CODE,to_char(NULL)) LOW_LCN_STC_STATE_CODE,
    decode(LCN_ADT_ADDRESS_TYPE,'D',LCN_ZIP_CODE,to_char(NULL)) LOW_LCN_ZIP_CODE,
    decode(LCN_ADT_ADDRESS_TYPE,'D',LCN_CNT_COUNTY_CODE,to_char(NULL)) LOW_LCN_CNT_COUNTY_CODE,
    decode(LCN_ADT_ADDRESS_TYPE,'D',LCN_LANDLORD,to_char(NULL)) LOW_LCN_LANDLORD,
    decode(LCN_ADT_ADDRESS_TYPE,'D',LCN_LANDLORD_PHONE,to_char(NULL)) LOW_LCN_LANDLORD_PHONE,
    decode(LCN_ADT_ADDRESS_TYPE,'D',END_DATE,to_char(NULL)) LOW_END_DATE,
    decode(LCN_ADT_ADDRESS_TYPE,'D',LCN_SUB_LOCATION_GTA,to_char(NULL)) LOW_LCN_SUB_LOCATION_GTA,
    decode(LCN_ADT_ADDRESS_TYPE,'D',LCN_DIRECTION_GTA,to_char(NULL)) LOW_LCN_DIRECTION_GTA
    FROM LOCATIONS LOC
    WHERE (LCN_LTY_LOCATION_TYPE ='AS' OR LCN_ADT_ADDRESS_TYPE='D')
    AND LCN_CURRENT_ADDRESS_IND ='Y'
    thanks

  • Mutiple Rows from a Single Row using SQL

    How can i get Multiple rows from a single row using sql ?
    Example : one row contains the complete address separated by delimiter say comma (,) as address1,address2,city,state,zip,country
    I want to split this row and get the output in multiple rows as address1 address2 city state zip country using sql query.
    Thanks,

    Hi,
    The solution above assumes that the |-delimited entries always contain at least one character. If you have a string like
    1 Elm Street|||Sioux City|IA||it will think 'Siuox City' is address2.
    If you have empty entries, like that, then you need something a little more complicated:
    INSERT INTO table2
    (       address1
    ,     address2
    ,     address3
    ,     city
    ,     state
    ,     postal
    ,     country
    SELECT     SUBSTR (REGEXP_SUBSTR ('|' || txt, '\|[^|]*', 1, 1), 2)     -- address1
    ,     SUBSTR (REGEXP_SUBSTR ('|' || txt, '\|[^|]*', 1, 2), 2)     -- address2
    ,     SUBSTR (REGEXP_SUBSTR ('|' || txt, '\|[^|]*', 1, 3), 2)     -- address3
    ,     SUBSTR (REGEXP_SUBSTR ('|' || txt, '\|[^|]*', 1, 4), 2)     -- city
    ,     SUBSTR (REGEXP_SUBSTR ('|' || txt, '\|[^|]*', 1, 5), 2)     -- state
    ,     SUBSTR (REGEXP_SUBSTR ('|' || txt, '\|[^|]*', 1, 6), 2)     -- postal
    ,     SUBSTR (REGEXP_SUBSTR ('|' || txt, '\|[^|]*', 1, 7), 2)     -- country
    FROM     table1
    ;

  • __Is there a way to 'merge' multiple curves into a single curve?

    __Is there a way to 'merge' multiple curves into a single curve?
    By this I mean I have file with 2-12 curve layers - I wanted to 'merge' the curves so that I can end up with a single curve with the attributes of many. Maybe is there a script that would do this?

    I don't mean to be critical, but how do you get to a situation where you have 12 successive Curves layers?
    The advantage to a Curves layer is that you can adjust and re-adjust it to your heart's content.
    If you're habitually adding new Curves layers one over the other, maybe you should re-evaluate your process of working...  Perhaps the way you're thinking you should just work at a high bit depth and do repeated Curves operations on the pixels?  Or put some time into retraining yourself to not add a new Curves layer but to manipulate the one that's already there.  There are some nice new enhancements (e.g., the "finger" subtool that allows you to choose a spot in the image and manipulate that part of the curve).
    Again, I'm not trying to criticize you, just looking to see if maybe there's a way to avoid getting to the point where you need to combine Curves in the first place, since there's no direct "Merge Curves" capability, outside of just stamping a set of image and adjustment layers into pixels.  For completeness I suppose I should mention how to do that...  You can Stamp any combination of visible layers into a single layer of pixels (effectively combining all the Curves layers et. al.) by pressing Control - Shift - Alt - E.
    -Noel

  • Need help converting multipe rows in a single row

    I want to convert multiple rows into a single row. Oracle version is 10.2
    SQL> with abc
      2  as
      3  (select 1 a, 2 b, 3 c from dual union
      4  select 4, 5, 6 from dual)
      5  select * from abc;
             A          B          C
             1          2          3
             4          5          6I want the output as
    A      B       C
    1,4   2,5    3,6Thanks,
    Gangadhar
    Edited by: GR on Feb 6, 2012 9:35 PM

    GR wrote:
    I want to convert multiple rows into a single row. Oracle version is 10.2
    SQL> with abc
    2  as
    3  (select 1 a, 2 b, 3 c from dual union
    4  select 4, 5, 6 from dual)
    5  select * from abc;
    A          B          C
    1          2          3
    4          5          6I want the output as
    A      B       C
    1,4   2,5    3,6
    You haven't specified if there's a particular order to the data, so I've assumed one...
    SQL> ed
    Wrote file afiedt.buf
      1  with t as (select 1 a, 2 b, 3 c from dual union
      2             select 4, 5, 6 from dual)
      3  --
      4  -- end of test data
      5  --
      6  select trim(',' from sys_connect_by_path(a,',')) as a
      7        ,trim(',' from sys_connect_by_path(b,',')) as b
      8        ,trim(',' from sys_connect_by_path(c,',')) as c
      9  from (select a,b,c,row_number() over (order by a) as rn from t)
    10  where connect_by_isleaf = 1
    11  connect by rn = prior rn+1
    12* start with rn = 1
    SQL> /
    A          B          C
    1,4        2,5        3,6
    SQL>

  • Merge multiple pdf files into single pdf

    How to merge multiple pdf files into single pdf file through any programmatic languages? Kindly share with me.
    Thanks

    Easy PDF
    http://www.macupdate.com/app/mac/38090/easy-pdf
    How To: Combine multiple PDFs in Preview
    http://macenstein.com/default/2011/12/how-to-combine-multiple-pdfs-in-preview/
    How to merge pdf files in OSX
    http://macintoshhowto.com/leopard/how-to-merge-pdf-files-with-preview-in-leopard .html
    How to Combine Multiple PDFs Using Preview
    http://www.macobserver.com/tmo/article/how_to_combine_multiple_pdfs_using_previe w/

  • Merging Multiple Rows into a single Row

    I've read a number of posts with no real good answers or answers that might be good for tables with 3 columns of data. I have a table with 33 columns that will all need to be combined. A little history. Apparently in production the Primary Key Constraint
    was dropped which allowed some duplicate data into the table. Now they want me to squish the records together to fix it.
    Sorry I couldn't include the screen shot of the data, MSDN says my account isn't verified...
    My requirements when I'm putting them together, CERElibilityID is a unique column. This is a sticky problem because in the related tables it is only one of the parent records gets child records related to it.
     I just want to keep the one that has the child records in CERPrepActivity table. If there are no child records then the rule will be like all the other records with data. 
    If a  field is null and another record has data we take the record that has data.
    If multiple records have data we take the record that has the highest "ModifiedOn" timestamp column value.
    I feel like I'm asking a lot, but I'm in a bit of a bind and I've spent the morning Googling and have come up with nothing 
    Thank  you for any help the community can provide and the more specific you can be the better. I'm not a DBA or SQL guru by any stretch so I'm way out of my element.
    Thanks

    Using the systables, you can get information about your table. I put these together:
    SELECT '
    LEFT OUTER JOIN #CEREligibility ['+c.name+']
    ON s.caseID = ['+c.name+'].caseID
    AND s.modifiedOn = ['+c.name+'].modifiedOn
    AND ['+c.name+'].['+c.name+'] = (SELECT TOP 1 ['+c.name+'] FROM #CEREligibility WHERE caseID = s.caseID AND ['+c.name+'] IS NOT NULL ORDER BY ModifiedOn)
    AND ['+c.name+'].['+c.name+'] IS NOT NULL'
    FROM tempdb.sys.objects o
    INNER JOIN tempdb.sys.columns c
    ON o.object_id = c.object_id
    AND o.name LIKE '#CEREligibility%'
    SELECT '['+c.name+'].['+c.name+'] AS ['+c.name+'], '
    FROM tempdb.sys.objects o
    INNER JOIN tempdb.sys.columns c
    ON o.object_id = c.object_id
    AND o.name LIKE '#CEREligibility%'
    On my test system I created your table as a temp table named #CEREligibility.
    The first of these two queries generates LEFT OUT JOIN SQL for a self join. Because we're using the columns systable, a LOJ for each column is generated.
    The second, produces a select list.
    Putting the two together like so, and adding a FROM and GROUP BY gives us:
    SELECT
    MAX([CEREligibilityId].[CEREligibilityId]) AS [CEREligibilityId], s.[CaseId], MAX([M2Eligibility].[M2Eligibility]) AS [M2Eligibility], MAX([CDREligibility].[CDREligibility]) AS [CDREligibility], MAX([M2Comments].[M2Comments]) AS [M2Comments], MAX([M2CommentsRtf].[M2CommentsRtf]) AS [M2CommentsRtf], MAX([CDRComments].[CDRComments]) AS [CDRComments], MAX([CDRCommentsRtf].[CDRCommentsRtf]) AS [CDRCommentsRtf], MAX([RIAWA].[RIAWA]) AS [RIAWA], MAX([RIAWADate].[RIAWADate]) AS [RIAWADate], MAX([EducationAndTraining].[EducationAndTraining]) AS [EducationAndTraining], MAX([EducationAndTrainingDate].[EducationAndTrainingDate]) AS [EducationAndTrainingDate], MAX([Internship].[Internship]) AS [Internship], MAX([InternshipDate].[InternshipDate]) AS [InternshipDate], MAX([Apprenticeship].[Apprenticeship]) AS [Apprenticeship], MAX([ApprenticeshipDate].[ApprenticeshipDate]) AS [ApprenticeshipDate], MAX([Entrepreneurship].[Entrepreneurship]) AS [Entrepreneurship], MAX([EntrepreneurshipDate].[EntrepreneurshipDate]) AS [EntrepreneurshipDate], MAX([EmploymentPrep].[EmploymentPrep]) AS [EmploymentPrep], MAX([EmploymentPrepDate].[EmploymentPrepDate]) AS [EmploymentPrepDate], MAX([OTPrep].[OTPrep]) AS [OTPrep], MAX([OTPrepDate].[OTPrepDate]) AS [OTPrepDate], MAX([ExitInterview].[ExitInterview]) AS [ExitInterview], MAX([ExitInterviewDate].[ExitInterviewDate]) AS [ExitInterviewDate], MAX([CreatedOn].[CreatedOn]) AS [CreatedOn], MAX([CreatedBy].[CreatedBy]) AS [CreatedBy], MAX([ModifiedOn].[ModifiedOn]) AS [ModifiedOn], MAX([ModifiedBy].[ModifiedBy]) AS [ModifiedBy], MAX([BCPermInEligibility].[BCPermInEligibility]) AS [BCPermInEligibility], MAX([CCPermInEligibility].[CCPermInEligibility]) AS [CCPermInEligibility], MAX([M2EligibilityDate].[M2EligibilityDate]) AS [M2EligibilityDate], MAX([CDREligibilityDate].[CDREligibilityDate]) AS [CDREligibilityDate], MAX([ExitSeparationCode].[ExitSeparationCode]) AS [ExitSeparationCode], MAX([ExitSeparationSubCode].[ExitSeparationSubCode]) AS [ExitSeparationSubCode]
    FROM #CEREligibility s
    LEFT OUTER JOIN #CEREligibility [CEREligibilityId]
    ON s.caseID = [CEREligibilityId].caseID
    AND s.modifiedOn = [CEREligibilityId].modifiedOn
    AND [CEREligibilityId].[CEREligibilityId] = (SELECT TOP 1 [CEREligibilityId] FROM #CEREligibility WHERE caseID = s.caseID AND [CEREligibilityId] IS NOT NULL ORDER BY ModifiedOn)
    AND [CEREligibilityId].[CEREligibilityId] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [CaseId]
    ON s.caseID = [CaseId].caseID
    AND s.modifiedOn = [CaseId].modifiedOn
    AND [CaseId].[CaseId] = (SELECT TOP 1 [CaseId] FROM #CEREligibility WHERE caseID = s.caseID AND [CaseId] IS NOT NULL ORDER BY ModifiedOn)
    AND [CaseId].[CaseId] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [M2Eligibility]
    ON s.caseID = [M2Eligibility].caseID
    AND s.modifiedOn = [M2Eligibility].modifiedOn
    AND [M2Eligibility].[M2Eligibility] = (SELECT TOP 1 [M2Eligibility] FROM #CEREligibility WHERE caseID = s.caseID AND [M2Eligibility] IS NOT NULL ORDER BY ModifiedOn)
    AND [M2Eligibility].[M2Eligibility] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [CDREligibility]
    ON s.caseID = [CDREligibility].caseID
    AND s.modifiedOn = [CDREligibility].modifiedOn
    AND [CDREligibility].[CDREligibility] = (SELECT TOP 1 [CDREligibility] FROM #CEREligibility WHERE caseID = s.caseID AND [CDREligibility] IS NOT NULL ORDER BY ModifiedOn)
    AND [CDREligibility].[CDREligibility] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [M2Comments]
    ON s.caseID = [M2Comments].caseID
    AND s.modifiedOn = [M2Comments].modifiedOn
    AND [M2Comments].[M2Comments] = (SELECT TOP 1 [M2Comments] FROM #CEREligibility WHERE caseID = s.caseID AND [M2Comments] IS NOT NULL ORDER BY ModifiedOn)
    AND [M2Comments].[M2Comments] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [M2CommentsRtf]
    ON s.caseID = [M2CommentsRtf].caseID
    AND s.modifiedOn = [M2CommentsRtf].modifiedOn
    AND [M2CommentsRtf].[M2CommentsRtf] = (SELECT TOP 1 [M2CommentsRtf] FROM #CEREligibility WHERE caseID = s.caseID AND [M2CommentsRtf] IS NOT NULL ORDER BY ModifiedOn)
    AND [M2CommentsRtf].[M2CommentsRtf] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [CDRComments]
    ON s.caseID = [CDRComments].caseID
    AND s.modifiedOn = [CDRComments].modifiedOn
    AND [CDRComments].[CDRComments] = (SELECT TOP 1 [CDRComments] FROM #CEREligibility WHERE caseID = s.caseID AND [CDRComments] IS NOT NULL ORDER BY ModifiedOn)
    AND [CDRComments].[CDRComments] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [CDRCommentsRtf]
    ON s.caseID = [CDRCommentsRtf].caseID
    AND s.modifiedOn = [CDRCommentsRtf].modifiedOn
    AND [CDRCommentsRtf].[CDRCommentsRtf] = (SELECT TOP 1 [CDRCommentsRtf] FROM #CEREligibility WHERE caseID = s.caseID AND [CDRCommentsRtf] IS NOT NULL ORDER BY ModifiedOn)
    AND [CDRCommentsRtf].[CDRCommentsRtf] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [RIAWA]
    ON s.caseID = [RIAWA].caseID
    AND s.modifiedOn = [RIAWA].modifiedOn
    AND [RIAWA].[RIAWA] = (SELECT TOP 1 [RIAWA] FROM #CEREligibility WHERE caseID = s.caseID AND [RIAWA] IS NOT NULL ORDER BY ModifiedOn)
    AND [RIAWA].[RIAWA] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [RIAWADate]
    ON s.caseID = [RIAWADate].caseID
    AND s.modifiedOn = [RIAWADate].modifiedOn
    AND [RIAWADate].[RIAWADate] = (SELECT TOP 1 [RIAWADate] FROM #CEREligibility WHERE caseID = s.caseID AND [RIAWADate] IS NOT NULL ORDER BY ModifiedOn)
    AND [RIAWADate].[RIAWADate] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [EducationAndTraining]
    ON s.caseID = [EducationAndTraining].caseID
    AND s.modifiedOn = [EducationAndTraining].modifiedOn
    AND [EducationAndTraining].[EducationAndTraining] = (SELECT TOP 1 [EducationAndTraining] FROM #CEREligibility WHERE caseID = s.caseID AND [EducationAndTraining] IS NOT NULL ORDER BY ModifiedOn)
    AND [EducationAndTraining].[EducationAndTraining] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [EducationAndTrainingDate]
    ON s.caseID = [EducationAndTrainingDate].caseID
    AND s.modifiedOn = [EducationAndTrainingDate].modifiedOn
    AND [EducationAndTrainingDate].[EducationAndTrainingDate] = (SELECT TOP 1 [EducationAndTrainingDate] FROM #CEREligibility WHERE caseID = s.caseID AND [EducationAndTrainingDate] IS NOT NULL ORDER BY ModifiedOn)
    AND [EducationAndTrainingDate].[EducationAndTrainingDate] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [Internship]
    ON s.caseID = [Internship].caseID
    AND s.modifiedOn = [Internship].modifiedOn
    AND [Internship].[Internship] = (SELECT TOP 1 [Internship] FROM #CEREligibility WHERE caseID = s.caseID AND [Internship] IS NOT NULL ORDER BY ModifiedOn)
    AND [Internship].[Internship] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [InternshipDate]
    ON s.caseID = [InternshipDate].caseID
    AND s.modifiedOn = [InternshipDate].modifiedOn
    AND [InternshipDate].[InternshipDate] = (SELECT TOP 1 [InternshipDate] FROM #CEREligibility WHERE caseID = s.caseID AND [InternshipDate] IS NOT NULL ORDER BY ModifiedOn)
    AND [InternshipDate].[InternshipDate] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [Apprenticeship]
    ON s.caseID = [Apprenticeship].caseID
    AND s.modifiedOn = [Apprenticeship].modifiedOn
    AND [Apprenticeship].[Apprenticeship] = (SELECT TOP 1 [Apprenticeship] FROM #CEREligibility WHERE caseID = s.caseID AND [Apprenticeship] IS NOT NULL ORDER BY ModifiedOn)
    AND [Apprenticeship].[Apprenticeship] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [ApprenticeshipDate]
    ON s.caseID = [ApprenticeshipDate].caseID
    AND s.modifiedOn = [ApprenticeshipDate].modifiedOn
    AND [ApprenticeshipDate].[ApprenticeshipDate] = (SELECT TOP 1 [ApprenticeshipDate] FROM #CEREligibility WHERE caseID = s.caseID AND [ApprenticeshipDate] IS NOT NULL ORDER BY ModifiedOn)
    AND [ApprenticeshipDate].[ApprenticeshipDate] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [Entrepreneurship]
    ON s.caseID = [Entrepreneurship].caseID
    AND s.modifiedOn = [Entrepreneurship].modifiedOn
    AND [Entrepreneurship].[Entrepreneurship] = (SELECT TOP 1 [Entrepreneurship] FROM #CEREligibility WHERE caseID = s.caseID AND [Entrepreneurship] IS NOT NULL ORDER BY ModifiedOn)
    AND [Entrepreneurship].[Entrepreneurship] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [EntrepreneurshipDate]
    ON s.caseID = [EntrepreneurshipDate].caseID
    AND s.modifiedOn = [EntrepreneurshipDate].modifiedOn
    AND [EntrepreneurshipDate].[EntrepreneurshipDate] = (SELECT TOP 1 [EntrepreneurshipDate] FROM #CEREligibility WHERE caseID = s.caseID AND [EntrepreneurshipDate] IS NOT NULL ORDER BY ModifiedOn)
    AND [EntrepreneurshipDate].[EntrepreneurshipDate] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [EmploymentPrep]
    ON s.caseID = [EmploymentPrep].caseID
    AND s.modifiedOn = [EmploymentPrep].modifiedOn
    AND [EmploymentPrep].[EmploymentPrep] = (SELECT TOP 1 [EmploymentPrep] FROM #CEREligibility WHERE caseID = s.caseID AND [EmploymentPrep] IS NOT NULL ORDER BY ModifiedOn)
    AND [EmploymentPrep].[EmploymentPrep] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [EmploymentPrepDate]
    ON s.caseID = [EmploymentPrepDate].caseID
    AND s.modifiedOn = [EmploymentPrepDate].modifiedOn
    AND [EmploymentPrepDate].[EmploymentPrepDate] = (SELECT TOP 1 [EmploymentPrepDate] FROM #CEREligibility WHERE caseID = s.caseID AND [EmploymentPrepDate] IS NOT NULL ORDER BY ModifiedOn)
    AND [EmploymentPrepDate].[EmploymentPrepDate] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [OTPrep]
    ON s.caseID = [OTPrep].caseID
    AND s.modifiedOn = [OTPrep].modifiedOn
    AND [OTPrep].[OTPrep] = (SELECT TOP 1 [OTPrep] FROM #CEREligibility WHERE caseID = s.caseID AND [OTPrep] IS NOT NULL ORDER BY ModifiedOn)
    AND [OTPrep].[OTPrep] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [OTPrepDate]
    ON s.caseID = [OTPrepDate].caseID
    AND s.modifiedOn = [OTPrepDate].modifiedOn
    AND [OTPrepDate].[OTPrepDate] = (SELECT TOP 1 [OTPrepDate] FROM #CEREligibility WHERE caseID = s.caseID AND [OTPrepDate] IS NOT NULL ORDER BY ModifiedOn)
    AND [OTPrepDate].[OTPrepDate] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [ExitInterview]
    ON s.caseID = [ExitInterview].caseID
    AND s.modifiedOn = [ExitInterview].modifiedOn
    AND [ExitInterview].[ExitInterview] = (SELECT TOP 1 [ExitInterview] FROM #CEREligibility WHERE caseID = s.caseID AND [ExitInterview] IS NOT NULL ORDER BY ModifiedOn)
    AND [ExitInterview].[ExitInterview] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [ExitInterviewDate]
    ON s.caseID = [ExitInterviewDate].caseID
    AND s.modifiedOn = [ExitInterviewDate].modifiedOn
    AND [ExitInterviewDate].[ExitInterviewDate] = (SELECT TOP 1 [ExitInterviewDate] FROM #CEREligibility WHERE caseID = s.caseID AND [ExitInterviewDate] IS NOT NULL ORDER BY ModifiedOn)
    AND [ExitInterviewDate].[ExitInterviewDate] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [CreatedOn]
    ON s.caseID = [CreatedOn].caseID
    AND s.modifiedOn = [CreatedOn].modifiedOn
    AND [CreatedOn].[CreatedOn] = (SELECT TOP 1 [CreatedOn] FROM #CEREligibility WHERE caseID = s.caseID AND [CreatedOn] IS NOT NULL ORDER BY ModifiedOn)
    AND [CreatedOn].[CreatedOn] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [CreatedBy]
    ON s.caseID = [CreatedBy].caseID
    AND s.modifiedOn = [CreatedBy].modifiedOn
    AND [CreatedBy].[CreatedBy] = (SELECT TOP 1 [CreatedBy] FROM #CEREligibility WHERE caseID = s.caseID AND [CreatedBy] IS NOT NULL ORDER BY ModifiedOn)
    AND [CreatedBy].[CreatedBy] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [ModifiedOn]
    ON s.caseID = [ModifiedOn].caseID
    AND s.modifiedOn = [ModifiedOn].modifiedOn
    AND [ModifiedOn].[ModifiedOn] = (SELECT TOP 1 [ModifiedOn] FROM #CEREligibility WHERE caseID = s.caseID AND [ModifiedOn] IS NOT NULL ORDER BY ModifiedOn)
    AND [ModifiedOn].[ModifiedOn] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [ModifiedBy]
    ON s.caseID = [ModifiedBy].caseID
    AND s.modifiedOn = [ModifiedBy].modifiedOn
    AND [ModifiedBy].[ModifiedBy] = (SELECT TOP 1 [ModifiedBy] FROM #CEREligibility WHERE caseID = s.caseID AND [ModifiedBy] IS NOT NULL ORDER BY ModifiedOn)
    AND [ModifiedBy].[ModifiedBy] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [BCPermInEligibility]
    ON s.caseID = [BCPermInEligibility].caseID
    AND s.modifiedOn = [BCPermInEligibility].modifiedOn
    AND [BCPermInEligibility].[BCPermInEligibility] = (SELECT TOP 1 [BCPermInEligibility] FROM #CEREligibility WHERE caseID = s.caseID AND [BCPermInEligibility] IS NOT NULL ORDER BY ModifiedOn)
    AND [BCPermInEligibility].[BCPermInEligibility] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [CCPermInEligibility]
    ON s.caseID = [CCPermInEligibility].caseID
    AND s.modifiedOn = [CCPermInEligibility].modifiedOn
    AND [CCPermInEligibility].[CCPermInEligibility] = (SELECT TOP 1 [CCPermInEligibility] FROM #CEREligibility WHERE caseID = s.caseID AND [CCPermInEligibility] IS NOT NULL ORDER BY ModifiedOn)
    AND [CCPermInEligibility].[CCPermInEligibility] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [M2EligibilityDate]
    ON s.caseID = [M2EligibilityDate].caseID
    AND s.modifiedOn = [M2EligibilityDate].modifiedOn
    AND [M2EligibilityDate].[M2EligibilityDate] = (SELECT TOP 1 [M2EligibilityDate] FROM #CEREligibility WHERE caseID = s.caseID AND [M2EligibilityDate] IS NOT NULL ORDER BY ModifiedOn)
    AND [M2EligibilityDate].[M2EligibilityDate] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [CDREligibilityDate]
    ON s.caseID = [CDREligibilityDate].caseID
    AND s.modifiedOn = [CDREligibilityDate].modifiedOn
    AND [CDREligibilityDate].[CDREligibilityDate] = (SELECT TOP 1 [CDREligibilityDate] FROM #CEREligibility WHERE caseID = s.caseID AND [CDREligibilityDate] IS NOT NULL ORDER BY ModifiedOn)
    AND [CDREligibilityDate].[CDREligibilityDate] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [ExitSeparationCode]
    ON s.caseID = [ExitSeparationCode].caseID
    AND s.modifiedOn = [ExitSeparationCode].modifiedOn
    AND [ExitSeparationCode].[ExitSeparationCode] = (SELECT TOP 1 [ExitSeparationCode] FROM #CEREligibility WHERE caseID = s.caseID AND [ExitSeparationCode] IS NOT NULL ORDER BY ModifiedOn)
    AND [ExitSeparationCode].[ExitSeparationCode] IS NOT NULL
    LEFT OUTER JOIN #CEREligibility [ExitSeparationSubCode]
    ON s.caseID = [ExitSeparationSubCode].caseID
    AND s.modifiedOn = [ExitSeparationSubCode].modifiedOn
    AND [ExitSeparationSubCode].[ExitSeparationSubCode] = (SELECT TOP 1 [ExitSeparationSubCode] FROM #CEREligibility WHERE caseID = s.caseID AND [ExitSeparationSubCode] IS NOT NULL ORDER BY ModifiedOn)
    AND [ExitSeparationSubCode].[ExitSeparationSubCode] IS NOT NULL
    GROUP BY s.caseID
    When I ran this against your test data, It produced a single row for each of the two case ID's.
    To keep performance in line, I also created a covering index on the temp table:
    CREATE INDEX idx_caseID_ModifiedOn ON #CEREligibility (caseID, modifiedOn) INCLUDE ([CEREligibilityId], [M2Eligibility], [CDREligibility], [M2Comments], [M2CommentsRtf], [CDRComments], [CDRCommentsRtf], [RIAWA], [RIAWADate], [EducationAndTraining], [EducationAndTrainingDate], [Internship], [InternshipDate], [Apprenticeship], [ApprenticeshipDate], [Entrepreneurship], [EntrepreneurshipDate], [EmploymentPrep], [EmploymentPrepDate], [OTPrep], [OTPrepDate], [ExitInterview], [ExitInterviewDate], [CreatedOn], [CreatedBy], [ModifiedBy], [BCPermInEligibility], [CCPermInEligibility], [M2EligibilityDate], [CDREligibilityDate], [ExitSeparationCode], [ExitSeparationSubCode])
    Don't forget to mark helpful posts, and answers. It helps others to find relevant posts to the same question.

  • Oracle query - Merging multiple rows into a single row output

    Hi All,
    I have to have a multiple row output to be converted into a single row output.My current output looks as follows:
    ID YR INC_CODE OFFN SCHOOLNO
    8006 2002 00175 SC03 12
    8006 2002 00175 DC06 12
    8006 2002 00175 DC03 12
    8006 2002 00175 DC02 12
    ID,INCIDENT CODE,OFFENSE are all Primary keys
    So I need the output as follows:(IN ONE ROW)
    ID YR INC_CODE OFFN1 OFFN2 OFFN3 OFFN4 SCHOOLNO
    8006 2002 00175 SC03 DC06 DC03 DC02 12
    Can you help me on this since have been spinning the wheel and this has to be a query since will have couple of tables join to produce a materialized view.
    Thanks in advance

    Hi Nigel,
    Thanks for the reply I tested out the portion having the decode and I get the output as follows:
    ID YR INC_CODE OFFN1 OFFN2 OFFN3 OFFN4 OFFN5
    8982 2002 2175 DOC01 -----------------------
    8982 2002 2175 DOC02-------------------
    8982 2002 2175 DOC03------------
    8982 2002 2175 DOC06-------
    8982 2002 2175 SCV03
    There is no value as max for OFFN and each INC_CODE MAY HAVE UP TO A MAX OF 5 OFFN.My query is as follows:
    select distinct STU_STUDENT_ID, INC_BEG_SCH_YR,INC_INCIDENT_CODE
    , decode(rank() over (partition by INC_CODE order by OFFN),1,OFFN,null) as offn1
    , decode(rank() over (partition by INC_CODE order by OFFN),2,OFFN,null) as offn2
    , decode(rank() over (partition by INC_CODE order by OFFN),3,OFFN,null) as offn3
    , decode(rank() over (partition by INC_CODE order by OFFN),4,OFFN,null) as offn4
    , decode(rank() over (partition by INC_CODE order by OFFN),5,OFFN,null) as offn5
    from stu_offn where
    stu_offn.ID = '8982' and stu_offn.INC_CODE = '2175'
    (****Where clause is just given to just check a value)
    So as you know I need to just have all the OFFN in a single row ie as follows:
    ID YR INC_CODE OFFN1 OFFN2 OFFN3 OFFN4 OFFN5
    8982 2002 2175 DOC01 DOC02 DOC03 DOC06 SCV03
    Can you just give me a step by step procedure to go through this and the table in this case is just 'STU_OFFN'
    Thanks for the earlier reply appreciate it!
    ****Sending this again to show the exact way the output is coming

  • Multiple rows Converge to Single row and join

    Hi Folks,
    I am facing a tricky challenge to join a table with multiple rows and converge into a single row (based on ID, period) and join with another table to get a single row. Let me explain.
    Table 1: DTL_TABLE (id, period, course, names, title, type)
    1 2010 mat john null null
    1 2010 mat jim null null
    1 2010 cam null officer null
    1 2010 cam null Prof null
    1 2010 phy null null Inclass
    1 2010 phy null null Online
    Join with
    Table 2: ID_TABLE(id, period, Loc, Dept, Code)
    1 2010 nj 101 CC.
    Output format (id, period, course, names, title, type, Loc, Dept, Code)
    result : 1 2010 mat,cam,phy john,jim officer,prof inclass,online nj 101 CC
    I have created all the DDLs and DMLs if that help. Kindly let me know if a Join SQL query is possible.
    Thank you,
    Aj
    CREATE TABLE DTL_TABLE
       ids      VARCHAR2 (10),
       period   VARCHAR2 (10),
       course   VARCHAR2 (10),
       names    VARCHAR2 (10),
       title    VARCHAR2 (10),
       TYPE     VARCHAR2 (10)
    INSERT INTO DTL_TABLE
         VALUES ('1',
                 '2010',
                 'mat',
                 'jim',
                 NULL,
                 NULL);
    INSERT INTO DTL_TABLE
         VALUES ('1',
                 '2010',
                 'mat',
                 'john',
                 NULL,
                 NULL);
    INSERT INTO DTL_TABLE
         VALUES ('1',
                 '2010',
                 'mat',
                 'kale',
                 NULL,
                 NULL);
    INSERT INTO DTL_TABLE
         VALUES ('1',
                 '2010',
                 'cam',
                 NULL,
                 'officer',
                 NULL);
    INSERT INTO DTL_TABLE
         VALUES ('1',
                 '2010',
                 'cam',
                 NULL,
                 'prof',
                 NULL);
    INSERT INTO DTL_TABLE
         VALUES ('1',
                 '2010',
                 'phy',
                 NULL,
                 NULL,
                 'inclass');
    INSERT INTO DTL_TABLE
         VALUES ('1',
                 '2010',
                 'phy',
                 NULL,
                 NULL,
                 'online');
    COMMIT;
    CREATE TABLE id_table
       ids      VARCHAR2 (10),
       period   VARCHAR2 (10),
       loc      VARCHAR2 (10),
       dept     VARCHAR2 (10),
       code     VARCHAR2 (10)
    INSERT INTO id_table
         VALUES ('1',
                 '2010',
                 'nj',
                 '101',
                 'cc');
    COMMIT;

    Aj09 wrote:
    Hi Folks,
    I am facing a tricky challenge to join a table with multiple rows and converge into a single row (based on ID, period) and join with another table to get a single row. Let me explain.
    Table 1: DTL_TABLE (id, period, course, names, title, type)
    1 2010 mat john null null
    1 2010 mat jim null null
    1 2010 cam null officer null
    1 2010 cam null Prof null
    1 2010 phy null null Inclass
    1 2010 phy null null Online
    Join with
    Table 2: ID_TABLE(id, period, Loc, Dept, Code)
    1 2010 nj 101 CC.
    Output format (id, period, course, names, title, type, Loc, Dept, Code)
    result : 1 2010 mat,cam,phy john,jim officer,prof inclass,online nj 101 CC
    I have created all the DDLs and DMLs if that help. Kindly let me know if a Join SQL query is possible.
    SELECT TBL.id,
           DTLperiod,
           course,
           names,
           title,
           TYPE,
           Loc,
           Dept,
           Code
    FROM   ID_TABLE TBL,
           DTL_TABLE DTL
    WHERE  TBL.ID = DTL.ID
           AND TBL.PERIOD = DTL.PERIOD; it not good to use RESERVED WORDS like "ID" or "TYPE" as column names

  • Multiple clobs in a single row of data

    I have several clobs in a single row of data and have created a procedure where I attempt to display the first 4k of each clob.
    using a for loop cursor I select all of the clobs in a row at the same time and then I use dbms_lob.read to get the first 4k of data.
    For the first lob of each row everything works fine but when I attempt to dbms_lob.read the second one I get an "ORA-06502: PL/SQL: numeric or value error: invalid LOB locator specified: ORA-22275" and I'm not sure why?
    does anyone know of an example where two or more clobs are selected and then converted to 4K varchars?
    sample columns for the table:
    SPECIALREQUIREMENTSS     CLOB
    REFERENCERANGE     CLOB
    ALERTVALUE     CLOB
    REFERENCELAB     VARCHAR2(50 CHAR)
    TESTINCLUDES     CLOB
    LASTUPDATE     DATE
    sample code (I removed some code for clairity - this produces the same error):
    create or replace
    procedure test_lobs as
    v_lab_blob blob;
    v_lobamt binary_integer := 32767;
    v_lobpos pls_integer := 1;
    v_labrec labman.lab_testingdata%rowtype;
    v_buffer varchar2(32767) :='';
    v_start_left number;
    begin
    -- *** housekeeping
    dbms_lob.createtemporary(v_labrec.testincludes,TRUE);
    dbms_lob.createtemporary(v_labrec.specialrequirementss,TRUE);
    Plpdf.init;
    Plpdf.NewPage;
    Plpdf.SetColor4Drawing(66,66,66);
    Plpdf.SetColor4Filling(180,180,180);
    v_start_left := Plpdf.GetPageWidth-Plpdf.GetPageRightSpace;
    -- *** select the test name for shaded printing
    for x in (select indexnumber, test from labman.lab_testingdata where test like 'A%') loop
    -- *** select the test data for printing
    select * into v_labrec from labman.lab_testingdata where indexnumber = x.indexnumber;
    -- *** test includes
    if dbms_lob.getlength(v_labrec.testincludes) > 0 or v_labrec.testincludes is not null then
    Plpdf.SetPrintFont('Arial','B',8);
    Plpdf.LineBreak(.1);
    Plpdf.PrintCell(25,5,'Test Includes:',0,0,'R',0,null,0);
    Plpdf.SetPrintFont('Arial',null,8);
    if dbms_lob.getlength(v_labrec.testincludes) > 32767 then
    v_buffer := '*** error - text is greater than 32k ***';
    else
    v_lobamt := 32767;
    v_buffer := '';
    dbms_lob.read(v_labrec.testincludes,v_lobamt,v_lobpos,v_buffer);
    end if;
    Plpdf.SetLeftMargin(Plpdf.GetCurrentX);
    Plpdf.PrintFlowingText(5,v_buffer,null,0);
    Plpdf.SetLeftMargin(v_start_left);
    Plpdf.lineBreak;
    end if;
    -- *** special requirements
    Plpdf.SetPrintFont('Arial','B',8);
    Plpdf.LineBreak(.1);
    Plpdf.PrintCell(25,5,'Special Requirements:',0,0,'R',0,null,0);
    Plpdf.SetPrintFont('Arial',null,8);
    if dbms_lob.getlength(v_labrec.specialrequirementss) > 32767 then
    v_buffer := '*** error - text is greater than 32k ***';
    elsif dbms_lob.getlength(v_labrec.specialrequirementss) = 0 then
    v_buffer := '';
    else
    v_lobamt := 32767;
    v_buffer := '';
    dbms_lob.read(v_labrec.specialrequirementss,v_lobamt,v_lobpos,v_buffer);
    end if;
    Plpdf.SetLeftMargin(Plpdf.GetCurrentX);
    Plpdf.PrintFlowingText(5,v_buffer,null,0);
    Plpdf.SetLeftMargin(v_start_left);
    Plpdf.lineBreak;
    commit;
    end loop;
    Plpdf.SendDoc(v_lab_blob);
    -- store the PDF document
    delete from store_blob;
    commit;
    INSERT INTO STORE_BLOB (blob_file, created_date)
    VALUES (v_lab_blob, SYSDATE);
    COMMIT;
    end test_lobs;

    didn't think that checking for a length of zero and null would produce two different results - should have known better.
    Thanks for your help!
    elsif dbms_lob.getlength(v_labrec.specialrequirementss) = 0
    or v_labrec.specialrequirementss is null then

  • Multiple row as a single row in a column

    Hi,
    I want to select Multiple rows into a single line in 'Single Column Table' .
    For ex:
    Employee table has only one column , named as empname . it has three rows
    Select empname from emp;
    empname
    thambi
    peter
    antony
    My expected result: thambi,peter,antony

    How do I ask a question on the forums?
    https://forums.oracle.com/forums/thread.jspa?threadID=2174552#9360002

  • Customizing Sharepoint Calendar Week Group View to display multiple weeks in a single row

    Hi,
    SharePoint Calendar's Week Group View is useful for comparing multiple co-worker's schedule, and we have a business needs to be able to view the schedule for with the date range of more than one week at a time between co-workers for planning purposes, is
    there a way (code or no-code) to manipulate the date/week range so that the calendar display more than 7 days in a single row?

    Hi,
    As there is no such OOTB feature, I would suggest that you can change the calendar scope to “Month” or create a Gantt view to display more weeks in a view.
    Or you can try to create a custom calendar web part to meet your requirement.
    Here are some samples of custom calendar web part for your reference:
    http://www.codeproject.com/Articles/108676/SharePoint-Custom-Calendar
    http://gunnarpeipman.com/2009/01/creating-sharepoint-global-calendar/
    https://blog.metrostarsystems.com/2013/10/21/creating-a-custom-sharepoint-calendar-rollup/
    Best regards
    Patrick Liang
    TechNet Community Support

  • Inserting table in web form/ Inserting multiple cells in a single row

    Dear Mr Johnson,
    Thanks for your early reply.
    I am rather disappointed .....as I need to distribute my form urgently with a table insertion capability.
    I had purchased Adobe webform central subscription with the idea that a paid subscription will fetch me the full editing capability of the Adobe form central web forms.
    Please inform me as to when this vital update regarding the table insertion/ multiple cells insertion in a single row capability (update) will be functional and available for our use as today is 26th of January, 2013.
    Kindly reply ASAP.
    Thanks,
    with kind regards,
    Dr Ali

    See this thread from two days ago where Randy Swineford of Adobe says that it is expected to be added at the end of January: http://forums.adobe.com/thread/1140470?tstart=0
    I don't know if it will include a table tool.

  • How to merge three columns values to single row values in sql server 2008

    Hi Frds.....
    I have three quantity in my table.
    Quantity1,quantity2,quantity3
    this three quantity have different values
    ex:
    quantity1 = 1000,quantity2=2000,quantity3=3000
    the three column combine 2 display in single row values. this values display in one by one.
    ex: quantity
         1000
         2000
         3000

    You will need to use the UNPIVOT operator:
    DECLARE @example TABLE
    Id int NOT NULL IDENTITY(1,1),
    Quantity1 int,
    Quantity2 int,
    Quantity3 int
    INSERT INTO @example VALUES (1000, 2000, 3000), (4000, 5000, 6000);
    SELECT * FROM @example;
    SELECT Id, Quantity, QuantityType
    FROM @example
    UNPIVOT
    Quantity FOR QuantityType IN (Quantity1, Quantity2, Quantity3)
    ) AS u;
    Output:
    (2 row(s) affected)
    Id Quantity1 Quantity2 Quantity3
    1 1000 2000 3000
    2 4000 5000 6000
    (2 row(s) affected)
    Id Quantity QuantityType
    1 1000 Quantity1
    1 2000 Quantity2
    1 3000 Quantity3
    2 4000 Quantity1
    2 5000 Quantity2
    2 6000 Quantity3
    (6 row(s) affected)

Maybe you are looking for

  • How to create a Bool Option for Full Screen and Page Item in Mucow?

    Hi Guys! I was looking to create a bool option in Mucow widget options which toggles between Full Screen and a Normal Page Item . Example: Qooqee's Google Map Widget Need some help. Thanks in Advance

  • Is there a way to bring back the actual tab "bar"?

    So in switching from FF3.6 to 5.0 I have noticed that the actual "bar" that holds the tabs is gone. Observe: [http://i.imgur.com/eU7lo.jpg http://i.imgur.com/eU7lo.jpg] It's visually slightly annoying to not have a distinct separator between the tab

  • Login(user ID and Password) to my VI

    Hello, Iam creating a vi with some parameters...........My VI consists of Tabs, now in home page user should enter user name and password...........and if it is success then the VI should give acess to all tabs......otherwise it should display that w

  • PA30, attaching documents through the employee personal master dat

    Dear freinds, We are attaching documents through the employee personal master data PA30, Our client wants to know where exactly these attachments are getting saved; Our SAP environment is ECC6.0 on AIX 5.3. so i exactly would like to know what is the

  • SQL Developer Problems with Microsoft Word Apostrophes

    Hi, I'm trying to copy and paste a list like the following from Microsoft Word to SQL Developer - '123','456','789' Shouldnt be a problem. But when ever I paste it into an sql file in Developer it comes out with different styled apostrophes which SQL