How to deal with NULL values in regexp_substr?

DECLARE
   TYPE t_rec IS TABLE OF VARCHAR2(200);

/* case 1 */
   l_input    varchar2(100) := '28/09/2009 00:00:00|AFRISB|FC|773|7|17|512|76|60|U|';
/* case 2 */
--   l_input    VARCHAR2(100) := '06/10/2009 00:00:00|PDIERR|PS|999|0|1|0|0||U|';
   l_bars     PLS_INTEGER;
   l_fields   PLS_INTEGER;
   l_rec      t_rec := t_rec();
BEGIN
   l_bars     := regexp_count(l_input, '\|', 1, 'i');
   l_fields   := l_bars + 1;

   FOR fld IN 1 .. l_fields
   LOOP
      l_rec.EXTEND();

      l_rec(fld)   := REGEXP_SUBSTR(l_input, '[^|]+', 1, fld);
      dbms_output.put_line('Fld ' || fld || ': ' || l_rec(fld));
   END LOOP;
END;

The above code is that I break a string of pipe delimited into individual elements.

Looking at the case 1 in the code, the output displays each field correctly. However in case 2, the 9th field is null (nothing between the two tubes) so the regexp_substr 19 online is assigning the 'U' in the box 10 as a field 9.

What should I do to get the line 19 to correctly assign a NULL value to field 9?

Information about the version of the database are:

BANNER

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

12 c Oracle database Release 12.1.0.1.0 - 64 bit Production
PL/SQL Release 12.1.0.1.0 - Production
CORE Production 12.1.0.1.0
AMT for 64-bit Windows: Version 12.1.0.1.0 - Production

NLSRTL Version 12.1.0.1.0 - Production

Thank you

Steve

Hello

If you want to use regexes, so instead of

REGEXP_SUBSTR (l_input, "[^ |]") +', 1, fld);

use

REGEXP_SUBSTR (l_input

, '([^|] *)(\|| $)'

-P

fld

NULL

-P

);

