How to achieve this using sql?

assume I have a below table and data
 
create table sk_abcd (a varchar2(6), b varchar2(4));
insert into sk_abcd values ('abcdef', '1235');
insert into sk_abcd values ('qwert', '15');
commit;
 
now I want output as below:
 
<some query>
 
a       b 
--      --
ab     123
cd      5  
ef      null
qw    15
er      null
t       null

Hello

You don't give no matter what version of the database, or a clear explanation about the logic, so I just think that's what you want:

SQL> SELECT substr(a, 2*value(t)+1, 2) a,
  2         substr(b, 3*value(t)+1, 3) b
  3  FROM sk_abcd,
  4       TABLE(
  5         CAST(
  6           MULTISET( select level-1 i from dual connect by level <= ceil(length(a)/2) )
  7           AS sys.odcinumberlist
  8         )
  9       ) t
 10  ;

A        B
-------- ------------
ab       123
cd       5
ef
qw       15
er
t        

6 rows selected
 

Tags: Database

Similar Questions

  • How to achieve this using the sql query?

    Hello gurus,

    I have a table like this
    id    name
    1       a
    2       b
    3       c
    4       d
    5       e
    6       f
    7       g
    8       h
    9       i
    10     j
    11     k
    12     l
    13     m
    now my result should be like this
    id    name  id   name   id   name 
    1       a     6       f      11     k
    2       b     7       g     12     l
    3       c     8       h     13     m
    4       d     9       i
    5       e     10      j
    How to achieve by sql query?

    Thank you and best regards,
    friend

    Edited by: most wanted! February 22, 2012 05:55

    Hello

    Did you mean this:

    with a as
    (select 1 id ,'a' name from dual
    union all select 2 id ,'b' name from dual
    union all select 3 id ,'c' name from dual
    union all select 4 id ,'d' name from dual
    union all select 5 id ,'e' name from dual
    union all select 6 id ,'f' name from dual
    union all select 7 id ,'g' name from dual
    union all select 8 id ,'h' name from dual
    union all select 9 id ,'i' name from dual
    union all select 10 id ,'j' name from dual
    union all select 11 id ,'k' name from dual
    union all select 12 id ,'l' name from dual
    union all select 13 id ,'m' name from dual
    )
    
    select
      id_1
      ,name_1
      ,id_2
      ,name_2
      ,id_3
      ,name_3
    
    from
      (
      select
        id id_1
        ,name name_1
        ,lead(id,5) over (order by id) id_2
        ,lead(name,5) over (order by id) name_2
        ,lead(id,10) over (order by id)  id_3
        ,lead(name,10) over (order by id) name_3
        ,rownum r
      from
        a
      )
    where
      r <=5
    
    D_1                   NAME_1 ID_2                   NAME_2 ID_3                   NAME_3
    ---------------------- ------ ---------------------- ------ ---------------------- ------
    1                      a      6                      f      11                     k
    2                      b      7                      g      12                     l
    3                      c      8                      h      13                     m
    4                      d      9                      i
    5                      e      10                     j 
    

    Kind regards

    Peter

  • How to achieve this using an analytic function - please help

    version 10g.
    This code works very well with my requirement. I'm tyring learn analytical functions and implement than in the query below. I tried to use row_number,
    but I could nt achieve the desired results. Please give me some ideas.

    SELECT c.tax_idntfctn_nmbr irs_number, c.legal_name irs_name,
           f.prvdr_lctn_iid
      FROM tax_entity_detail c,
           provider_detail e,
           provider_location f,
           provider_location_detail pld
     WHERE c.tax_entity_sid = e.tax_entity_sid
       AND e.prvdr_sid = f.prvdr_sid
       AND pld.prvdr_lctn_iid = f.prvdr_lctn_iid
       AND c.oprtnl_flag = 'A'
       AND c.status_cid = 2
       AND e.oprtnl_flag = 'A'
       AND e.status_cid = 2
       AND (c.from_date) =
              (SELECT MAX (c1.from_date)
                 FROM tax_entity_detail c1
                WHERE c1.tax_entity_sid = c.tax_entity_sid
                  AND c1.oprtnl_flag = 'A'
                  AND c1.status_cid = 2)
       AND (e.from_date) =
              (SELECT MAX (c1.from_date)
                 FROM provider_detail c1
                WHERE c1.prvdr_sid = e.prvdr_sid
                  AND c1.oprtnl_flag = 'A'
                  AND c1.status_cid = 2)
       AND pld.oprtnl_flag = 'A'
       AND pld.status_cid = 2
       AND (pld.from_date) =
              (SELECT MAX (a1.from_date)
                 FROM provider_location_detail a1
                WHERE a1.prvdr_lctn_iid = pld.prvdr_lctn_iid
                  AND a1.oprtnl_flag = 'A'
                  AND a1.status_cid = 2)
    Thank you

    Published by: new learner on May 24, 2010 07:53

    Published by: new learner on May 24, 2010 10:50

    Can be like that not tested...

    Select *.
    Of
    (

    SELECT c.tax_idntfctn_nmbr irs_number, c.legal_name irs_name,
    f.prvdr_lctn_iid, c.from_date as c_from_date, max (c.from_date) more (partition c.tax_entity_sid) as max_c_from_date,
    e.from_date as e_from_date, max (e.from_date) more (partition e.prvdr_sid) as max_e_from_date,
    PLD.from_date as pld_from_date, max (pld.from_date) more (pld.prvdr_lctn_iid partition) as max_pld_from_date

    OF tax_entity_detail c,.
    e provider_detail
    provider_location f,
    LDP provider_location_detail
    WHERE c.tax_entity_sid = e.tax_entity_sid
    AND e.prvdr_sid = f.prvdr_sid
    AND pld.prvdr_lctn_iid = f.prvdr_lctn_iid
    AND c.oprtnl_flag = 'A '.
    AND c.status_cid = 2
    AND e.oprtnl_flag = 'A '.
    AND e.status_cid = 2
    AND pld.oprtnl_flag = 'A '.
    AND pld.status_cid = 2

    ) X
    where c_from_date = max_c_from_date AND e_from_date = max_e_from_date AND
    pld_from_date = max_pld_from_date

  • Is it possible to transfer videos from the iPod from someone else on my iPhone?  How to achieve this?

    Is it possible to transfer videos from the iPod from someone else on my iPhone?  How to achieve this?

    Depends on the model of iPod exactly.

    If the iPod is supported you can try using AirDrop: How to use with your iPhone, iPad or iPod touch - Apple Support AirDrop

    If this is not the case, there are applications in the App Store that will allow you to send files, including videos taken with the iPod and who reside in the film to other devices.

    https://iTunes.Apple.com/us/app/photo-transfer-app-easily/id365152940?Mt=8

    Photo transfer app allows you to quickly copy pictures and videos from your iPhone, iPad, Mac or PC using your local wifi network.

    You can't send videos that are stored by default Apple video App.

  • How to achieve this specific shadow effect?

    Hi all

    Does anyone know how to achieve this effect of specific shadow in InDesign: an instruction step by step, a plugin, etc.?

    Shadows.png

    Kind regards

    Kasyan

    Kasyan,

    I usually just use the base pen. I draw the object with a few clicks of the pen, fill it with whatever color, the hue value if you want, then use the settings more or less as below.

    Mike

  • How to achieve this simple effect?

    How to achieve this simple effect?

    Hi guys,.

    I just want to know what do you call the effect which the corners of the screen is blurred and darker, and how can we achieve?

    See the video in this link www.youtube.com/watch?v=lHj83FRR11s.

    Thank you in advance!

    Use a solid layer of the color of your choice then add a mask and change his pen:

    The effects coming from the photograph is called vignetting or vignnete

    Another way is to add a bright spot and animated, but its more difficult, I hope it works

  • I had to replace my hard drive and need to reinstall Acrobat Pro.  How to achieve this?

    I had to replace my hard drive and need to reinstall Acrobat Pro.  How to achieve this?

    Hi Roger,

    Please visit: http://www.adobe.com/downloads/other-downloads.html

    I hope this helps.

    Concerning

    Megha Rawat

  • How to transform this PL/SQL query in a PL/SQL function?

    Salvation of nice people!

    I have a nice flash chart that SQL code is below. I want to see this table only if this query returns results. I tried to put it in condition. How transformt this ciode SQL "SLQ function returning a Boolean"?
    DECLARE
    X VARCHAR2 (4000);
    BEGIN
    x := 
    'SELECT NULL LINK, trunc(a.DATE1, '''||:P13_TRUNC||'''), avg(b.pourcentage_remplissage)
    FROM    EVV_'||:P13_SITE||' a, bassin_remplissage b
    WHERE   a.CLEF_VAR = (SELECT CLEF_VAR FROM SITE_ECHELLE WHERE SITE='''||:P13_SITE||''') 
    AND     round(a.valeur, 1) = b.cote_ngf
    AND     DATE1 BETWEEN 
    TO_DATE ('''||:P13_DATE_DEBUT||'000000'', ''DD/MM/YYYYHH24MISS'') AND 
    TO_DATE ('''||:P13_DATE_FIN||'235959'', ''DD/MM/YYYYHH24MISS'') 
    group by trunc(a.DATE1, '''||:P13_TRUNC||''')
    ORDER BY trunc(a.DATE1, '''||:P13_TRUNC||''')';
    RETURN (X);
    END;
    Thank you for your kind replies.

    Christian

    Christian:

    Try this

    DECLARE
       x   VARCHAR2 (4000);
    BEGIN
       x :=
             'SELECT COUNT(*)
    FROM    EVV_'
          || NVL(:p13_site, 'E003')
          || ' a, bassin_remplissage b
    WHERE   a.CLEF_VAR = (SELECT CLEF_VAR FROM SITE_ECHELLE WHERE SITE='''
          || NVL(:p13_site, 'E003')
          || ''')
    AND     round(a.valeur, 1) = b.cote_ngf
    AND     DATE1 BETWEEN
    TO_DATE ('''
          || NVL(:p13_date_debut, '01/01/1980')
          || '000000'', ''DD/MM/YYYYHH24MISS'') AND
    TO_DATE ('''
          || NVL(:p13_date_fin, '01/01/2080')
          || '235959'', ''DD/MM/YYYYHH24MISS'')
     ';
    
       EXECUTE IMMEDIATE x
       INTO WWV_FLOW.g_id;
    
       IF wwv_flow.g_id IS NULL OR wwv_flow.g_id = 0
       THEN
          RETURN FALSE;
       ELSE
          RETURN TRUE;
       END IF;
    END;
    

    Published by: city has 8 July 2009 06:12
    Moved the 'back' clause where it should be :)

    Published by: city has 8 July 2009 06:13

  • not all no body no how to achieve this effect in ae or premiere pro cs5

    looking to see if any1 can help me achieve this effect for my music videos http://www.youtube.com/watch?v=xIBEl35_wB0 & feature = related is there a plug-in as fcp or an easy way to achieve this appreciate any help thanks...

    If you do not understand the answer you gave Andrew, so it is important to start at the beginning and learn the basics of After Effects first.

    Start here to learn After Effects.

  • Help! How to achieve this effect in Photoshop?

    How to do this effect in the PS7?

    http://www.cobrastarship.com/Media/justblaize.jpg

    Thank you very much!

    http://www.Deke.com/content/faking-HDR-portrait

  • How to achieve this effect using Adobe Photoshop Touch?

    Hello

    I'm new to photoshop of sorts, as you will soon learn, so I have trouble working on what effects, if have, some images, I find online. At the moment I'm working on what effect (s) on the links below images have, can anyone help? I guess they are the same effects on different images?

    https://PBS.twimg.com/Media/B6h7rb_IEAAXR3a.PNG

    https://PBS.twimg.com/Media/B6ipKsDIUAAmMOU.PNG

    https://PBS.twimg.com/Media/B6iRV_XCIAAcHM6.PNG

    https://PBS.twimg.com/Media/B6iQBbWCMAAlCD2.PNG

    https://PBS.twimg.com/Media/B6iOePUCIAAy7tV.PNG

    Thanks in advance!

    http://TV.Adobe.com/m/#! /Watch/learn-Photoshop-touch/introducing-Photoshop-touch-on-the-IP ad-2.

  • When I delete an email from one of my devices, computer, iphone, or ipad, I'd removed from 2 other devices. How to achieve this?

    When I delete an email from any of my devices such as computer, iphone, or ipad, I want email deleted automatically 2 other devices. How this is done?

    It depends on what kind of email service you use, POP or IMAP.

  • How to achieve this effect?

    I'm looking to recreate the effect as seen in the video below at 01:10.

    https://www.YouTube.com/watch?v=kThmu-o_nhI

    Any help would be appreciated, especially the part where each individual smile falls differently. Also, when every smile appears, I thought at first it was just a scale in, but looks like it has a different effect to him.

    Thank you!

    I had manually on this sucker. nothing to it. Take a look:

    you create two layers in photoshop or illustrator

    import into Ae. make an animation to one of them - the 'different' effect you notice - this is called an overflow-under-overtaking animation and you must use the graph for this editor. First, you set your scale to 0 and after 10 images to 100 like this:

    then you go into the graphics editor and on the value graph, you change your curve of this:

    to do this:

    See that it is a go-around and extensions of waveform more about it here:

    http://www.Motionscript.com/articles/bounce-and-overshoot.html

    This is my clumsy way to explain how it works

    Move keyframes until you get the distribution right and now you've got it

    so we got the scale just as it should be! now as for the position - since we know that we want more of them, we should try to work D.R.Y - do not repeat yourself - make us an animation and duplicate instead of deal with alone. We will add location to the mix and we'll take smiley all the way upward and downwards, then some so we have room when we scale it afterwards.

    now, we want to change the speed a bit, so we'll go into the graphics editor on the speed graph and adjust it like this:

    This is the graph of speed so at the beginning, we want less speed and gradually increase

    now, we got a dandy end of an animation

    now us precomp this layer and call him smiley-animation and press the button cut so we can now version 13.8 appreciate the beautiful cropped a pre comped layer limits

    we drag the anchor in the Middle, so it will be easier to position the layers a scale them subsequently

    now reproduce us like crazy by pressing Ctrl + D and drag it into the window of the model with the selection rectangle and what not

    and now reduce us some of the layers a little

    and offset the layers

    now, we've got this amazing thing:

    Oops... you have one coming down enough. not to worry - it's all in the same model! We can go inside and drag it down!

    What is in laughing face? We work D.R.Y. we are simply duplicate the animation precomp smiley in the project window and name it funny animation

    go inside and replace the layer with layer laughing smiley

    and now in our main composition we replace some of the smiley with precomps precomps laughing in the project window

    now, we are DONE: TAKE a BREAK!

  • How to achieve this effect in Photoshop?

    NOTE: This is NOT my photo is an example to look at it, I'll do!

    Does anyone know how this look is achieved in Photoshop?

    FullSizeRender.jpg

    You mean that your light, milky appearance? Try to pull up on a curves adjustment layer shadow.

  • How to achieve this logic?

    I have 3 tables with structure as below.

    create table T1

    (ColA VARCHAR2 (50 CHAR) NOT NULL,)

    ColB VARCHAR2 (50 CHAR) NOT NULL,

    Teachers VARCHAR2 (50 CHAR) NOT NULL,

    date of startdt

    float (126) of t1_price 0 not null by default)

    create table T2

    (ColA VARCHAR2 (50 CHAR) NOT NULL,)

    ColB VARCHAR2 (50 CHAR) NOT NULL,

    Teachers VARCHAR2 (50 CHAR) NOT NULL,

    date of startdt

    float (126) of t2_price 0 not null by default)

    create table T3

    (ColA VARCHAR2 (50 CHAR) NOT NULL,)

    ColB VARCHAR2 (50 CHAR) NOT NULL,

    Teachers VARCHAR2 (50 CHAR) NOT NULL,

    date of startdt

    float (126) of t3_price 0 not null by default)

    Requirement is to fill the T3_price in the table T3 provided that if there is an entry in T1 for same startdate, T1_price should be used elsewhere last entry of T2 must be used. Some examples of data.

    Registrations in Q1

    ColA

    ColB

    Teachers

    Startdt

    T1_Price

    VAL1

    VAL2

    VAL3

    14/09/2014

    100

    VAL1

    VAL2

    VAL3

    21/09/2014

    100

    VAL1

    VAL2

    VAL3

    10/12/2014

    200

    Registrations in Q2

    ColA

    ColB

    Teachers

    Startdt

    T2_Price

    VAL1

    VAL2

    VAL3

    09/07/2014

    200

    VAL1

    VAL2

    VAL3

    10/05/2014

    300

    09/07/2014

    14/09/2014

    21/09/2014

    28/09/2014

    10/05/2014

    10/12/14

    19/10/14

    T1_Price

    100

    100

    200

    T2_Price

    200

    200

    300

    T3_Price should be

    200

    100

    100

    200

    300

    200

    300

    Can you get it someone please let me know if the above requirement can be achieved in a single update statement? I tried with the statement below.

    UPDATE r T3

    SET T3_price =

    (NVL)

    (SELECT T1_Price

    T1 d

    WHERE r.colA = d.ColA

    AND r.ColB = d.ColB

    AND r.ColC = d.ColC

    AND r.startdt = d.startdt),

    (SELECT T2_Price

    B T2

    WHERE r.colA = b.ColA

    AND r.ColB = b.ColB

    AND r.ColC = b.ColC

    AND r.startdt > = b.startdt))) < < < < I don't know that I'm missing my logic in that statement.

    WHERE THERE ARE

    (SELECT T1_Price

    T1 d

    WHERE r.colA = d.ColA

    AND r.ColB = d.ColB

    AND r.ColC = d.ColC

    AND r.startdt = d.startdt

    UNION

    SELECT T2_Price

    B T2

    WHERE r.colA = b.ColA

    AND r.ColB = b.ColB

    AND r.ColC = b.ColC

    AND r.startdt > = b.startdt);

    Hello

    That's what you asked for:

    MERGE INTO dst of t3

    WITH THE HELP OF)

    SELECT t3.cola, t3.colb, t3.colc, t3.startdt

    MAX (t1.t1_price) AS t1_price

    MAX (t2.t2_price) DUNGEON (DENSE_RANK LAST ORDER BY t2.startdt)

    AS last_t2_price

    T3

    LEFT OUTER JOIN t1 ON t1.cola = t3.cola

    AND t1.colb = t3.colb

    AND t1.colc = t3.colc

    AND t1.startdt = t3.startdt

    LEFT OUTER JOIN t2 ON t2.cola = t3.cola

    AND t2.colb = t3.colb

    AND t2.colc = t3.colc

    AND t2.startdt<=>

    GROUP OF t3.cola, t3.colb, t3.colc, t3.startdt

    ) CBC

    WE (dst.cola = src.cola

    AND dst.colb = src.colb

    AND dst.colc = src.colc

    AND dst.startdt = src.startdt

    )

    WHEN MATCHED THEN UPDATE

    SET dst.t3_price = NVL (src.t1_price, src.last_t2_price)

    ;

    Here's what Q3 looks after execution of this MERGER:

    COLA, COLB TEACHERS STARTDT T3_PRICE

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

    VAL1 VAL2, VAL3 200 14 - SEP - 07

    VAL1 VAL2, VAL3 14-SEPT-14 100

    VAL1 VAL2, VAL3 21-SEP-14 100

    VAL1 VAL2, VAL3 28-SEPT-14 200

    VAL1 VAL2, VAL3 5 OCTOBER 14 300

    VAL1 VAL2, VAL3 12 OCTOBER 14 200

    VAL1 VAL2, VAL3 19 OCTOBER 14 300

Maybe you are looking for