Divide the data into several lines in the table

Hello

I use apex of Oracle 10 g 3.2.

I have a requirement like this.

I have a table like TableA

Col1 Col2
90 1
91 1:2:3
92 3

I want the data as

Col1 Col2
90 1
91 1
91 2
91 3
92 3

How to do this?

Thank you

Published by: user13305573 on August 3, 2010 20:16
with
   your_data as
(
   select 90 as col1, '1'  as col2      from dual union all
   select 91, '1:2:3'   from dual union all
   select 92, '3'       from dual
)
select
   y.col1,
   regexp_substr(y.col2, '[^:]+', 1, t1.column_value) as col2
from
   your_data y,
 13     table(cast(multiset(select level from dual connect by  level <= length (regexp_replace(y.col2, '[^:]+'))  + 1) as sys.OdciNumberList)) t1
 14  /

              COL1 COL2
------------------ -----
                90 1
                91 1
                91 2
                91 3
                92 3

5 rows selected.

Elapsed: 00:00:00.05
ME_XE?select * from v$version;

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 Linux: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production

5 rows selected.

Elapsed: 00:00:00.03
ME_XE?

Tags: Database

Similar Questions

  • How to use the checkbox to select several lines of af: table

    Hi all
    I want to use the checkbox to select several lines of af: table

    Kind regards
    Tom

    Hello

    look at this link
    http://Sameh-Nassar.blogspot.com/2009/12/use-checkbox-for-selecting-multiple.html

    Kind regards
    Felix

  • Help to extract data Clob to a column in a table that has several lines in a table

    Help to extract data Clob to a column in a table that has several lines in a table

    It works for only the first line

    CREATE or REPLACE DIRECTORY XMLDIR AS ' / orabackups';

    Grant read, write on DIRECTORY XMLDIR to the public;

    () dbms_xslprocessor.clob2file

    beef in CLOB,

    XMLDIR IN VARCHAR2,

    "testfile2.txt" IN VARCHAR2);

    DECLARE

    buf CLOB.

    BEGIN

    SELECT H15_DOC

    IN buf

    OF H15TEST. H15_STAGE

    where rownum = 1;

    dbms_xslprocessor.clob2file (buf, 'XMLDIR', 'testfile2.txt');

    END;

    /

    -This error code

    CREATE or REPLACE DIRECTORY XMLDIR AS ' / orabackups';

    Grant read, write on DIRECTORY XMLDIR to the public;

    () dbms_xslprocessor.clob2file

    XData in CLOB,

    XMLDIR IN VARCHAR2,

    "testfile2.txt" IN VARCHAR2,

    CSID in NUMBER: = 0);

    DECLARE

    CURSOR xmlmycur IS SELECT H15_DOC

    OF H15TEST. H15_STAGE

    where rownum = 102140;

    l_clob CLOB.

    XData CLOB.

    BEGIN

    DBMS_LOB.CREATETEMPORARY (l_clob, true);

    DBMS_LOB.CREATETEMPORARY (xdata, true);

    OPEN xmlmycur.

    LOOP

    SEEK xmlmycur INTO xdata;

    dbms_xslprocessor.clob2file (xdata, 'XMLDIR', 'testfile2.txt');

    EXIT WHEN xmlmycur % notfound;

    END LOOP;

    CLOSE Xmlmycur;

    END;

    /

    ORA-21560: 3 argument is null, invalid or out of range

    ORA-06512: at "SYS." DBMS_LOB", line 991

    ORA-06512: at "XDB". DBMS_XSLPROCESSOR', line 324

    ORA-06512: at line 15 level

    FYI, it seems that the file being created will exceed 5 gig

    Yes, it is a known issue with DBMS_XSLPROCESSOR.clob2file with big files.

    Here is a slightly modified version of the code that I posted earlier, fixing WRITE_ERROR except:

    DECLARE

    v_file utl_file.file_type;

    -write a unique to clob

    procedure write_clob (p_content in clob) is

    v_buffer varchar2 (32767).

    V_POSITION pls_integer: = 1;

    v_amount pls_integer: = 32767;

    Start

    loop

    Start

    DBMS_LOB. Read (p_content, v_amount, v_position, v_buffer);

    exception

    When no_data_found then exit;

    end;

    UTL_FILE.put_raw (v_file, utl_raw.cast_to_raw (v_buffer), true);

    V_POSITION: = v_position + v_amount;

    end loop;

    end;

    BEGIN

    -Open the file

    v_file: = utl_file.fopen ('TEST_DIR', 'testfile2.txt', 'wb', 32767);

    -loops through the lines

    for r in)

    Select h15_doc

    of h15test.h15_stage

    )

    loop

    write_clob (r.h15_doc);

    end loop;

    UTL_FILE.fclose (v_file);

    END;

    /

  • Comparison of the data of several rows in a table - based on the primary key

    Currently I have a select statement that returns hundreds of records.  Each returned record is linked to A NUMBER of ORDER this order number has a recipe.  (a bit like a cooking recipe).  Each recipe has many records in the database related to this order number and records should be compared to records in a table that bind to a specific primary key...  (I have already developed the logic to isolate what PK I need).  If all these records that are returned by the select statement below does not match all the records containing PK in the table below, I need to get the next PK and compare all these recordings for select statements return.

    See below for a better understanding. Need a good example detailed on how to solve my problem here.

    Just to help you understand:

    Each element of the recipe is 3 parts (side, ref_des, part_number).  1 single recipe can have several parts (where the part_number), and each of these pieces should be placed on the lower side or top of the Board that is there "side" comes into play.  Same thing with Ref_Des.

    What is going on

    Select statement returns the RECIPE of ORDER NUMBER A.  There will be multiple records returned by this query.

    Select the Return statement:

    • Side
    • Ref_Des
    • Part_Number

    Example of return:

    B c17 75145-2

    T f14 89242-8

    B s12 45123-3

    etc,

    In general - what I need to do:

    There is a table called AUTO_RECIPE_DETAILS.  I take all of the records returned by the select query above and compare for each record in this table relating to the recipe 30319-000001.  30319-000001 a number of records.  It is the primary key for a whole recipe as seen above.  This primary key is bound the number of data records in this table.  The comparison is to see if all records under RECIPE_NAME 30319 -000001 match all the records returned by the select statement.

    IF IT DOES NOT MATCH: recover the following recipe in this table below 30319 -000002 and make the same comparison.

    Here's a perfect example of what the table looks like: (AUTO_RECIPE_DETAILS)


    RECIPE_NAME SIDE REF_DES PART_NUM

    -30319-000001 C16 87595-1 B

    -30319-000002           T B14 74150-4

    -30319-000001 T B14 34251-2          

    -30319-000001            T F24 84180-7

    -30319-000002 T B12 13710-8          



    It is the solution to my original question.  By this thread, it's the right answer and I hope this helps someone who is trying to compare two arrays element-by-element.  In the end, the advice given in this thread were correct and I will be using all of your suggestions and the scrapping of this.  Thank you everyone for your help though.

    FOR index_p IN pid_recipe. FIRST... pid_recipe. LAST

    LOOP

    Result WHEN the OUTPUT = 1;

    FOR index_d IN details_recipe. FIRST... details_recipe. LAST

    LOOP

    IF (pid_recipe (index_p). SIDE = details_recipe (index_d). SIDE)

    AND (pid_recipe (index_p). REF_DES = details_recipe (index_d). REF_DES)

    AND (pid_recipe (index_p). PART_NUM = details_recipe (index_d). PART_NUM)

    THEN

    EXIT;

    ON THE OTHER

    DBMS_OUTPUT. Put_line("IT WAS NOT a MATCH");

    result: = 1;

    EXIT;

    END IF;

    END LOOP;

    END LOOP;

    DBMS_OUTPUT. Put_line('LOOP OUT');

  • divide the table based on the number of lines

    Hello

    I am trying to split a table based on the number of lines and then treat.
    Say I have a TEST_XXX table that contains 50 lines, what I would do is.
    to access multiple lines of 10. How can we achieve this?

    What I thought is, once the table is created and the line are filled.
    Add a new column to the table and perform a procedure that inserts of 1 to 10 first lines
    and 2 to 10 lines and 3 to 10 next ranks... etc. Based on this, that we can treat
    the first set of lines then play next or etc...

    is there a better way to do it?

    Code to create the table:
    CREATE TABLE TEST_XXX
    (
      A_ID   VARCHAR2(10),
      B_ID   NUMBER,
      c_ID   VARCHAR2(10),
      D_ID   NUMBER
    )
    Code to add lines:

    DECLARE
    BEGIN
      FOR I IN 1..50
      LOOP
          INSERT INTO TEST_XXX VALUES('ABCDE',123,'ZYXWV',321);
      END LOOP;
      COMMIT;
    END;
    The original problem is, I have a huge table, and I write a sql query to process,
    When I treat him by selecting all the values in the table, it is very slow.
    But when I have treat small Coulon (say 100 rows), it works very well.
    That's how I got the approach described above in mind.

    You can use NTILE.

    See:
    http://download.Oracle.com/docs/CD/B19306_01/server.102/b14200/functions101.htm#SQLRF00680
    http://asktom.Oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:47910227585839

  • Representing data of several lines into one line

    Hi all

    Please check the query below:
    select manager_id mg_id, employee_id emp_id, last_name name from employees 
    where manager_id = '100'
    and DEPARTMENT_ID = '80'
    If I run the following query, o/p then comes wise line; as below:
           mg_id           emp_id            name
           100             145                     Russell
           100             146                     Partners
           100             147                     Errazuriz
           100             148                     Cambrault
           100             149                     Zlotkey
    But if I want the o/p as below; That is to say; under Manager # 100, all employees emp_id and name should come in ONE row NOT in several lines:
    mg_id                   emp_id     name          emp_id       name       emp_id     name         emp_id     name                emp_id         name
    100                             145             Russell     146       Partners        147     Errazuriz       148              Cambrault        149        Zlotkey
    pls help me sort the above desired o/p.

    kindly tell me if there are guidelines of accounting (except 'Plain Text help' on the right side) in this forum. I tried a lot of post above 2 o/p in easy to read format, but could not do so.

    Published by: Francis Sep 20, 2009 04:28

    Published by: Francis Sep 20, 2009 04:29
  • ETL - split manually entered data on several lines

    Hi people. The question of an experienced Oracle semi programmer...

    I'm looking for some advice on an elegant solution and/or good performance for a lot of food data our database Oracle (10 g R2).

    The source data are entered manually and contains invalid entries. More important, a good percentage of the data contains several purchase order numbers into one field in the source, for example ("123456789, 987654000, 987654003, 987654006, 4008-4010').

    In the destination table, I want each of these purchase orders to be its own record.

    Any thoughts on a good approach to this? I read a few articles on Asktom.com on the 'pipeline functions', but since it is done on the back-end (client only comes into play until after I confirmed the results), I didn't know if I could derive all the benefits of lines own 'pipes' to a single DML vs coating DML statement in my PL/SQL.

    The database "at a distance" from the source is also Oracle 10 g 2, if that matters.

    I recently discovered how elegantly I could go the other way - compilation of the string fields to multiple records in a single string concatenated to the destination folder using analytical functions. Could take a PL/SQL process that ran for almost half an hour up to seconds in a single SQL statement. = D

    Hoping maybe one of the experts can point me in the right direction here. Thanks in advance for any advice you can offer.
    with t1 as (
                select '100000,100,103,105-109' str from dual union all
                select '200000,200,203,205-209' str from dual
               ),
         t2 as (
                select  str,
                        regexp_substr(str,'[^,]+') first_element,
                        column_value element_number,
                        regexp_substr(str,'[^,]+',1,column_value) element
                  from  t1,
                        table(cast(multiset(select level from dual connect by level <= length(regexp_replace(str || ',','[^,]'))) as sys.odciNumberList))
               ),
         t3 as (
                select  str,
                        first_element,
                        element_number,
                        element,
                        regexp_substr(element || '-' || element,'[^-]+') start_sub_element,
                        regexp_substr(element || '-' || element,'[^-]+',1,2) end_sub_element
                  from  t2
               )
    select  str,
            case element_number
              when 1 then to_number(first_element)
              else to_number(first_element) + to_number(start_sub_element) + column_value - 1
            end val
      from  t3,
            table(cast(multiset(select level from dual connect by level <= end_sub_element - start_sub_element + 1) as sys.odciNumberList))
    /
    
    STR                           VAL
    ---------------------- ----------
    100000,100,103,105-109     100000
    100000,100,103,105-109     100100
    100000,100,103,105-109     100103
    100000,100,103,105-109     100105
    100000,100,103,105-109     100106
    100000,100,103,105-109     100107
    100000,100,103,105-109     100108
    100000,100,103,105-109     100109
    200000,200,203,205-209     200000
    200000,200,203,205-209     200200
    200000,200,203,205-209     200203
    
    STR                           VAL
    ---------------------- ----------
    200000,200,203,205-209     200205
    200000,200,203,205-209     200206
    200000,200,203,205-209     200207
    200000,200,203,205-209     200208
    200000,200,203,205-209     200209
    
    16 rows selected.
    
    SQL> 
    

    SY.

  • 1 line into several lines

    I have a table time_entries
    create table time_entries 
    (employee_id integer, 
    start_date date, 
    end_date date, 
    CONSTRAINT pk_time_entries PRIMARY KEY (employee_id, start_date))
    Suppose I have a line in this table (date in the format yyyy-mm-dd):

    Employee_ID, start_date, end_date
    -------------------------
    1, 2012-08-27, 2012-09-02


    As you can see the difference between dates is 7 days. I want to write a query so that each day has its own line, that is, I want to write a query that translates into 1 line above 7 rows. This is the result set, I want:

    Employee_ID, start_date, end_date
    -------------------------
    1, 2012-08-27, 2012-08-27
    1, 2012-08-28, 28-08-2012
    1, 2012-08-29, 2012-08-29
    1, 2012-08-30, 2012-08-30
    1, 2012-08-31, 2012-08-31
    1, 2012-09-01, 2012-09-01
    1, 2012-09-02, 2012-09-02

    Is it possible to do it in a select statement?

    Published by: srhcan on August 17, 2012 16:26

    Published by: srhcan on August 17, 2012 16:26

    srhcan wrote:

    BluShadow wrote:

    srhcan wrote:
    I expect a generic SQL solution that can run on databases other suppliers as well.

    This is not good design. Different databases have different ways of doing things for the best performance, etc. You are advised to use the best data, you write the query and does not focus on making things way 'generic '. This way you could design a "database layer" (aka the database layer) specific to each database.

    I agree with your point of view. But the system, I'm currently train do not have a DAO layer for each type of database. All SQLs are coded in the business layer, and this is why all these SQLs are generic SQLs.

    Then you must accept this run of things in this code will be more difficult to do, probably more code involved and may not be as effective as it could be. As they say... sh! design t = sh! application of t.

  • Apex 4 Add several lines in a table

    Hello

    I use Apex 4.0 and I'm trying to view multiple empty lines in tabular form, when a page loads.

    Instead of having the click of the button 'Add Row' user, I want to display a few blank on the page if the table contains data or not.

    Examples or ideas on how to do that?

    Marsha

    Put this in the "run when the Page loads"
    ::AddRow();
    ::AddRow();
    ...
    (the number of lines that you want to add).

  • topics in several lines in a table view - is this possible?

    My needs is the ability to graphically to group columns and assign common positions, for example my Business Model r_gion measures for

    'expenses actual city', 'forecasts city', "expenses actual city B", 'forecasts city B', ' report Actuals A / B ","city of actual spending C.

    I want to show exactly these measures in the form of columns in my table, BUT there should be a common topic 'A city' for the first two columns and then "city B" during the third and fourth column.

    is - it somehow possible? can I somehow combine my columns without using pivot ('City' as a dimension in the "columns" of the pivot section would be an option if I didn't have the last two columns, I think..?)

    Did you read my post carefully? In Table view, you have the opportunity to present the position of the Table and ColumnHeadings. To do this, click on the view of the Table Properties button and click on the "Display Table and column headers" drop-down and select 'as of the separate lines."

    Now do what I said above. So for actual expenditures and forecasts from City A, click the button properties of these two columns, select the checkbox "headings"Custom"in column Format tab edit and change the title of the Table" town. "for the column header, you must change it in the"real"and"Forecast", respectively."

    Seen in a display table and you will have your multiline headers.

  • updated several lines in a table table anthor

    I need to transfer all coloumn table full_name 'name_f' in coloumn full_name lines in the table "new_osama".


    Update new_osama t
    Define full_name = (select full_name of name_f u
    where u.EMP_CODE = t.emp_code
    and t.full_name is null)

    It back
    ERROR on line 2:
    ORA-01427: einreihig subquery returns multiple rows
    update new_osama t
    set full_name=(select full_name from name_f u
    where u.EMP_CODE=t.emp_code
    and t.full_name is null and rownum = 1)
    

    Table of"name_f" have repeat lines for some 'emp_code '.

    select count(emp_code) from name_f;
    /
    select count(distinct emp_code) from name_f;
    /
    
  • Divide a line into several lines based on the amount

    Dear all,

    Please provide a solution for this scenario.

    The query...

    Select line_id, component, sizes, quantity of sales_tab;

    and the result...

    LINE_IDCOMPONENTSIZESQUANTITY
    8BODYSMALL214.33
    4BODYMEDIUM187.89
    1BODYLARGE230.87
    7BODYEXTRA LARGE205.03
    3BODYXX LARGE148,52
    2SLEEVESMALL197.57
    6SLEEVEMEDIUM176.4
    5SLEEVELARGE193.8
    10SLEEVEEXTRA LARGE184.87
    9SLEEVEXX LARGE138.53

    Business rule: for all rows where the quantity is greater than 200, generate a new identical line with quantity = quantity - 200 like - we. This is the quantity of each line must not exceed 200.

    The required result is...

    LINE_IDCOMPONENTSIZESQUANTITY
    8BODYSMALL200
    8BODYSMALL14.33
    4BODYMEDIUM187.89
    1BODYLARGE200
    1BODYLARGE30,87
    7BODYEXTRA LARGE200
    7BODYEXTRA LARGE5.03
    3BODYXX LARGE148,52
    2SLEEVESMALL197.57
    6SLEEVEMEDIUM176.4
    5SLEEVELARGE193.8
    10SLEEVEEXTRA LARGE184.87
    9SLEEVEXX LARGE138.53

    Thank you

    Usman

    Use:

    Select line_id,

    component,

    sizes,

    amount of column_value

    of sales_tab.

    table)

    cast)

    MultiSet)

    Select less (200, - 200 quantity * (level - 1))

    of the double

    connect in quantity > 200 * (level - 1)

    )

    as sys. OdciNumberList

    )

    )

    order of line_id,

    amount desc

    /

    For example:

    SQL > with sales_tab like)
    2 Select line_id 8, component 'Body', 'SMALL' amount 214.33 of all sizes the double union
    3. Select 4, 'BODY', 'WAY', 187.89 double Union all
    4 Select 1, 'BODY', 'LARGE', 230.87 double Union all
    5. Select 7, 'BODY', 'EXTRA LARGE', 205.03 double Union all
    6 select 3, 'BODY', 'XX-LARGE', 148,52 of double union all
    7. Select 2, 'CHANNEL', 'SMALL', 197.57 double Union all
    8. Select 6, 'CHANNEL', 'WAY', 176.4 from dual union all
    9. Select 5, 'ROUND', 'BIG', 193.8 double Union all
    10. Select 10, 'ROUND', 'EXTRA LARGE', 184.87 double Union all
    11. Select 9, 'ROUND', 'XX-LARGE', double 138.53
    12                  )
    13. Select line_id,
    14 components,
    15 sizes,
    amount of 16 column_value
    sales_tab 17,
    Table 18)
    19 mount)
    (20) type multiset
    21 select less (200, - 200 quantity * (level - 1))
    22 double
    23 connect quantity > 200 * (level - 1)
    24                            )
    25 as sys. OdciNumberList
    26                    )
    27              )
    28 order of line_id,
    29 quantity desc
    30.

    LINE_ID COMPON QUANTITY SIZES
    ---------- ------ ----------- ----------
    1 BODY 200 GRAND
    1 BODY GRAND 30,87
    2 SLEEVES SMALL 197.57
    3 BODY XX LARGE 148,52
    4 WAY 187.89 BODY
    5 SLEEVES 193.8 GRAND
    SLEEVE 6 MEANS 176.4
    7 BODY 200 EXTRA-LARGE
    7 BODYWORK 5.03 EXTRA-LARGE
    8 200 SMALL BODY
    8 BODY SMALL 14.33

    LINE_ID COMPON QUANTITY SIZES
    ---------- ------ ----------- ----------
    CHANNEL 9 XX GRAND 138.53
    10 SLEEVES EXTRA-LARGE 184.87

    13 selected lines.

    SQL >

    SY.

  • Serialize the data into several messages from serial port

    Hello

    My current LabVIEW project, I want to read data from the serial port and store the (transformed) response in a file.

    Since my design model is based arround the Manager of messages queued waiting my serial communication is also build around that. (see this post for my original question).

    But now I have the following problem:

    In the loop 1 I put several messages in the queue of loop 2.

    Loop 2 processes these messages and sends them to the print queue of loop 1.

    Loop 1 gets several messages that need to be combined into 1 string and (with other data) in a file.

    Just to clarify:

    Loop 1, I have send 3 messages for each connected device. Even though I have a separate file for each device, the response to the messages must be in 1 result string.

    (Note on the picture: there are other loops running at the same time you will also need to access the serial port for the port for loop 1 is not an option)

    Hope you can help.

    A next attempt to download the code

    The attached Code is provided as is. It has not been tested or validated as a product for use in a deployed application or system, or for use in dangerous environments. You assume all risk for use of the Code and the use of the Code is subject to the license terms of Sample Code which can be found at: http://ni.com/samplecodelicense

  • Insert data into a line that already has PK

    I inserted all my key primary data in a table, when I try and enter data in the rest of the columns I get a "cannot insert NULL in error".

    How can I get into the rest of the data columns for the same line?  Thank you.

    Insert into site_managers (sm_name, office_id, SM_phone, SM_email, manager_ID, INVOCIE_NUM, Workorder_NUM, FACID)

    values ('Jessica', ' 001 ', ' 8132156688',' [email protected]', '0056919', ' k-4490', ' 2014-53-4456', '538624156' ")

    I don't know why first of all, you must insert the PK and then update all the other columns, but you can update multiple columns at the same time as:

    Update site_managers

    Set sm_name = "Jessica Stulginski",

    office_id = '001',

    SM_phone = '8132156688',

    ...

    Where site_manager_id = '0056913';

    John

  • Hyperion Financial Reporting: Recover data from several lines of another grid

    Hey geniuses,.

    Don't know if this is the right place to ask questions on HFR...

    I have two grids: welcome and support. I tried to recover data supporting the grid, where there are 10 children report derived from a line of HFR lines. I intended to show all children of 10 lines in the report. I tried ".row grid [X] [X]" to recover data and < < MemberName > > to retrieve the name of the project, but only one line is presented in the main with the first name of line project (grid support) and report data sum of the total 10 rows (grid support).

    All good ideas?

    Thanks to a bouquet.

    Instead of the formula line insert a line of text and add the function

    >
    >
    >
    .....................................................

    The problem should be solved

    Concerning

    Celvin

    http://www.orahyplabs.com

Maybe you are looking for

  • Satellite Pro L670 - 11 d and Dynadock U10 problem re-docking station

    This my first post on this forum - I hope I have the right category. We have a user with a Satellite Pro L670 - 11 d attached to a port replicator Dynadock U10 USB. Everything seems fine, except when press us the disconnect button (or select eject Do

  • Jet Office Pro 8500 will not be printed via wireless network.

    All of a sudden, my printer does not print anything from any of my devices. Just print items get saved in the queue. The printer is connected to the router, all configuration and test pages that it's good and ready. I have windows 7.

  • 15 - r045TX: controller / PCI device Driver networks

    I'm having a problem with controller network & PCI device Drivers I get a msg tat - the drivers for this device are not installed When I looked up the solution install the airline pilot, I failed so please give me the solution for issues tis. PRODUCT

  • Vista Code 80072efe

    Have a HP DV9429US with Vista Home Premium 32 bit Service Pack 2 and I could not update for a while now.  I had various problems of recent virus, even if I run the Microsoft Security Essentials, which was not able to update or another.  I used Malwar

  • My speakers are having abuzzing sound in the background, what can be?

    My speakers just started humming and the volume is low I can mount the speakers but it still sounds low. I blew my speakers?