Comma seperated Column, to get details?

how to do, when Table1 has Column with comma seperated IDs, details are in the Table2.
Table 1
ID Col2
1 10,12
2 18,12
3 5,3
4 10
Table 2
col1 col2
3 new
5 old
10 semi
12 mild
18 very mild
a query/pl sql to get the results in:
Results:
ID Col2
1 10
1 12
2 18
2 12
3 5
3 3
4 10

but fails if the column has more number of seperated valuesWhat do you mean? Do you get an error? Or the wrong results?
This works for me on 10gXE:
BANNER
Oracle Database 10g Express Edition Release 10.2.0.1.0 - Product
PL/SQL Release 10.2.0.1.0 - Production
CORE    10.2.0.1.0      Production
TNS for 32-bit Windows: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production
SQL> drop table t;
Table dropped.
SQL> create table t as
  2  select 1 id, '12,13' col from dual union
  3  select 2 id, '10,11,12,13' col from dual union
  4  select 3 id, '1,2' col from dual union
  5  select 4 id, '12,13,14,15' col from dual union
  6  select 5 id, '1,2,3,4,5,6,7,8' col from dual union
  7  select 6 id, '1' col from dual union
  8  select 7 id, '100,101,102' col from dual union
  9  select 8 id, '21,22,23,24,25,26,27,28,29,30,31' col from dual;
Table created.
SQL> select id
  2  ,      column_value
  3  from ( select id
  4         ,      ','||col||',' col
  5         from   t
  6        )
  7  ,      table(cast(multiset(select substr( col
  8                                          , instr (col, ',', 1, level  ) + 1
  9                                          , instr (col, ',', 1, level+1) - instr (col, ',', 1, level) -1
10                                          )
11                                from   dual
12                                connect by level <= length(col)-length(replace(col,',',''))-1
13                              )
14                      as sys.odcinumberlist
15                    )
16              );
        ID COLUMN_VALUE
         1           12
         1           13
         2           10
         2           11
         2           12
         2           13
         3            1
         3            2
         4           12
         4           13
         4           14
         4           15
         5            1
         5            2
         5            3
         5            4
         5            5
         5            6
         5            7
         5            8
         6            1
         7          100
         7          101
         7          102
         8           21
         8           22
         8           23
         8           24
         8           25
         8           26
         8           27
         8           28
         8           29
         8           30
         8           31
35 rows selected.

