Solved

concatenate

Posted on 2011-02-22
1
435 Views
Last Modified: 2012-05-11
Hi I am using Oracle 9i with following query
/* Formatted on 22/02/2011 10:19:33 AM (QP5 v5.136.908.31019) */
SELECT ELECTMEMBER.MEMBERNO,
       TITLE.DESCRIPTION || ' ' || ELECTMEMBER.NAME AS NAME,
       TRIM(SUBSTR (ELECTMEMBERADDRESS.ADDRESS,
                    1,
                    INSTR (ELECTMEMBERADDRESS.ADDRESS,
                           '$',
                           1,
                           1)
                    - 1))
          AS ADDRESS1,
       TRIM(SUBSTR (ELECTMEMBERADDRESS.ADDRESS,
                    INSTR (ELECTMEMBERADDRESS.ADDRESS,
                           '$',
                           1,
                           1)
                    + 1,
                    (INSTR (ELECTMEMBERADDRESS.ADDRESS,
                            '$',
                            1,
                            2)
                     - 1)
                    - (INSTR (ELECTMEMBERADDRESS.ADDRESS,
                              '$',
                              1,
                              1))))
          AS ADDRESS2,
       TRIM(SUBSTR (ELECTMEMBERADDRESS.ADDRESS,
                    INSTR (ELECTMEMBERADDRESS.ADDRESS,
                           '$',
                           1,
                           2)
                    + 1,
                    (INSTR (ELECTMEMBERADDRESS.ADDRESS,
                            '$',
                            1,
                            3)
                     - 1)
                    - (INSTR (ELECTMEMBERADDRESS.ADDRESS,
                              '$',
                              1,
                              2))))
          AS ADDRESS3,
       TRIM(SUBSTR (ELECTMEMBERADDRESS.ADDRESS,
                    INSTR (ELECTMEMBERADDRESS.ADDRESS,
                           '$',
                           1,
                           3)
                    + 1))
          AS ADDRESS4,
          ELECTMEMBERADDRESS.CITYOTHER
       || CITY.DESCRIPTION
       || ' - '
       || ELECTMEMBERADDRESS.PINCODE
          AS CITY,
       TRUNC (TO_DATE (ELECTMEMBER.ELECTDATE, 'DD/MM/YYYY')) AS ELECTDATE,
       TRUNC (TO_DATE (ELECTMEMBER.EFFECTIVEDATEFROM, 'DD/MM/YYYY'))
          AS EFFECTIVEFROM,
       TRUNC (TO_DATE (ELECTMEMBER.EFFECTIVEDATETO, 'DD/MM/YYYY'))
          AS EFFECTIVETO,
       CATEGORYSUBGROUP.DESCRIPTION AS CATEGORYSUBGROUP,
       SUBSCRIPTION.DESCRIPTION AS SUBSCRIPTION
  FROM ELECTMEMBER
       LEFT OUTER JOIN ELECTMEMBERADDRESS
          ON ELECTMEMBER.ELECTMEMBER_ID = ELECTMEMBERADDRESS.ELECTMEMBER_ID
       LEFT OUTER JOIN CATEGORYSUBGROUP
          ON CATEGORYSUBGROUP.CATEGORYSUBGROUP_ID =
                ELECTMEMBER.CATEGORYSUBGROUP_ID
       LEFT OUTER JOIN CITY
          ON CITY.CITY_ID = ELECTMEMBERADDRESS.CITY_ID
       LEFT OUTER JOIN COUNTRY
          ON COUNTRY.COUNTRY_ID = ELECTMEMBERADDRESS.COUNTRY_ID
       LEFT OUTER JOIN STATE
          ON STATE.STATE_ID = ELECTMEMBERADDRESS.STATE_ID
       LEFT OUTER JOIN TITLE
          ON TITLE.TITLE_ID = ELECTMEMBER.TITLE_ID
       LEFT OUTER JOIN ELECTSUBSCRIPTIONUSER
          ON ELECTMEMBER.ELECTMEMBER_ID =
                ELECTSUBSCRIPTIONUSER.ELECTMEMBER_ID
       LEFT OUTER JOIN SUBSCRIPTION
          ON ELECTSUBSCRIPTIONUSER.SUBSCRIPTION_ID =
                SUBSCRIPTION.SUBSCRIPTION_ID
       LEFT OUTER JOIN ELECTMEMBERTYPE
          ON ELECTMEMBER.ELECTMEMBERTYPE_ID =
                ELECTMEMBERTYPE.ELECTMEMBERTYPE_ID
 WHERE ELECTMEMBER.ELECTDATE BETWEEN NVL (
                                        TO_DATE ('10/02/2009', 'DD/MM/YYYY'),
                                        ELECTMEMBER.ELECTDATE)
                                 AND  NVL (
                                         TO_DATE ('10/02/2012', 'DD/MM/YYYY'),
                                         ELECTMEMBER.ELECTDATE)
       AND ELECTMEMBER.ISACTIVE = 1
       AND ELECTMEMBERADDRESS.ISCORRESPONDENCEADDRESS=1
       AND ELECTMEMBERTYPE.ELECTMEMBERTYPE.ISELECT = 1
       AND ELECTMEMBER.MEMBERNO='K-293'
       
       I want to concatenate  SUBSCRIPTION.DESCRIPTION AS SUBSCRIPTION as per excel sheet shown in desired output. Problem is I do not know how many rows will come so I cant hard code it
elect.xls
0
Comment
Question by:GRChandrashekar
1 Comment
 
LVL 28

Accepted Solution

by:
Naveen Kumar earned 500 total points
ID: 34958776
This link contains all string aggregation techniques. You can pick the one which suits you. just note you need to pick the one which works in 9i

http://www.oracle-base.com/articles/misc/StringAggregationTechniques.php
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
dates - loop 12 67
Oracle Public Synonyms and Privileges 2 65
database upgrade 8 77
Extract Currency data from a string and put them in a new field 3 36
Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: http://www.e-e.com/A_8429.html Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many…
Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question