. The 6th argument to REGEXP_SUBSTR is a new feature of Oracle 11.1.  It's kind of a back reference. Normally, REGEXP_SUBSTR returns the substring that matches the pattern in the 2nd argument.  If the 6th argument is 1, however, REGEXP_SUBSTR returns only the part of the pattern between the 1st on the left '(' et sa correspondance)."

Tags: Database

Similar Questions

  • dealing with null values

    HI people

    req1:
    It may be a specific difference between "not" and "does not exist".
    which is the best 'there is no' or 'no', when it nulls.i.e If the subquery contains NULL values.

    I hope you people understand my question


    Thanks in advance

    Published by: newbie on February 18, 2011 03:52

    This can be useful
    http://asktom.Oracle.com/pls/asktom/f?p=100:11:3607896341573320:P11_QUESTION_ID:442029737684

  • Cumulative total for each day - how to deal with nulls

    I'm on 11.2.0.3.  I want to write a query to calculate a running total of the incidents a day - this request will be used for an APEX line chart.


    Sample table and data:

    create table sales (
      id number primary key,
      time_of_sale date,
      item varchar2(20));
    
    
    insert into sales values (1, to_date('02-JAN-2013','DD-MON-YYYY'), 'book');
    insert into sales values (2, to_date('03-JAN-2013','DD-MON-YYYY'), 'candle');
    insert into sales values (3, to_date('05-JAN-2013','DD-MON-YYYY'), 'bicycle');
    insert into sales values (4, to_date('05-JAN-2013','DD-MON-YYYY'), 'football');
    insert into sales values (5, to_date('07-JAN-2013','DD-MON-YYYY'), 'football');
    insert into sales values (6, to_date('10-JAN-2013','DD-MON-YYYY'), 'elephant');
    insert into sales values (7, to_date('10-JAN-2013','DD-MON-YYYY'), 'turtle');
    insert into sales values (8, to_date('10-JAN-2013','DD-MON-YYYY'), 'book');
    insert into sales values (9, to_date('10-JAN-2013','DD-MON-YYYY'), 'candle');
    insert into sales values (10, to_date('10-JAN-2013','DD-MON-YYYY'), 'bicycle');
    commit;
    

    For each of the days between 1 January and 10 Jan I want to get the total functioning of the number of sales.

    So the output l would like is:

    DAY ITEMS_PER_DAY

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

    1ST JANUARY 13 0

    JANUARY 2, 13 1

    JANUARY 3, 13 2

    JANUARY 4, 13 2

    5 JANUARY 13 4

    JANUARY 6, 13 4

    JANUARY 7, 13 5

    JANUARY 8, 13 5

    JANUARY 9, 13 5

    10 JANUARY 13 10

    So even if there is no sale on January 4, we show the total of the previous day.

    If I can create a series of dates using the:

    select trunc((to_date('01-JAN-2013','DD-MON-YYYY')-1) + rownum) day 
    from dual 
    connect by rownum <= 10
    

    And I can't the cumulative aid total:

    select trunc(time_of_sale) as day, sum(count(*)) over (order by trunc(time_of_sale)) as items_per_day
    from sales
    group by trunc(time_of_sale)
    

    Overall, it gives me:

    SQL > select

    2 a.day as the day,

    3 b.items_per_day

    4 of

    5 (select trunc((to_date('01-JAN-2013','DD-MON-YYYY')-1) + rownum) as day

    6 double

    7 plug by rownum < = 10).

    8 (select trunc (time_of_sale) day, sum (count (*)) (trunc (time_of_sale) order) as items_per_day

    9 sales

    10 group by trunc (time_of_sale)) b

    11 where a.day = b.day [+] - replace by parentheses to avoid the formatting of the forum

    12 order by a.day

    13.

    DAY ITEMS_PER_DAY

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

    1st January 13 null

    JANUARY 2, 13 1

    JANUARY 3, 13 2

    Value null 4 January 13

    5 JANUARY 13 4

    Value null January 6, 13

    JANUARY 7, 13 5

    Value null January 8, 13

    Value null January 9, 13

    10 JANUARY 13 10

    It's not exactly what I'm looking for.  I played a bit with a lag, but had no success.

    Any ideas?

    Thank you

    John

    Hi, John,.

    You want to do the SUM after the outer join, like this:

    WITH days_wanted AS

    (

    SELECT TO_DATE (January 1, 2013 ', 'DD-MON-YYYY') + ROWNUM - 1 day YOU

    OF the double

    CONNECT BY ROWNUM<=>

    )

    SELECT d.day

    SUM (COUNT (s.id)) OVER (ORDER BY d.day) AS items_to_date

    OF days_wanted d

    S sale LEFT OUTER JOIN ON TRUNC (s.time_of_sale) = d.day

    GROUP BY d.day

    ORDER BY d.day

    ;

    Note that we must use COUNT (s.id) instead of COUNT (*) here, because, given that it is evaluated once the outer join, COUNT (*) would be taken into account less than $ 1 a day, because the outer join ensures there will be at least 1 row in the game for each row in days_wanted, whether or not it matches anything in sales.

    It wouldn't work using the old join syntax, too, but I suggest to use the ANSI syntax, especially for outer joins.  It reduces the amount and the complexity of the coding, and which allows to reduce the number of errors.  (Also, it avoids the problem of the display of this site.)

  • How to display the line empty as a line with null values

    Hi all

    Pls advise me if it is possible to use a single query statement to display
    Empty row (i.e. not a single return line) as a line with null values.

    For example,.

    Select the names of names_mst whose name = "sgasfgs".

    Result:
    Names of
    =====
    < null >

    Hello
    If you desire to join external to double, as shown below, you still get at least a line of production

    SELECT  nm.names
    FROM            dual
    LEFT OUTER JOIN names_mst   nm  ON nm.name='sgasfgs';
    
  • Remove data with null value

    Hello

    I'm using Oracle 11 g. I have a table with an id of 3, node, the value column. Combination of the column id and node, that must be taken account for deletion on the registers.

    Here, I need to delete lines with the NULL value in the value column. If for a combination of id and node with non-null values, then I need to delete rows with a null value for this combination.

    If the combination of id, node is not null value then this records should not delete.

    Below table, I need to remove the second row, for which is a value not zero VOICE CAL '10' is there, so I need to delete the row with null values. (VOICE, CAL, NULL)

    Network, FL, there is no value is non-null then I should NOT delete this line.

    This table is to have 100 s of this association, we can delete data in a single delete query?

    Or how I can delete rows with nulls for this combination.

    Tab1

    VALUE OF THE NŒUD ID

    VOICE CAL 10
    VOICE CAL NULL
    NETWORK NULL FL

    Thank you

    Hello

    oradba11 wrote:

    Hello

    I'm using Oracle 11 g. I have a table with an id of 3, node, the value column. Combination of the column id and node, that must be taken account for deletion on the registers.

    Here, I need to delete lines with the NULL value in the value column. If for a combination of id and node with non-null values, then I need to delete rows with a null value for this combination.

    If the combination of id, node is not null value then this records should not delete.

    Below table, I need to remove the second row, for which is a value not zero VOICE CAL '10' is there, so I need to delete the row with null values. (VOICE, CAL, NULL)

    Network, FL, there is no value is non-null then I should NOT delete this line.

    This table is to have 100 s of this association, we can delete data in a single delete query?

    Or how I can delete rows with nulls for this combination.

    Tab1

    VALUE OF THE NŒUD ID

    VOICE CAL 10
    VOICE CAL NULL
    NETWORK NULL FL

    Thank you

    You can do this in a single DELETE statement (it is not a request), using an EXISTS or IN the subquery.  For example:

    REMOVE table_x m

    WHERE the value IS NULL

    AND THERE ARE)

    SELECT 0

    FROM table_x s

    WHERE s.id = m.id

    AND s.node = m.node

    AND s.value IS NOT NULL

    )

    ;

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

  • How to deal with analysis PC Performance & Stability Report

    Yesterday, when I just walked into my Office Xp, an error report in a program called... uh, PC Performance & Stability Report analysis, can possibly be, telling me to correct these errors have shown under its professional service.
    How to deal with him?
    Thank you for your advice it.

    Hello MeriClaybron,

    1. have you installed any show analyzing the program on your computer?

    This problem can be caused due to infection by the Virus. I suggest that you run a virus scan on your computer using Microsoft Safety scanner and check if you have the same problem.

    http://www.Microsoft.com/security/scanner/en-us/default.aspx

  • Apparently, my memory is almost full - no idea how to deal with not having a novice such am - sd card

    Apparently, my memory is almost full - no idea how to deal with not having a novice such am - sd card

    Hi sixty.

    It can also be a good idea to begin to transfer the content from your phone to a PC/Mac to help reduce the storage room.

    It is a process usually easy, just plug the unit to a PC, on the phone screen select MTP mode when it appears.

    Once finished, you just have to access the phone's internal memory and transfer pictures/videos from the DCIM folder.

    Let us know if you need help in this kind of task.

  • How to deal with operating system windows 8.1 and apps on usb device

    Hi, I have a laptop Lenovo G505. Windows 8 64-bit was preinstalled in it. Later, I upgraded to 8.1. Laptop is almost 9 months and still under warranty. Since a few days, built Lenovo solution Center alert this analysis of hardware detected failures in one or more devices. On suggestion of Lenovo, I ran hdtune pro app in my machine and it also detected 3 hard drive errors. As my machine is under warranty, Lenovo is ready to replace my hard drive with a new one. But they say that it is the responsibility of the customer to return the windows 8.1 operating system and install in the new drive and their liability is limited to the replacement of the hard disk only. I am not computer savvy and I request concerned to guide me how to deal with operating system windows 8.1 on external media like USB, DVD, and install in the new drive. I also installed a number of apps and paid games. Therefore, I would like to resume these games also files so that I need not buy again. Assistance in this regard is required.

    Hello Mohan,

    Thanks for posting your query in Microsoft Community Forum.

    I can of course understand the situation and will be happy to help with your query.

    Let me ask you;

    • You have the key product for Windows 8 or 8.1?

    You can create an installation media (DVD/USB) for Windows 8.1 and re-install when you want. However, in order to create an installation media for Windows 8.1, you need the product key. If you don't have the product key for Windows 8.1, you can not create installation media.

    You can create the installation media for Windows 8 by using the product key Windows 8 If you have. In this case, install you Windows 8 first and then go to Windows 8.1 through store.

    As far as your paid apps (purchased by store) are concerned, you should be able to install them as soon as you sign in with the same Microsoft Account where apps were purchased.

    You can see the steps indicated by Ronnie Vernon replied on 24 December2013, re - install paid apps.

    You can follow the steps below to create installation media.

    1. Run the program Windows 8.1 configuration or installation of Windows 8 (depending on the availability of the product key for the specific operating system.
    2. When you are prompted to run or save the file, choose run

    3. When you are prompted to enter a product key, enter the 25-character product key, that you received when you purchased Windows 8.1 (or Windows 8).

    4. When you are prompted to install Windows 8.1 (or Windows 8), select install by creating media and then click Next.

    5. Select the type of media you want to use: either a Flash DRIVE or a DVD.

    To create a USB flash drive

    1. Click on the USB flash drive.

    2. Plug the USB key into a USB port on your PC.

    3. When you are prompted, select the USB key that you want to use, and then click Next.

      If you have files on the USB flash drive, it will remove them.

    To create a DVD

    1. Click on the ISO file , and then select the location where to save the ISO file.

    2. Insert a blank recordable DVD into your DVD drive.

    3. Burn the ISO of the DVD file using Windows disc Image burner, or another program DVD burning.

    Note: Ensure that the USB or DVD key that you use has nothing else stored on it and has a sufficient free space to download the Windows 8.1 Installer: about 2.3 GB for the 64-bit version.

    You can also read the article below to create a USB stick recovery.

    Create a recovery USB disk

    Hope this information is useful. Please feel free to answer in the case where you are facing in the future other problems with Windows.

    Thank you.

  • After the recent update on 06/01/2016, pdf files created on the Tamil language there are blank pages. How to deal with all this?

    After updated recent Acrobat reader, dated 06/01/2016, files already created with Tamil fonts show blank pages. How to deal with all this?

    Hi tnrk64,

    We just released Acrobat Reader for iOS version 15.4 on 23 January 2016.

    This version includes the special snag you have met.

    Would you please try it and let us know if it works for you?

    If you have problems with Acrobat Reader on the Apple App Store update, please take a look at the following page for advice: http://adobe.com/go/updatehelp

    Thank you!

  • How to deal with the change in scope

    Dear,

    No org by enforcement period. Consolidation of the CDA. CDA entry.

    September, a company (X) is thrown into a perimeter (a-frame) and granted in a different consolidation perimeter (part B).

    I need perform the following acts:

    (A) CDA profit & loss of X, from September, must contribute to A scope results until December;

    (B) BAT profits/losses of X in September, October and December, must contribute to the results of scope B until December.

    (Operations under A) and B) can be automated? No idea how to do?

    I don't have a script. I need only a generic description on how you did.

    Thank you very much!

    According to my experience, assuming that you create a new entity for X under parent B, the best thing to do in these situations is to simply manage it via a journal entry.  You will write a day who would keep the CDA P & L (and in our cash flow of CDA case) result of X to the title of parent with equal and opposite impact hitting the new entity of X under B.  You post this journal in Sep, Oct, Nov and dec and continue loading data for a YEAR to X under B.

    However, if you simply drag & drop X under a new parent, I don't know how you deal with it.

    Kind regards
    Jason

  • full outer join: how to get without null values?

    full outer join: how to get without null values?

    Hello

    Please go well this url

    http://asktom.Oracle.com/pls/asktom/f?p=100:11:999478429860455:P11_QUESTION_ID:6585774577187

    Thank you
    Prakash P

  • How to deal with the table still growing?

    All tables are more and more applications. In some applications, tables become quickly more and more wide. How to deal with this problem?
    Currently I develop an application system. Should I add a large number of orders to remove the code for each table?

    The problem is delete is very time consuming.

  • How to deal with Menu select when there are NULL or a value with SQL

    I have a Menu(:P_55X) SELECT with:

    "NULL VALUE DISPLAY" = NULL

    'NULL RETURN VALUE' = NULL

    The graphical query is as follows.


    SELECT NULL LINK,
    START_DATE "FOR_MONTH",
    ROUND(AVG("SLA"),3) "SLA_UPTIME"
    from SLA_TIMES_ZABBIX
    LEFT JOIN (SELECT DISTINCT NODE_NAME,OS_TYPE from CMS.CMS_NODE_OS where remove_dt is NULL) OSNODE on LOWER(SLA_TIMES_ZABBIX.NODE_NAME)=LOWER(OSNODE.NODE_NAME)
    where OS_TYPE=:P55_X group by START_DATE order by START_DATE ASC;
    

    How can I accout for the (: P55_X) variable is sometimes NULL and not null sometimes. which means I can't use the '=' when values is null because I need an IS NULL it.

    The column in the database has a value or is set to NULL.

    Thank you

    Robert

    where (OS_TYPE = :P55_X OR (:P55_X IS NULL and OS_TYPE IS NULL))
    
  • REGEXP_SUBSTR for the list delimited by commas with null values

    Hello

    I have a column that stores a list of values comma-delimited. Some of these values in the list may be null. I'm having some trouble trying to extract the values using the REGEXP_SUBSTR function when null values are present. Here are two things I've tried:
    SELECT
       REGEXP_SUBSTR (val, '[^,]*', 1, 1) pos1
      ,REGEXP_SUBSTR (val, '[^,]*', 1, 2) pos2
      ,REGEXP_SUBSTR (val, '[^,]*', 1, 3) pos3
      ,REGEXP_SUBSTR (val, '[^,]*', 1, 4) pos4
      ,REGEXP_SUBSTR (val, '[^,]*', 1, 5) pos5
    FROM (SELECT 'AAA,BBB,,DDD,,FFF' val FROM dual);
    
    POS P POS P P
    --- - --- - -
    AAA   BBB
    SELECT
       REGEXP_SUBSTR (val, '[^,]+', 1, 1) pos1
      ,REGEXP_SUBSTR (val, '[^,]+', 1, 2) pos2
      ,REGEXP_SUBSTR (val, '[^,]+', 1, 3) pos3
      ,REGEXP_SUBSTR (val, '[^,]+', 1, 4) pos4
      ,REGEXP_SUBSTR (val, '[^,]+', 1, 5) pos5
    FROM (SELECT 'AAA,BBB,,DDD,,FFF' val FROM dual);
    
    POS POS POS POS P
    --- --- --- --- -
    AAA BBB DDD FFF
    As you can see that neither calls work correctly. Anyone know how to change the regular expression pattern to handle null values? I tried various other models but could not get anyone to work in all cases.

    Thank you

    Martin
    -----
    http://www.ClariFit.com
    http://www.TalkApex.com

    Hi, Martin,.

    That's what you want:

    SELECT
       RTRIM (REGEXP_SUBSTR (val, '[^,]*,', 1, 1), ',') pos1
      ,RTRIM (REGEXP_SUBSTR (val, '[^,]*,', 1, 2), ',') pos2
      ,RTRIM (REGEXP_SUBSTR (val, '[^,]*,', 1, 3), ',') pos3
      ,RTRIM (REGEXP_SUBSTR (val, '[^,]*,', 1, 4), ',') pos4
      ,RTRIM (REGEXP_SUBSTR (val || ','
                          , '[^,]*,', 1, 5), ',') pos5
    FROM (SELECT 'AAA,BBB,,DDD,,FFF' val FROM dual);
    

    The query above works in Oracle 10 or 11, but in Oracle 11, you can also do it with only REGEXP_SUBSTR, without using RTRIM:

    SELECT
       REGEXP_SUBSTR (val, '([^,]*),|$', 1, 1, NULL, 1) pos1
      ,REGEXP_SUBSTR (val, '([^,]*),|$', 1, 2, NULL, 1) pos2
      ,REGEXP_SUBSTR (val, '([^,]*),|$', 1, 3, NULL, 1) pos3
      ,REGEXP_SUBSTR (val, '([^,]*),|$', 1, 4, NULL, 1) pos4
      ,REGEXP_SUBSTR (val, '([^,]*),|$', 1, 5, NULL, 1) pos5
    FROM (SELECT 'AAA,BBB,,DDD,,FFF' val FROM dual);
    

    The problem with your first request was that he was looking for sub channels of 0 or more non-virgules. There was as a substring. consisting of 3 characters starting at position 1, he returned "AAA", as expected. Then there was an another substring, the 0 characters, starting at position 4, so it returned NULL. Then, there was a substring of 3 characters starting at position 5, so he returned 'BBB '.

    The problem with your 2nd request was that he was looking for 1 or more non-virgules. 'DDD' is the 3rd this substring.

    Published by: Frank Kulash, on February 16, 2012 11:36
    Added Oracle 11 example

  • How to replace a. null value in obiee report

    Hi gurus,

    In a single column, we get. as the data, how to replace. with the null value

    Please provide your inputs

    Thank you for your time in advance

    Try it out below mentioned formula.

    REPLACE ('service request'. "RS #"(, '.', '') "

Maybe you are looking for