Solved

concatenate

Posted on 2011-02-22
1
434 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

Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
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
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…

863 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now