Divide the line into several columns

Hi all

I have a question where I want to divide the line into multiple columns based on the delimiter ' |'.

Staging of Table structure: People_STG, I have people in it.

Create table People_STG(col1 varchar2(4000));


Insert into People_STG(Emp_id|) User name | FirstName. LastName. JobTitle | hire_date | Location_id)


SELECT REGEXP_SUBSTR ( COL1, '[^,|]+', 1, 1) EMP_ID,
       REGEXP_SUBSTR ( COL1, '[^|]+', 1, 2) USERNAME,
       REGEXP_SUBSTR ( COL1, '[^,|]+', 1, 3) FIRSTNAME,
       REGEXP_SUBSTR ( COL1, '[^,|]+', 1, 4) LASTNAME,
       REGEXP_SUBSTR ( COL1, '[^,|]+', 1, 5) JOBTITLE,
       REGEXP_SUBSTR ( COL1, '[^,|]+', 1, 6) HIRE_DATE,
       REGEXP_SUBSTR ( COL1, '[^,|]+', 1, 7) LOCATION_ID
FROM PEOPLE_STG
WHERE length(regexp_replace(COL1, '[^|]', '')) = 14;

But I am facing a problem here, as in some lines, function is null, but when I run the above query, it is not recognizing the empty element and inserting Hire_date values of function and location_id in Hire_date where function is null.

for example: 1 | akash51 | Akaksh | C | 22/11/14 | 15

Here the function is null, so when I run top to divide query it will insert 11/22/14 in the function column and 15 in Hire_Date.

Please need help on this one.

Oracle Version: 11.2 g

Thanks in advance,

Akash.

There are different techniques to cope with this.  Is a simple...

SQL > ed
A written file afiedt.buf