Similar Messages

  • Splitting comma seperated column data into multiple rows

    Hi Gurus,
    Please help me for solving below scenario. I have multiple value in single column with comma seperated values and my requirement is load that data into multiple rows.
    Below is the example:
    Source Data:
    Product         Size                                 Stock
    ABC              X,XL,XXL,M,L,S                 1,2,3,4,5,6
    Target Data:
    Product         Size                                 Stock
    ABC              X                                     1
    ABC              XL                                   2
    ABC              XXL                                 3
    ABC              M                                    4
    ABC              L                                      5
    ABC             S                                        6
    Which transformation we need to use for getting this output?
    Thanks in advance !

    Hello,
    Do you need to do this tranformation through OWB mapping only? And can you please tell what type of source you are using? Is it a flat file or a table?
    Thanks

  • Have a column which is having comma seperated values.. and i am trying to s

    Have a column which is having comma seperated values.. and i am trying to seperate it.
    I am trying to create a stored procedure ..Version 11g xe. .and apex version 4..
    Here is the part of code..I cant make a procedure. .cause my statement consist with clause..
    create or replace procedure ins_adv_invoice
    (mmagazine_no number,madvtno number,missueno number,msection varchar2,mpagenumber varchar2,msalesman_code varchar2)
    is
    cursor cx is with testa as
    (select pagenumber name from advertiser)
    select regexp_substr(pagenumber, '[^,]+', 1, rownum) result
    from advertiser
    connect by level <= length(regexp_replace(pagenumber, '[^,]+')) + 1
    where advt_no = madvtno;
    begin
    for xxx in cx
    loop
    insert into adv_invoice (magazine_no,advtno,adissue,section,page_number,salesman_code)
    values (mmagazine_no,madvtno,missueno,msection,xxx.result,msalesman_code);
    end loop;
    end;
    But when i run this .. it doesnt create procedure. .I get he following error..
    LINE/COL ERROR
    5/14 PL/SQL: SQL Statement ignored
    9/69 PL/SQL: ORA-00933: SQL command not properly ended
    SQL>
    Still not able to figure it out..Can any one help..
    Thanks

    Change the query to swap the last two lines:
    cursor cx is with testa as
    (select pagenumber name from advertiser)
    select regexp_substr(pagenumber, '[^,]+', 1, rownum) result
    from advertiser
    where advt_no = madvtno
    connect by level <= length(regexp_replace(pagenumber, '[^,]+')) + 1;
    ...

  • Column should display comma seperated value.

    Hi All,
    Iam working on Reports6i.
    In my data model i have a query which gives some product names(only one column), i need to display those product names with a comma seperator.
    Just like Product1,Product2,....
    Can anybody guide me as this is very urgent.
    Thanks in Advance
    Chinni.

    something like this ?
    WITH DATA AS (SELECT 'X' product,1 order_id FROM DUAL
                  UNION ALL
                  SELECT 'Y' product,1 order_id FROM DUAL
                  UNION ALL
                  SELECT 'Z' product,1 order_id FROM DUAL
                  UNION ALL
                  SELECT 'XX' product,2 order_id FROM DUAL
                  UNION ALL
                  SELECT 'YY' product,2 order_id FROM DUAL
                  UNION ALL
                  SELECT 'ZZ' product,2 order_id FROM DUAL
    SELECT LTRIM(sys_connect_by_path(product,','), ',') PRODUCTS
      FROM (SELECT product,
                   order_id,
                   row_number()   OVER (partition by order_id order by product) RN,
                   count(product) OVER (partition by order_id) MAXROW
              FROM data) 
    WHERE RN=MAXROW CONNECT BY     PRIOR RN+1=RN
                                AND PRIOR ORDER_ID=ORDER_ID START WITH RN=1

  • Mapping a column with comma seperated values

    Hi,
    I have two tables
    1. Tasks (task_id, task_description)
    2. Task_assignment (username, task_assignment_value)
    the task_assignment_value has a comma seperated list of task_ids.
    What is the best ways to map the tables ?
    Thanks in advance.
    Moinuddin Mohammed

    I have a couple of attributes where I do this. From TopLink's perspective, I just map it as a String. Then, in my accessors for the attribute, I transform the primitive between the String and an Array or however the rest of the app wants to see the attribute.
    Here's an example that's actually more complicated than absolutely necessary. The mapped attributed is indicatorValueListString. It is lazily converted to an Array of Enums when it is first accessed. And it is converted back to a String in the preWriteEventCallback that is mapped in the TopLink descriptor.
    This implementation attempts to minimize the number of times the String<->Array conversion takes place, but if that's not a concern, it could be made much more simple. Also, at my company we privately manage collections with the Collection classes for dynamic allocation, but publicly exchange Arrays for type-safety. This could also be factored out. ValuedEnumUtils basically manages asking the enum for its delimiter and performing the actual conversion between a String and an Array or back.
    private String indicatorValueListString;
    private List indicatorValueSelections;
    private List indicatorValueSelections() {
            if (indicatorValueSelections == null) {
                    indicatorValueSelections = new ArrayList();
                    if (indicatorValueListString != null) {
                            indicatorValueSelections =
                                    java.util.Arrays.asList(ValuedEnumUtils.decodeEnumString(
                                         IndicatorValueEnum.class,indicatorValueListString));
            return indicatorValueSelections;
    private void indicatorValueSelections(List newIndicatorValueSelections) {
            indicatorValueSelections = newIndicatorValueSelections;
    public IndicatorValueEnum[] getIndicatorValueSelections() {
            return (IndicatorValueEnum[])indicatorValueSelections().toArray(new IndicatorValueEnum[0]);
    public void setIndicatorValueSelections(IndicatorValueEnum[] newIvSelections) {
            indicatorValueSelections(java.util.Arrays.asList(newIvSelections));
    public boolean addIndicatorValueSelection(IndicatorValueEnum anIvEnum) {
            return indicatorValueSelections().add(anIvEnum);
    public boolean removeIndicatorValueSelection(IndicatorValueEnum anIvEnum) {
            return indicatorValueSelections().remove(anIvEnum);
    public void preWriteEventCallback(DescriptorEvent aDescriptorEvent) {
            // Note: Not using accessor to avoid lazy initialization if no changes
            // are necessary.
            if (indicatorValueSelections != null) {
                    indicatorValueListString =
                            ValuedEnumUtils.encodeEnumString((ValuedEnum[])indicatorValueSelections.toArray());
    }

  • Excel comma seperated .csv files save as semicolon seperated

    Hi
    I work with excel 360 student version danish and i'm trying to convert an siemens .xmls generated file to an .csv comma seperated file but excel save it as an semi colon though it's written in help file it should save it as an comma seperated file.
    Any solution on that what i would call a bug thats been there for over a year?

    Kent, I think you're posting a complaint about Excel, which is off topic for the TechNet Website Feedback forum. The best place to post that would be over at http://answers.microsoft.com in the office section.  Below is some boilerplate that
    I've written up that might also help you.
    Thanks,
    Mike
    Unfortunately your post is off topic here, in the TechNet Site Feedback forum, because it is not Feedback about the TechNet Website or Subscription.  This is only one forum among the many that are on the TechNet Discussion Forums, and given
    your post, you likely chose the wrong forum.  This is a standard response I’ve written up in advance to help many people (thousands, really.) who post their question in this forum in error, but please don’t ignore it.  The links I share below I’ve
    collected to help you get right where you need to go with your issue.
    For technical issues with Microsoft products that you would run into as an
    end user of those products, one great source of info and help is
    http://answers.microsoft.com, which has sections for Windows, Hotmail, Office, IE, and other products. Office related forums are also here:
    http://office.microsoft.com/en-us/support/contact-us-FX103894077.aspx
    For Technical issues with Microsoft products that you might have as an
    IT professional (like technical installation issues, or other IT issues), you should head to the TechNet Discussion forums at
    http://social.technet.microsoft.com/forums/en-us, and search for your product name.
    For issues with products you might have as a Developer (like how to talk to APIs, what version of software do what, or other developer issues), you should head to the MSDN discussion forums at
    http://social.msdn.microsoft.com/forums/en-us, and search for your product or issue.
    If you’re asking a question particularly about one of the Microsoft Dynamics products, a great place to start is here:
    http://community.dynamics.com/
    If you really think your issue is related to the subscription or the TechNet Website, and I screwed up, I apologize!  Please repost your question to the discussion forum and include much more detail about your problem, that could include screenshots
    of the issue (do not include subscription information or product keys in your screenshots!), and/or links to the problem you’re seeing. 
    If you really had no idea where to post this question but you still posted it here, you still shouldn’t have because we have a forum just for you!  It’s called the Where is the forum for…? forum and it’s here:
    http://social.msdn.microsoft.com/forums/en-us/whatforum/
    Moving to off topic. 
    Thanks, Mike
    MSDN and TechNet Subscriptions Support
    Did Microsoft call you out of the blue about your computer?
    No, they didn't.

  • Count the number of elements in comma seperated list of values

    Hello Friends,
    I have a string with comma seperated list of values say
    String v = 34343,erere,ererere,sdfsdfsdfs,4454,5454,dsfsdfsfsd,fsdfsdfsdfs,dfdsfsdfsdfs,sdsfdsf,ererdsdsd45454,fsdfsdfs
    Want to count how many elements are existing in this string .
    Thanks/Kumar

    Hi, Kumar,
    REGEXP_COUNT, which Hoek used, is handy, but it only works in Oracle 11. Which version of Oracle are you using?
    In any version of Oracle, you can count the commas by seeing how much the string shrinks when you remove them.
    LENGTH (str) + 1 - LENGTH (REPLACE (str, ',')) Can str have multiple commas in a row? What if there's nothing between consecutive commas, or nothing by whitespace? Can str begin or end with a comma? Can str consist of nothing but commas? Depending on your answers, you may have to change things. You might want
    REGEXP_COUNT ( str
                 , '[^,]+'
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and also post the results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    Always say which version of Oracle you're using.
    See the forum FAQ {message:id=9360002}

  • I want to create stored procedure which will give output rows from "values that are passed as one parameter (comma seperated) to store procedure".

    Hello,
    I want to create stored procedure which will give output rows from "values that are passed as one parameter (comma seperated) to store procedure".
    Suppose , 
    Parameter value : person 1,person2,person3 
    table structure : 
    Project Name | officers 1 | officers 2
    here, officers 1 or officers 2 may contain names of multiple people.
    expected OUTPUT : distinct list(rows) of projects where person 1 or person 2 or person 3 is either officer1 or officer 2. 
    please explain or provide solution in detail 
    - Thanks

    Hi Visakh,
    Thanks for reply.
    But the solution you provided giving me right output only if officer 1 or officer 2 contains single value , not with comma seperated value.
    Your solution is working fine for following scenario : 
    Project 
    Officers 1
    Officers 2
    p1
    of11
    off21
    p2
    of12
    off22
    with parameter : of11,off22 : it will give expected output
    And its not working in case of :
    Project 
    Officers 1
    Officers 2
    p1
    of11,of12
    off21,off23
    p2
    of12,of13
    off22,off24
    with parameter : of11,off22 : it will not give any row in output
    I need patten matching not exact match :) 
    ok
    if thats the case use this modified logic
    CREATE PROC GetProjectDetails
    @PersonList varchar(5000)
    AS
    SELECT p.*
    FROM ProjectTable p
    INNER JOIN dbo.ParseValues(@PersonList,',')f
    ON ',' + p.[officers 1] + ',' LIKE '%,' + f.val + ',%'
    OR ',' + p.[officers 2] + ',' LIKE '%,' + f.val + ',%'
    GO
    Keep in mind that what you've done is a wrong design approach
    You should not be storing multiples values like this as comma separated list in a single column. Learn about normalization . This is in violation of 1st Normal Form
    Please Mark This As Answer if it solved your issue
    Please Mark This As Helpful if it helps to solve your issue
    Visakh
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • Need help with complex query with comma seperated

    Oracle version - 11.1.0.7.0
    Consider there are two tables table1 and table2
    Key---- ID
    A ---- 1
    A ---- 2
    A---- 3
    B ---- 4
    B ---- 5
    C ---- 6
    C ---- 8
    C ---- 9
    C ---- 10
    D ---- 11
    D ---- 12
    Table2
    ID
    1
    2
    6
    8
    11
    12
    I need result as in usedID column I should get comma seperated list of ID which are in table1 and table2 and in NOTUSEDID comma seperated list of ID which are in table1 but not in table2
    Key---- USEDID---- NOTUSEDID
    A ---- 1,2 ---- 3
    B ---- null ---- 4,5
    C ---- 6,8 ---- 9,10
    D ---- 11,12 ---- null

    Hi!
    Solution for Oracle 11g:
    SELECT A.KEY,
           listagg(decode(b.id, null, null, a.id), ',') WITHIN GROUP (ORDER BY  A.ID) AS USEDID,
           listagg(decode(b.id, null, a.id), ',') WITHIN GROUP (ORDER BY  A.ID) AS NOTUSEDID
      FROM TABLE1 A
           LEFT OUTER JOIN table2 b
           ON (A.ID = b.ID)
    GROUP BY a.key;
    Solution for databases prior to Oracle 11g:
    Please note that the function wm_concat is undocumented and can't be sorted!
    SELECT A.KEY,
           wm_concat(decode(b.id, null, null, a.id)) AS USEDID,
           wm_concat(decode(b.id, null, a.id)) AS NOTUSEDID
      FROM TABLE1 A
           LEFT OUTER JOIN table2 b
           ON (A.ID = b.ID)
    GROUP BY A.KEY;I used the following test case:
    create table table1(key varchar2(255), id number);
    CREATE TABLE table2(ID NUMBER);
    insert into table1 values('A', 1);
    INSERT INTO table1 VALUES('A', 2);
    INSERT INTO table1 values('A', 3);
    INSERT INTO table1 VALUES('B', 4);
    INSERT INTO table1 VALUES('B', 5);
    INSERT INTO table1 VALUES('C', 6);
    INSERT INTO table1 values('C', 8);
    INSERT INTO table1 VALUES('C', 9);
    INSERT INTO table1 VALUES('C', 10);
    INSERT INTO table1 values('D', 11);
    insert into table1 values('D', 12);
    insert into table2 values(1);
    insert into table2 values(2);
    insert into table2 values(6);
    insert into table2 values(8);
    insert into table2 values(11);
    insert into table2 values(12);
    commit;Best regards,
    Matt
    Edited by: Matt Schulz on Oct 12, 2011 12:43 PM

  • Inserting comma seperated values

    I created a stored procedure that creates an order_id. Using this id, the products and their pricetag are inserted. Hereafter the garnishes are inserted for each product.
    Creating an order id and inserting the products and their pricetag are working. The problem is at the inserting of garnishes. 
    The data is received by parameters, and I have also created a user defined type: where garnishId holds the comma seperated ids.
    CREATE TYPE [dbo].[ppg] AS TABLE(
    [ProductId] [int] NULL,
    [PriceId] [int] NULL,
    [garnishId] [VARCHAR](MAX) NULL
    this is the stored procedure:
    ALTER PROCEDURE [dbo].[sp_create_order]
    (@userId uniqueidentifier, @productPriceGarnishes dbo.ppg READONLY, @comment varchar(250))
    AS
    BEGIN
    DECLARE @orderId int
    DECLARE @orderDetailId int
    INSERT INTO orders (user_id, confirmed,comment) values(@userId,0,@comment);
    --Select last inserted PK
    SELECT @orderId=SCOPE_IDENTITY()
    -- insert products and price tag using @orderId
    INSERT INTO order_detail (order_id, product_id,price_id)
    SELECT @orderId, p.ProductId,
    p.PriceId
    FROM @productPriceGarnishes p
    SELECT @orderDetailId=SCOPE_IDENTITY()
    -- insert garnishes using the orderDetailId
    INSERT INTO order_detail_garnish (order_detail_id,garnish_id)
    SELECT @orderDetailId, (SELECT * FROM SplitDelimiterString(p.garnishId))
    FROM @productPriceGarnishes p
    END
    RETURN @orderId
    I found a function that splits the string by a delimiter in this website:
    http://www.codeproject.com/Tips/586395/Split-comma-separated-IDs-to-ge
    Where you can retrieve the ids by this query:
    (SELECT * FROM SplitDelimiterString(p.garnishId)
    The problem is that I don't know how to add these ids with their corresponding orderDetailId, after each product is added.

    Unfortunately it appears you assume too much.  Presumably the reason you chose to define @productPriceGarnishes as a table is to support the creation of multiple rows. And you use these rows to insert into the order_detail table which has an identity
    column as the primary key (again, presumably).  So the question then becomes how do you get the identity values for ALL of the inserted rows?  You can't do that with SCOPE_IDENTITY - your code currently is designed with the assumption that there
    is only one row to be inserted.  To work around that limitation you need to use the output clause (examples can be found by searching). 
    Next comes another problem.  How do you know which identity value is assigned to which row of your table variable during the insert?  You need some sort of natural key to associate the inserted rows with the rows in the table variable.  Do
    you have one?  Before you think you do, you need to think about what restrictions are placed on the content of the table variable (if any).  Is it possible to have multiple rows with the same values for ProductId and PriceId?  Do not assume
    - you need to be certain that this is or is not a possibility.
    Assuming that the rows are unique (which simplifies things greatly), you associate the inserted order_detail rows to the table variable via something like:
    select ... from @ins_detail as ins inner join @productPriceGarnishes as ppg
    on ins.ProductId = ppg.ProductId and ins.PriceId = ppg.PriceId
    Note that @ins_detail is a table variable that you would declare and populate via the output clause. It will contain the identity values for each row that you inserted.  With that, you can then generate the rows that you need to insert into the garnish
    table by applying the results of your splitter function.  Which is a step that I'll skip for now since you have much reading and work to do. 
    Now some last comments.  I am suspicious of a column named PriceId.  That is not a good sign - price is an attribute of something and not the basis of a relationship between tables.  The use of identity columns (especially as primary keys)
    can be a problem - and this is one good example.  Based on what I've just written and its assumptions, the natural key for order_detail is (order_id, product_id, price_id) - why do you need an identity column?  Again, searching will find past
    discussions about identity columns and their usage.

  • How to store Comma Seperated Value in a File with Jsp

    Hai friends,
    I need to get all the filed values like Empname,salary ,location..........
    and at the end of jsp page i have to put a browse button when i choose a file using theis browse button the total content in the form shoud store in that file as comma seperated values.

    1. Create JSP
    2. When you click the button call the event that saves the data in CSV format
    Your question is so broad, I don't have exact answer for you.
    What have you done so far?
    The man with blues.

  • Comma Seperated Files

    I am trying to read in data from a .CSV file.
    The CSV file contains a list of questions and answers in the
    format;
    Question, option1, option2,option3,option4, correct answer
    My problem is that I can get the whole line into an array but
    I can't find a way of getting each element of the comma seperated
    file into a multi dimensioned array.
    I need to be able to use MyArray[1,1] is equal to
    Question and MyArray[1,2] is equal to
    option1 etc etc
    Hope this makes sense
    Paul

    In your routine you have two loops.
    Either one will work on thier own but as soon i nest them
    then it just stops working........
    The below data is stored as a Data.csv file (Obviously it
    contains a lot more these are the first 3 records.) **Can't count =
    4 records lol)
    ,,B,,,,Lorry,,,,,X,,,,,CC5001 ,Mark one answer,,under 7.5
    tonnes maximum authorised mass,over 7.5 tonnes maximum authorised
    mass,over 7.5 metres overall height,under 7.5 metres overall
    height,,,1111,This sign means no entry for goods
    vehicles,TS4619.eps,CC5001.gif ,Vehicle Weights and Dimensions
    ,,B,,,,Lorry,,,,,X,,,,,CC5002 ,Mark one answer,,either the
    left-hand or middle lane,only the left-hand lane,only the middle
    lane,any of the lanes,,,1111,Your lorry is over 7.5 tonnes maximum
    authorised mass. This sign means you may use,TS4545.eps,CC5002.gif
    ,Vehicle Weights and Dimensions
    ,,C,,,,Lorry,,,,,,X,,,,CC5003,Mark one answer,,30 mph,40
    mph,50 mph,60 mph,,,1111,You are driving a lorry with a maximum
    authorised mass of 7 tonnes. What is the maximum speed limit on a
    single carriageway?,,,Vehicle Weights and Dimensions
    ,,B,,,,Lorry,,,,,X,,,,,CC5004,Mark one answer,,30 mph,40
    mph,50 mph,60 mph,,,1111,What is the national speed limit on a
    single carriageway road for a rigid lorry weighing more than 7.5
    tonnes maximum authorised mass?,,,Vehicle Weights and
    Dimensions

  • How to make comma seperated file

    hi
    I have a select statement that looks like below. I want to make comma seperated file for the selected columns. How to write it?
    SELECT MM.DAL_NUMBER,
    '19-NOV-2009' as WSS_CE,
    CPN_INT,
    TRADE_DATE,
    MX_DATE "LAST_DATE",
    CUSTOMER_SPECIF CUST_GID,
    NAME_SHORT CUST_NAME_SHORT
    from my_table;
    if you could provide me with exact query.
    Thanks

    Slightly more generic approach...
    As sys user:
    CREATE OR REPLACE DIRECTORY TEST_DIR AS '\tmp\myfiles'
    GRANT READ, WRITE ON DIRECTORY TEST_DIR TO myuser
    /As myuser:
    CREATE OR REPLACE PROCEDURE run_query(p_sql IN VARCHAR2
                                         ,p_dir IN VARCHAR2
                                         ,p_header_file IN VARCHAR2
                                         ,p_data_file IN VARCHAR2 := NULL) IS
      v_finaltxt  VARCHAR2(4000);
      v_v_val     VARCHAR2(4000);
      v_n_val     NUMBER;
      v_d_val     DATE;
      v_ret       NUMBER;
      c           NUMBER;
      d           NUMBER;
      col_cnt     INTEGER;
      f           BOOLEAN;
      rec_tab     DBMS_SQL.DESC_TAB;
      col_num     NUMBER;
      v_fh        UTL_FILE.FILE_TYPE;
      v_samefile  BOOLEAN := (NVL(p_data_file,p_header_file) = p_header_file);
    BEGIN
      c := DBMS_SQL.OPEN_CURSOR;
      DBMS_SQL.PARSE(c, p_sql, DBMS_SQL.NATIVE);
      d := DBMS_SQL.EXECUTE(c);
      DBMS_SQL.DESCRIBE_COLUMNS(c, col_cnt, rec_tab);
      FOR j in 1..col_cnt
      LOOP
        CASE rec_tab(j).col_type
          WHEN 1 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_v_val,2000);
          WHEN 2 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_n_val);
          WHEN 12 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_d_val);
        ELSE
          DBMS_SQL.DEFINE_COLUMN(c,j,v_v_val,2000);
        END CASE;
      END LOOP;
      -- This part outputs the HEADER
      v_fh := UTL_FILE.FOPEN(upper(p_dir),p_header_file,'w',32767);
      FOR j in 1..col_cnt
      LOOP
        v_finaltxt := ltrim(v_finaltxt||','||lower(rec_tab(j).col_name),',');
      END LOOP;
      --  DBMS_OUTPUT.PUT_LINE(v_finaltxt);
      UTL_FILE.PUT_LINE(v_fh, v_finaltxt);
      IF NOT v_samefile THEN
        UTL_FILE.FCLOSE(v_fh);
      END IF;
      -- This part outputs the DATA
      IF NOT v_samefile THEN
        v_fh := UTL_FILE.FOPEN(upper(p_dir),p_data_file,'w',32767);
      END IF;
      LOOP
        v_ret := DBMS_SQL.FETCH_ROWS(c);
        EXIT WHEN v_ret = 0;
        v_finaltxt := NULL;
        FOR j in 1..col_cnt
        LOOP
          CASE rec_tab(j).col_type
            WHEN 1 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_v_val);
                        v_finaltxt := ltrim(v_finaltxt||',"'||v_v_val||'"',',');
            WHEN 2 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_n_val);
                        v_finaltxt := ltrim(v_finaltxt||','||v_n_val,',');
            WHEN 12 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_d_val);
                        v_finaltxt := ltrim(v_finaltxt||','||to_char(v_d_val,'DD/MM/YYYY HH24:MI:SS'),',');
          ELSE
            v_finaltxt := ltrim(v_finaltxt||',"'||v_v_val||'"',',');
          END CASE;
        END LOOP;
      --  DBMS_OUTPUT.PUT_LINE(v_finaltxt);
        UTL_FILE.PUT_LINE(v_fh, v_finaltxt);
      END LOOP;
      UTL_FILE.FCLOSE(v_fh);
      DBMS_SQL.CLOSE_CURSOR(c);
    END;This allows for the header row and the data to be written to seperate files if required.
    e.g.
    SQL> exec run_query('select * from emp','TEST_DIR','output.txt');
    PL/SQL procedure successfully completed.Output.txt file contains:
    empno,ename,job,mgr,hiredate,sal,comm,deptno
    7369,"SMITH","CLERK",7902,17/12/1980 00:00:00,800,,20
    7499,"ALLEN","SALESMAN",7698,20/02/1981 00:00:00,1600,300,30
    7521,"WARD","SALESMAN",7698,22/02/1981 00:00:00,1250,500,30
    7566,"JONES","MANAGER",7839,02/04/1981 00:00:00,2975,,20
    7654,"MARTIN","SALESMAN",7698,28/09/1981 00:00:00,1250,1400,30
    7698,"BLAKE","MANAGER",7839,01/05/1981 00:00:00,2850,,30
    7782,"CLARK","MANAGER",7839,09/06/1981 00:00:00,2450,,10
    7788,"SCOTT","ANALYST",7566,19/04/1987 00:00:00,3000,,20
    7839,"KING","PRESIDENT",,17/11/1981 00:00:00,5000,,10
    7844,"TURNER","SALESMAN",7698,08/09/1981 00:00:00,1500,0,30
    7876,"ADAMS","CLERK",7788,23/05/1987 00:00:00,1100,,20
    7900,"JAMES","CLERK",7698,03/12/1981 00:00:00,950,,30
    7902,"FORD","ANALYST",7566,03/12/1981 00:00:00,3000,,20
    7934,"MILLER","CLERK",7782,23/01/1982 00:00:00,1300,,10The procedure allows for the header and data to go to seperate files if required. Just specifying the "header" filename will put the header and data in the one file.
    Adapt to output different datatypes and styles are required.

  • Comma seperated checkboxes - add comma AND a space

    Comma seperated checkboxes has worked great for me, except for one thing. I want the values to be seperated by a comma AND a space, like so:
    This is what I get now.
    location1,location2,location3
    What I'd like to get is:
    location1, location2, location3
    Is what I want possible? If so what's the easiest way to change it?
    -Kevin

    I'm running into another problem. Your solution for displaying the locations with spaces works great when querying a single record.
    However, when I use in a repeat region, all records show the location of the first record. This problem is only present in a repeat region.
    For the repeat region, I choose a recordset called feeds to repeat. Repeating elements inside are displayed as .
    Now, $locations is in that recordet but $locations_with_spaces is not.
    Is there a way to get $locations_with_spaces to repeat properly?
    Thanks
    -Kevin

  • How to query the comma seperated values stored in Database

    Hi,
    I have a strange scenario, I am storing the specific data as a comma seperated value in the database. I want to query the DB with the comma seperated value as a Bind variable against the comma seperated value stored in DB.
    For eg : The data stored in DB has
    Row1 - > 1,2,3,4,5,6,7,8
    Row2 - > 4,5,6,7,8,9,10
    When I pas the Bind variable as '4,8' I should get Row1 and Row2 .
    Quick help his highly appreciated.. Thanks in Advance

    Oh, and if you actually wanted the data returned rather than just the row primary keys....
    SQL> ed
    Wrote file afiedt.buf
      1  with t as (select 1 as rw, '1,2,3,4,5,6,7,8' as txt from dual union all
      2             select 2, '4,5,6,7,8,9,10' from dual union all
      3             select 3, '1,6,7,9' from dual)
      4  -- end of test data
      5      ,r as (select '4,8' as req from dual)
      6  -- end of required data
      7      ,split_t as (select rw, regexp_substr(txt, '[^,]+', 1, rn) as val
      8                   from t, (select rownum rn from dual connect by rownum <= (select max(length(regexp_replace(t.txt, '[^,]'))+1) from t))
      9                   where regexp_substr(txt, '[^,]+', 1, rn) is not null
    10                  )
    11      ,split_r as (select regexp_substr(req, '[^,]+', 1, rownum) as val
    12                   from r
    13                   connect by rownum <= length(regexp_replace(req, '[^,]'))+1
    14                  )
    15  --
    16  select distinct t.rw, t.txt
    17  from   split_t st join split_r sr on (st.val = sr.val)
    18                    join t on (t.rw = st.rw)
    19* order by 1
    SQL> /
            RW TXT
             1 1,2,3,4,5,6,7,8
             2 4,5,6,7,8,9,10
    SQL>

Maybe you are looking for

  • Need help to disable input selection-screen - very urgent

    Hi SAP experts, I have a requirement where in I need to disable ( Grey out ) the input fileds on the selection screen . My problem is as I am using ABAP query I am not able to use any events ( AT SELECTION-SCREEN OUTPUT ). My selection screen looks l

  • I can't sign in to Apple store,but my Apple id is verified what i must do?

    hi everybody need your help...      i created an Apple ID everything seems ok  since it's verified,but when i try to sign in to the itunes store a message show's up and it's says'THIS APPLE ID HAS NOT YET BEEN USED WITH THE ITUNES STORE' what i must

  • Full screen widget and footer

    Hi Guys, I want to protect my footer from my full screen widget  slide show. I could put my footer in one layer and the widget in another, unfortunately in this case the footer will hide part of my slide show. I don't like this solution.  I could cre

  • Can Google be hacked by Skype extn in Chrome?

    Hi, I've been trying to get a response on various forums across the web without success. If this is a stupid question then I don't mind being told so. About a week ago my Gmail reported unusual activity from an IP address not normally associated with

  • To establish meeting with several participants

    How to establish meetings in OCS Calendar with several participants using Java?