1 with t as (select 1 | akash51 |) Akaksh | C | 22/11/14 | 15' as col1 of union double all the
2 Select 2 | akash52 | Akaksh | C | Jobs jobs | 23/11/14 | 15' of the double
3            )
4  --
5. end of test data
6  --
7 select trim (REGEXP_SUBSTR (COL1, ' [^, |] +', 1, 1)) EMP_ID,.
8 toppings (REGEXP_SUBSTR (COL1, ' [^, |] +', 1, 2)) USERNAME,.
9 garnish (REGEXP_SUBSTR (COL1, ' [^, |] +' 1, 3)) FIRSTNAME,
10 pads (REGEXP_SUBSTR (COL1, ' [^, |] +' 1, 4)) LASTNAME,.
11 garnish (REGEXP_SUBSTR (COL1, ' [^, |] +' 1, 5)) JOBTITLE,.
12 pads (REGEXP_SUBSTR (COL1, ' [^, |] +', 1, 6)) HIRE_DATE,.
13 garnish (REGEXP_SUBSTR (COL1, ' [^, |] +' 1, 7)) location_id
14 * from (select replace (col1, ' |)) ',' | as col1 of t)
SQL > /.

EMP_ID USERNAME FIRSTNAME LASTNAME, JOBTITLE HIRE_DATE LOCATION_I
---------- ---------- ---------- ---------- ---------- ---------- ----------
1 akash51 Akaksh C 22/11/14 15
2 akash52 Akaksh C Job 23/11/14 15

Tags: Database

Similar Questions

  • divide a line into several columns

    Hi all

    I have a csv file with the information that looks like

    Dispatch_id/vendor_id

    --------------------------------

    1234/111

    1234/333

    1234\222

    1 234 111

    1234 111

    "1234/111.

    1234/111

    I want the output to be

    Vendor_id Dispatch_id

    --------------------------------------------

    1234 111

    333 1234

    222 1234

    1234 111

    1234 111

    1234 111

    1234 111

    I tried to use REGEXP_SUBSTR like this:

    SELECT REGEXP_SUBSTR('1234/111','[^/]+') DISPATCH_ID,

    VENDOR_ID REGEXP_SUBSTR('1234/111','[^/]+',1,2)

    BY DOUBLE D

    and I got the output

    Vendor_id Dispatch_id

    --------------------------------------------

    1234 111

    What is good!

    But my problem is that I have different delimiters in each line (example: ' \ ',' ',' ', "',)

    How can I mention all these delimiters in query REGEXP_SUBSTR?

    Or

    Is there another way I can write a simple query?

    Please help me!

    1058268 wrote:

    Hi all

    I have a csv file with the information that looks like

    Dispatch_id/vendor_id

    --------------------------------

    1234/111

    1234/333

    1234\222

    1 234 111

    1234 111

    "1234/111.

    1234/111

    I want the output to be

    Vendor_id Dispatch_id

    --------------------------------------------

    1234 111

    333 1234

    222 1234

    1234 111

    1234 111

    1234 111

    1234 111

    I tried to use REGEXP_SUBSTR like this:

    SELECT REGEXP_SUBSTR('1234/111','[^/]+') DISPATCH_ID,

    VENDOR_ID REGEXP_SUBSTR('1234/111','[^/]+',1,2)

    BY DOUBLE D

    and I got the output

    Vendor_id Dispatch_id

    --------------------------------------------

    1234 111

    What is good!

    But my problem is that I have different delimiters in each line (example: ' \ ',' ',' ', "',)

    How can I mention all these delimiters in query REGEXP_SUBSTR?

    ...

    Sure.

    "[^ /]" refers to all characters except ' / ' "

    ' [^ /------"]': the set of all characters except" / ', ' \' "' (single quote) or" "(space).  So, if you can list all the possible delimiters, just put them all inside square brackets, like this:

    SELECT REGEXP_SUBSTR (combined_id, "[^ / \"]' 1, 1 ") AS dispatch_id - omit the last 2 arguments, if you want

    , REGEXP_SUBSTR (combined_id, "[^ / \"]', 1, 2 ") AS vendor_id

    FROM table_x;

    If you would care to post CREATE TABLE and INSERT instructions for some examples of data, then I could test it.

    If it's easier to display the characters which may not be delimiters, then lose the ^ right after ' ['.]  For example

    "[0123456789]" which is equivalent to

    '[0-9]' and is also equivalent to

    "[[: digit:]]"

  • Divide the lines into different columns

    HRCM_RECRUITMENT_NO amount facilities
    R000035 MONEY, FOOD, BASIC 0,0,0

    I did the result like this


    Now, I want to like this


    HRCM_RECRUITMENT_NO facilities Facilities_1 Facilities_2 amount Amount_1 Amount_2

    R000035. CASH FOOD BASIC 0 0 0


    Please help me! Tell me what to do?

    Hello
    This will not work unless you have constant facilities for all HRCM_RECRUITMENT_NO.

    SQL> with h as
      2  (select 'R000035' HRCM_RECRUITMENT_NO ,'CASH,FOOD,BASIC' Facilities ,'0,0,0' Amount from dual) 
    
      3  select HRCM_RECRUITMENT_NO,regexp_substr(Facilities,'[^,]+',1,1) f1,
      4         regexp_substr(Facilities,'[^,]+',1,2) f2,
      5         regexp_substr(Facilities,'[^,]+',1,3) f3,
      6         regexp_substr(Amount,'[^,]+',1,1) A1,
      7         regexp_substr(Amount,'[^,]+',1,2) A2,
      8         regexp_substr(Amount,'[^,]+',1,3) A3
      9  from h;
    
    HRCM_RE F1   F2   F3    A A A
    ------- ---- ---- ----- - - -
    R000035 CASH FOOD BASIC 0 0 0
    

    Twinkle

  • Divide a line into several points

    I see that I can use SDO_LRS. SPLIT_GEOM_SEGMENT to divide a line into one only point (and get 2 lines resulting).

    However, someone at - it an idea how can I split a line, at several points, in several segments? I need to do for the number of lines, so a function or procedure would be nice as appropriate.

    Thank you

    Published by: ronnie-m on April 22, 2013 04:43

    Sorry for pasting quick and dirty, was a minimum on time and problems with my dev env.

    Perhaps still not the best outline but hoping there more explanaition should be ok.

    Concerning

    Luke

    select l.line_id,                                                                                                                                         -- line line_id
            ROW_NUMBER() OVER (PARTITION BY l.line_id order by l.rowid )                                                                              -- optional sub id, to make submains unique in combination with line_id (guess this will be ordered
            sdo_lrs.CLIP_GEOM_SEGMENT(SDO_LRS.CONVERT_TO_LRS_GEOM(l.geometry ), branch_measure, branch_next_measure, 0.05)              -- actual clipping, needs convert to LRS apparently, start end end branch measure
            from
                   line l,                                                                                                                                            -- rejoin mainly to get the geometry again
                             (
                             select line_id,                                                                                             -- line_id
                                     branch_measure,                                                                                                              -- measure of the branches (from CASE WHEN
                                     LEAD(branch_measure, 1, 0) OVER (PARTITION BY line_id order by branch_measure) branch_next_measure   -- Analytical function LEAD will get the next branch measure form the following ordered records per line_id
                             from
                                  (
                                  select a.line_id,                                                                                                              -- line_id
                                          CASE when                                                                                                              -- CASE (assuming branch will touch only at one point) it will be either the start or the endpoint
                                                      sdo_lrs.find_offset(                                                                    -- of the branch that will TOUCH, we are checking this based on the offset which one is closest
                                                                               SDO_LRS.CONVERT_TO_LRS_GEOM(a.geometry),                                   -- requires convert to LRS geom
                                                                               sdo_lrs.geom_segment_start_pt(b.geometry),                                   -- if it is neccessary to deal with multiple possibilities we might better use a temp table to evalute better
                                                                               0.05                                                                                -- TOLERANCE (all tolereance should be seen with respect to resolution of the data
                                                                               )                                                                   -- IF feasible, let spatial take care of the snapping
                                                      <
                                                      sdo_lrs.find_offset(
                                                                               SDO_LRS.CONVERT_TO_LRS_GEOM(a.geometry),
                                                                               sdo_lrs.geom_segment_end_pt(b.geometry),
                                                                               0.05
                                                                               )
                                            THEN
                                                 sdo_lrs.find_measure(
                                                                           SDO_LRS.CONVERT_TO_LRS_GEOM(a.geometry),
                                                                           sdo_lrs.geom_segment_start_pt(b.geometry),
                                                                           0.05
                                                                           )
                                            ELSE sdo_lrs.find_measure(
                                                                            SDO_LRS.CONVERT_TO_LRS_GEOM(a.geometry),
                                                                            sdo_lrs.geom_segment_end_pt(b.geometry),
                                                                            0.05)
                                              END branch_measure
                                  from line a, line b                                                                                                      -- self join using main and branch that touches
                                       WHERE sdo_relate(b.geometry, a.geometry, 'mask=TOUCH') = 'TRUE'                                     -- Should be replaceable with sdo_join + self join optimsation
                                       AND a.line_type = 'main'
                                       AND b.line_type = 'branch'
                                  union all                                                                                                                        -- union all to get the 0 measure (startpoint) in the subquery as the beginning of the first clipping segment
                                       select line_id, 0 as branch_measure
                                       from line
                                  union all                                                                                                                         -- union all to get the last measure (endpoint) in the subquery as the beginning of the first clipping segment
                                       select line_id,
                                                 sdo_geom.sdo_length(geometry, 0.05) as branch_measure                                                  -- maybe better to use actual get measure form lrs endpoint but is the same if no spaecial measure are used
                                       from line
                                  )
                             ) b
                             where
                             branch_measure < branch_next_measure                                                                                          -- avoid duplicates (2 branches at same location on main (but also the last + 1 segment with last measure and default value 0 from LEAD
                             and
                             l.line_id = b.line_id                                                                                                              -- join on line-id to reuse the geom (or potential other attributes from original lines
                             ;
    
  • 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.

  • How to divide a line into several posts based on the period.

    Hello

    I have data from the table like this:

    Project EMP_ID Date_Assignment Date_Expiry EMP_TYP

    P001 1000 1 JUNE 2015 30 JUNE 2015 D

    P001 1001 1 JULY 2015 31 JULY 2015 D

    1002 1 AUGUST 2015 31 AUGUST P001 2015 D

    P001 2000 01 - JUN - 2015 31-DEC-9999 M

    The report of three developers to the Manager during their own lifetime. I want the corresponding duration of Manager for each of them:

    Project EMP_ID Date_Assignment Date_Expiry EMP_TYP

    P001 1000 1 JUNE 2015 30 JUNE 2015 D

    P001 1001 1 JULY 2015 31 JULY 2015 D

    1002 1 AUGUST 2015 31 AUGUST P001 2015 D

    P001 2000 1 June 2015 M June 30, 2015

    P001 2000 July 1, 2015 M July 31, 2015

    P001 2000 31 August 1, 2015-AUG - 2015 M

    P001 2000 M 01-SEP-2015 31-DEC-9999

    For the last span (01-SEPT.-15 to 31 - DEC-9999) there is no developer reporting to the Manager.

    How in Oracle 11 g?

    Post edited by: 2808486

    The date ranges developers will never overlap? If so, what would happen?

    Your desired results can be achieved like this, but I don't think it makes a lot of sense:

    SELECT emp_id, date_assignment, date_expiry, emp_typ

    WCP

    WHERE emp_typ = '

    UNION ALL

    SELECT em.emp_id, ed.date_assignment, ed.date_expiry, em.emp_typ

    Ed, em emp EMP

    WHERE ed.emp_typ = '

    AND em.emp_typ = am'

    UNION ALL

    SELECT em.emp_id, MAX (ed.date_expiry) + 1, TO_DATE (31-DEC-9999 ',' mon-dd-yyyy ""), em.emp_typ

    EMP ed, emd em

    WHERE ed.emp_typ = '

    AND em.emp_typ = am'

    GROUP BY em.emp_id

    ORDER BY 4.2

  • 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?
    
  • Divide the class into several classes (simple fix I think)

    Here's the class, images and library for blueJ in a .rar file:
    http://www.mediafire.com/file/467dunvcmtfd67f/Ucigame_pong.rar

    If you don't use blueJ or want just the code, it's just a class:
    import ucigame.*;
    
    public class Pong extends Ucigame
    {
        Sprite ball;
        Sprite paddle;
    
        public void setup()
        {
            window.size(250, 250);
            window.title("Pong");
            framerate(30);
    
    
            Image bkg = getImage("images/background.png");
            canvas.background(bkg);
    
            ball = makeSprite(getImage("images/ball.gif", 255, 0, 0));
            paddle = makeSprite(getImage("images/paddle.png"));
    
            ball.position(canvas.width()/2 - ball.width()/2,
                          canvas.height()/2 - ball.height()/2);
            ball.motion(6, 3);
            paddle.position(canvas.width() - paddle.width() - 10,
                           (canvas.height() - paddle.height()) / 2);
        }
    
        public void draw()
        {
            canvas.clear();
    
            ball.move();
            ball.bounceIfCollidesWith(paddle);
            ball.bounceIfCollidesWith(TOPEDGE, BOTTOMEDGE, LEFTEDGE, RIGHTEDGE);
            paddle.stopIfCollidesWith(TOPEDGE, BOTTOMEDGE, LEFTEDGE, RIGHTEDGE);
    
            paddle.draw();
            ball.draw();
        }
    
        public void onKeyPress()
        {
            // Arrow keys and WASD keys move the paddle
            if (keyboard.isDown(keyboard.UP, keyboard.W))
                paddle.nextY(paddle.y() - 2);
            if (keyboard.isDown(keyboard.DOWN, keyboard.S))
                paddle.nextY(paddle.y() + 2);
            if (keyboard.isDown(keyboard.LEFT, keyboard.A))
                paddle.nextX(paddle.x() - 2);
            if (keyboard.isDown(keyboard.RIGHT, keyboard.D))
                paddle.nextX(paddle.x() + 2);
        }
    }
    and the library: http://ucigame.org/ucigame-source.zip

    All I want to do is have the Pong class call setup() and draw() onkeypress() of different classes. Or is it better that way? There is no main() or run() class the way ucigame makes the examples.

    Thank you
    Joey

    This isn't necessarily the best solution because I don't know all the details of your project, but if you wanted to put methods in a separate class and call them from the main() in the class of Pong method, you might do the following

    import ucigame.*;
    
    public class Pong extends Ucigame
    {
        public static voic main(String args[]){
            GameUtil gameUtilClass = New GameUtil();
    
            gameUtilClass.setup();
            gameUtilClass.draw();
            gameUtilClass.onKeyPress();
    
        }
    }
    
    // new class to hold methods
    public class GameUtil
    {
        Sprite ball;
        Sprite paddle;
    
        public void setup()
        {
            window.size(250, 250);
            window.title("Pong");
            framerate(30);
    
            Image bkg = getImage("images/background.png");
            canvas.background(bkg);
    
            ball = makeSprite(getImage("images/ball.gif", 255, 0, 0));
            paddle = makeSprite(getImage("images/paddle.png"));
    
            ball.position(canvas.width()/2 - ball.width()/2,
                          canvas.height()/2 - ball.height()/2);
            ball.motion(6, 3);
            paddle.position(canvas.width() - paddle.width() - 10,
                           (canvas.height() - paddle.height()) / 2);
        }
    
        public void draw()
        {
            canvas.clear();
    
            ball.move();
            ball.bounceIfCollidesWith(paddle);
            ball.bounceIfCollidesWith(TOPEDGE, BOTTOMEDGE, LEFTEDGE, RIGHTEDGE);
            paddle.stopIfCollidesWith(TOPEDGE, BOTTOMEDGE, LEFTEDGE, RIGHTEDGE);
    
            paddle.draw();
            ball.draw();
        }
    
        public void onKeyPress()
        {
            // Arrow keys and WASD keys move the paddle
            if (keyboard.isDown(keyboard.UP, keyboard.W))
                paddle.nextY(paddle.y() - 2);
            if (keyboard.isDown(keyboard.DOWN, keyboard.S))
                paddle.nextY(paddle.y() + 2);
            if (keyboard.isDown(keyboard.LEFT, keyboard.A))
                paddle.nextX(paddle.x() - 2);
            if (keyboard.isDown(keyboard.RIGHT, keyboard.D))
                paddle.nextX(paddle.x() + 2);
        }
    
    }
    

    Methods should not really have a class for each of them.

    Published by: JDScoot on May 23, 2011 15:33

  • only get a single photo on board contact despite the selection of several columns.

    When you select the photo and contact sheet then, there is only a single photo in the upper left column. Unable to get several copies despite the selection of several columns.

    The contact sheet shows only the photos you selected in the library before going to the page of Contacts.

    If you want to have multiple copies of the same image, you need to duplicate this image enough times so that you get the number you want on the contact page.  Select the thumbnail and use the key combination command + D to duplicate the photo.

    Select all duplicate images, and then go to the Contacts option in the printing process.

  • divide a column value and insert it into several columns

    Hello
    am new to plsql.
    I want to divide a characters in a column and insert into multiple columns

    I tried the function substr used the symbol ',' vary its place dynamically, so I can't apply the substr function.


    for example: before split
    col1:
    col2:
    COL3:
    COL4:
    colu5: adsdf, fgrty, erfth, oiunth, okujt



    after separation

    col1: adsd
    col2: fgrty
    COL3: erfth
    COL4: oiunth
    col5: adsdf, fgrty, erfth, oiunth, okujt



    can someone help me

    Thank you

    Published by: 800324 on December 23, 2010 08:28

    Published by: 800324 on December 23, 2010 08:36

    What:

    SQL> create table t
      2  (col1 varchar2(30)
      3  ,col2 varchar2(30)
      4  ,col3 varchar2(30)
      5  ,col4 varchar2(30)
      6  ,col5 varchar2(30)
      7  );
    
    Table created.
    
    SQL> insert into t (col5) values ('adsdf,fgrty,erfth,oiunth,okujt');
    
    1 row created.
    
    SQL> insert into t (col5) values ('x,y');
    
    1 row created.
    
    SQL> insert into t (col5) values ('a,b,c,d');
    
    1 row created.
    
    SQL> select * from t;
    
    COL1                           COL2                           COL3                           COL4                           COL5
    ------------------------------ ------------------------------ ------------------------------ ------------------------------ ------------------------------
                                                                                                                                adsdf,fgrty,erfth,oiunth,okujt
                                                                                                                                x,y
                                                                                                                                a,b,c,d
    
    3 rows selected.
    
    SQL>
    SQL> merge into t a
      2  using ( with t1 as ( select col5||',' col5
      3                       from   t
      4                     )
      5          select substr(col5, 1, instr(col5, ',', 1, 1)-1) col1
      6          ,      substr(col5, instr(col5, ',', 1, 1)+1, instr(col5, ',', 1, 2)- instr(col5, ',', 1, 1)-1) col2
      7          ,      substr(col5, instr(col5, ',', 1, 2)+1, instr(col5, ',', 1, 3)- instr(col5, ',', 1, 2)-1) col3
      8          ,      substr(col5, instr(col5, ',', 1, 3)+1, instr(col5, ',', 1, 4)- instr(col5, ',', 1, 3)-1) col4
      9          ,      rtrim(col5, ',') col5
     10          from   t1
     11        ) b
     12  on ( a.col5 = b.col5 )
     13  when matched then update set a.col1 = b.col1
     14                             , a.col2 = b.col2
     15                             , a.col3 = b.col3
     16                             , a.col4 = b.col4
     17  when not matched then insert (a.col1) values (null);
    
    3 rows merged.
    
    SQL> select * from t;
    
    COL1                           COL2                           COL3                           COL4                           COL5
    ------------------------------ ------------------------------ ------------------------------ ------------------------------ ------------------------------
    adsdf                          fgrty                          erfth                          oiunth                         adsdf,fgrty,erfth,oiunth,okujt
    x                              y                                                                                            x,y
    a                              b                              c                              d                              a,b,c,d
    
    3 rows selected.
    
    SQL> 
    

    Assuming you're on 9i...

  • Divide the string into rows according to the space

    I'm using Oracle 11.2.0.3.  I need a faster way to divide the organization names based on space as possible just using SQL.

    with org as

    (

    Select 1 org_pk, org_nm 'ALL american, INC.' of any double union

    Select org_pk 2, org_nm "COMPANY A.G" Union double all the

    Select org_pk 3, org_nm "GROWTH FUND SPONSORS and SONS, Inc." of the double

    )

    Select * org;

    Result, I need is

    1. ALL THE

    1 american

    1, INC.

    2 A.G

    2 COMPANY

    3. THE GROWTH

    3 FUND

    3 SPONSORS

    3 and

    3 WIRES,

    3 INC.

    Thank you very much.

    You can use GROUP BY with LISTAGG or XMLAGG. And ordinalite allows to preserve order:

    with org as)

    Select 1 org_pk, org_nm 'ALL american, INC.' of any double union

    Select 2 org_pk, 'A.G COMPANY' org_nm of all the double union

    Select org_pk 3, org_nm "GROWTH FUND SPONSORS and SONS, Inc." of the double

    )

    Select org_pk,

    x.org_nm,

    x.o

    org,.

    XMLTable)

    "ora: tokenize(.,"").

    by the way ' ' | org_nm

    columns

    path of varchar2 (4000) to org_nm '.'.

    o for the ordinalite

    ) x

    where x.org_nm is not null

    /

    ORG_PK ORG_NM O
    ---------- ------------------------------ ----------
    1 ALL                                     2
    1 American 3
    1 ,INC                                    5
    2 A.G                                     2
    2 COMPANY 4
    3 GROWTH                                  2
    3 FUND                                    3
    3 4 SPONSORS
    3 and                                     5
    3 SONS,                                   6
    3 INC.                                    7

    11 selected lines.

    SQL >

    However, I would like to use SUBSTR/INSTR plain + CONNECT BY if the volumes are large or performance is important.

    SY.

  • Splits the string into two columns

    Can someone please help me the following

    I want to divide into two columns URL and ID /cfd/abc.html,/night/aaa/Page1,/can/MLP/Page2|107

    Result must be

    Temporary table
    < font color = "red" > URL < / police > < font color = 'blue' > ID < / make >

    < font color = "red" > /cfd/abc.html < / police > < font color = "blue" > 107 < / make >

    < font color = "red" > / night/aaa/page 1 < / police > < font color = "blue" > 107 < / make >

    < font color = "red" > / can/MLP/Page2 < / police > < font color = "blue" > 107 < / make >


    There can be N number of comma separated URLs, but there will be only 1 separate ID which is the vertical bar (|)

    Try this,

    SQL> WITH T
      2       AS (SELECT  '/cfd/abc.html,/night/aaa/Page1,/can/MLP/Page2|107 ' str FROM DUAL UNION ALL
      3           SELECT  '/cfd/def.html,/bbbb/bbbb/Page1,/lll/MLP/Page3|108 ' str FROM DUAL)
      4  SELECT REGEXP_SUBSTR ( str, '[^,|]+', 1, lvl) URL,
      5         REGEXP_SUBSTR ( str, '[^|]+', 1, 2) ID
      6    FROM T,
      7         (SELECT LEVEL lvl
      8            FROM (SELECT MAX (LENGTH (REGEXP_REPLACE ( str, '[^,]'))) mx FROM T)
      9          CONNECT BY LEVEL <= mx + 1)
     10   WHERE Lvl - 1 <= LENGTH (REGEXP_REPLACE ( str, '[^,]+'))
     11   order by id,lvl;
    
    URL                                                ID
    -------------------------------------------------- -------------------------------------------------
    /cfd/abc.html                                      107
    /night/aaa/Page1                                   107
    /can/MLP/Page2                                     107
    /cfd/def.html                                      108
    /bbbb/bbbb/Page1                                   108
    /lll/MLP/Page3                                     108
    
    6 rows selected.
    
    SQL> 
    

    G.

  • divide the rectangle into pieces with an inner glow

    I have a rounded rectangle that I need to divide it into 3 parts (upper, middle, lower) while applying an inner glow effect to THE ORIGINAL shape. Anyway I tried this the inner glow is applied to all parties to all parties, including the internal limits of the parties.

    Any ideas?

    1. Draw the rounded rectangle.
    2. Divide at the appropriate places.
    3. Close the top resulting and substantive way.
    4. Join the two as a result of the railways; then close them.
    5. Apply a white fill all three.
    6. Apply the line wished to all three.
    7. Select all three. Group them.
    8. Apply the inner glow effect to the selected group.

    JET

  • About concatation, all the lines in a column

    Dear friends,

    I have to concatinate all lines as a column based on a whim of the key column.

    col1col2COL3COL4col5
    481TC_View4TC_View_A
    381TC_View3TC_View_B
    281TC_View2TC_View_C
    181TC_View1TC_View_D
    I need output like below
    col2col5
    81TC_View_A, TC_View_B, TC_View_C, TC_View_D

    I appreciate your help in this regard.

    Thank you

    Ravi

    Hi Ravi,

    That's exactly what the aggregate LISTAGG function:

    SELECT col2

    , LISTAGG (col5, ' / ') WITHIN GROUP (ORDER BY col5) AS all_col5s

    FROM table_x

    GROUP BY col2

    ORDER BY col2

    ;

    If you would care to post CREATE TABLE and INSERT statements for your sample data, and then I could test this.

  • Divide the data into separate rows

    Hi people,

    I have a request, which could be simplified as:

    with t as)

    "name select 'John', ' 7.3.2014' date_from, ' 13.3.2014 ' date_to, 'SICK DAY' reason for the double

    "" the name of Union select 'Mike', ' 28.3.2014 ' date_from, ' 2.4.2014 ' date_to, 'HOLIDAY' because of the double

    "" the name of Union select 'Tom', ' 14.3.2014 ' date_from, ' 14.3.2014 ' date_to, 'HOLIDAY' because of the double

    )

    Select * from t

    Each line includes a person's name, reason for his absence, the dates of and to.

    I would like to divide these lines in separate registers (for later analysis), so an expected output would look something like:

    with t as)

    name select 'John', ' 7.3.2014' absence_date, 'SICK DAY' reason for the double

    "the name of Union select 'John', ' 8.3.2014 ' absence_date, 'SICK DAY' reason for the double

    "the name of Union select 'John', ' 9.3.2014 ' absence_date, 'SICK DAY' reason for the double

    "the name of Union select 'John', ' 10.3.2014 ' absence_date, 'SICK DAY' reason for the double

    "the name of Union select 'John', ' 11.3.2014 ' absence_date, 'SICK DAY' reason for the double

    "the name of Union select 'John', ' 12.3.2014 ' absence_date, 'SICK DAY' reason for the double

    "the name of Union select 'John', ' 13.3.2014 ' absence_date, 'SICK DAY' reason for the double

    "the name of Union select 'Mike', ' 28.3.2014 ' absence_date, 'HOLIDAY' because of the double

    "the name of Union select 'Mike', ' 29.3.2014 ' absence_date, 'HOLIDAY' because of the double

    "the name of Union select 'Mike', ' 30.3.2014 ' absence_date, 'HOLIDAY' because of the double

    "the name of Union select 'Mike', ' 31.3.2014 ' absence_date, 'HOLIDAY' because of the double

    "the name of Union select 'Mike', ' 1.4.2014 ' absence_date, 'HOLIDAY' because of the double

    "the name of Union select 'Mike', ' 2.4.2014 ' absence_date, 'HOLIDAY' because of the double

    "the name of Union select 'Tom', ' 14.3.2014 ' absence_date, 'HOLIDAY' because of the double

    )

    Select * from t

    Please advice, how for the first example query to obtain a required output?

    Thank you

    Tomas

    SQL > with t as)
    2. Select the name of 'John '.
    3, to_date ("'07.3.2014', ' dd.mm.yyyy") date_from
    4, to_date ("'13.3.2014', ' dd.mm.yyyy") date_to
    5, 'SICK DAY' reason
    6 double
    7 union select name "Mike".
    8, to_date ("'28.3.2014', ' dd.mm.yyyy") date_from
    9, to_date ("'02.4.2014', ' dd.mm.yyyy") date_to
    10 at 'HOLIDAY '.
    11 double
    12 union select name of "Tom."
    13, to_date ("'14.3.2014', ' dd.mm.yyyy") date_from
    14, to_date ("'14.3.2014', ' dd.mm.yyyy") date_to
    15, because of "HOLIDAY".


    16 double
    17       )
    18 select name
    19, date_from + (level 1) leave_date
    20, reason
    21 t
    22 connect
    23 by level<= date_to="" -="" date_from="" +="">
    24 and prior name = name
    25 and prior sys_guid() is not null
    order 26
    27 by name
    28, leave_date;

    NAME LEAVE_DAT REASON
    ---- --------- --------
    John 7 March 14 SICK DAYS
    John 8 March 14 SICK DAYS
    John 9 March 14 SICK DAYS
    John 10 March 14 SICK DAYS
    John 11 March 14 SICK DAYS
    John 12 March 14 SICK DAYS
    John 13 March 14 SICK DAYS
    Mike HOLIDAY 28 March 14
    Mike HOLIDAY 29 March 14
    Mike HOLIDAY 30 March 14
    Mike HOLIDAY March 31, 14
    Mike HOLIDAY April 1, 14
    Mike VACATION April 2, 14
    Tom March 14 14 HOLIDAY

    14 selected lines.

    SQL >

Maybe you are looking for