data of cutting using substring and instring, and storage in a new table

Hi all

I have an emp_address 2tables, address as below:
---------------------------------------------------------------
create the table emp_address (emp_id varchar2 (10), address varchar2 (100));

Insert into EMP_ADDRESS
(EMP_ID, ADDRESS)
Values
('101', 'street1 fremont CA 94538');
Insert into EMP_ADDRESS
(EMP_ID, ADDRESS)
Values
("102", "Street.2 fremont, CA 94537');
COMMIT;


create the address table (emp_id varchar2 (10), street varchar2 (20), city varchar2 (15), State varchar2 (10), zip varchar2 (10));

-----------------------------------------------------------------------------
Emp_address data as below:

emp_id address

street1 101 fremont CA 94538

102 fremont, CA 94537 Street.2

------------------------------------------------------------------------------
now I read data emp_address and split the data of the address column and record these data in the address table like as below

emp_id Street City State Zip Code
street1 101 fremont, ca 94538
102 fremont, ca 94537 Street.2

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


I'm trying to divide these data using substring and instring. Actually my problem was between the data a few times I have 1tab or 2tabs and sometimes 3tab. If the number of tab spaces is not constant.

So can u help me in this case.

Thanks in adavnce

position of reference BluShadow

WITH emp_address AS (SELECT   '101' emp_id,
                              'street1 fremont CA 94538' address
                     FROM     DUAL
                     UNION ALL
                     SELECT   '102',
                              'street2  fremont CA 94537'
                     FROM     DUAL),
    emp_address_list_temp AS
      (SELECT       emp_id,
                    SUBSTR (
                      address,
                      DECODE (LEVEL,
                              1, 1,
                              INSTR (address, ' ', 1, LEVEL - 1) + 1
                             ),
                      DECODE (
                        INSTR (address, ' ', 1, LEVEL),
                        0,
                        LENGTH (address),
                        INSTR (address, ' ', 1, LEVEL)
                        - DECODE (LEVEL,
                                  1, 0,
                                  INSTR (address, ' ', 1, LEVEL - 1)
                                 )
                        - 1
                      )
                    )
                      address,
                    LEVEL rn
       FROM         emp_address
       CONNECT BY   LEVEL <=
                      LENGTH (address) - LENGTH (REPLACE (address, ' ')) + 1
       GROUP BY     emp_id, address, LEVEL),
    emp_address_list AS
      (SELECT   emp_id,
                address,
                ROW_NUMBER () OVER (PARTITION BY emp_id ORDER BY rn) rn
       FROM     emp_address_list_temp
       WHERE    TRIM (address) IS NOT NULL)
SELECT     emp_id,
           (SELECT   address
            FROM     emp_address_list e2
            WHERE    e2.emp_id = e1.emp_id
                 AND rn = 1)
             street,
           (SELECT   address
            FROM     emp_address_list e2
            WHERE    e2.emp_id = e1.emp_id
                 AND rn = 2)
             city,
           (SELECT   address
            FROM     emp_address_list e2
            WHERE    e2.emp_id = e1.emp_id
                 AND rn = 3)
             state,
           (SELECT   address
            FROM     emp_address_list e2
            WHERE    e2.emp_id = e1.emp_id
                 AND rn = 4)
             zip
FROM       emp_address_list e1
GROUP BY   emp_id

Tags: Database

Similar Questions

  • How to use substr and instr, where the line of input Multi text

    Hi all

    with

    data in the form of)

    Select ' Mary America.1234 Southridge Park Dr... Samna Lorie.MO.31234..' double val

    Union of all the

    Select 'Bill Johnson.Apartment 3 b. Sterling.VA.20166.3 Plaza Falke' of the double

    )

    Select

    regexp_substr (shipping_instructions, "[^ #] +' 1, 1") name

    , regexp_substr (shipping_instructions, "[^ #] +' 1, 2") address

    , regexp_substr (shipping_instructions, "[^ #] +' 1, 3") city

    , regexp_substr (shipping_instructions, "[^ #] +' 1, 4") State

    , regexp_substr (shipping_instructions, "[^ #] +' 1, 5") zip

    , regexp_substr (shipping_instructions, "[^ #] +' 1, 6") County

    FROM (select REGEXP_REPLACE (val, ' \.)) () [^.])', ' #\1 ") data shipping_instructions)

    (1)'Mary America.1234 Southridge Park Dr... Samna Lorie.MO.31234..'

    (2)'Bill Johnson.Apartment 3 b. Sterling.VA.20166.3 Falke Plaza. »

    "Mary America. 1234 Southridge Park Dr. Samna Lorie. MO.31234..'

    NAME ADDRESS CITY ZIP County SATE

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

    Married America 1234 Southridge Park Dr.    Samna Lorie MO 31234  NULL VALUE

    "Bill Johnson. Apartment 3B. Sterling. VA. 20166. Falke Plaza 3... "

    NAME ADDRESS CITY ZIP County SATE

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

    Bill Johnson apartment 3B Sterling, WILL 20166 3 Falke Plaza.

    Problem

    ---------

    (1) if the value, if the County (if null) value then it shows the ZIP with dot's (.) value, in the 31234 above..,.

    How to solve this problem?

    (2) another possible to fix the code, I want to use substr and InStr.

    (3) who is the best approach?

    Conditions:

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

    (1) shipping_instructions column has the value with "Mary America.1234 Southridge Park Dr... Samna Lorie.MO.31234... »

    This means it combined all the similar name, address, city, State, zip

    (2) we insreted in the table separately.

    =========================

    / * Use Substr and Instr * /.

    =========================

    I used substr and instr, but I'm getting the money results (no point in the address).

    "America Mary. 1234 Southridge Park Dr. Samna Lorie.MO.31234..'


    NAME ADDRESS CITY ZIP County SATE

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

    Mary America 1234 Southridge Park Dr. Samna Lorie MO 31234  NULL VALUE

    But I need the results (no point in the address)

    NAME ADDRESS CITY ZIP County SATE

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

    Mary America 1234 Southridge Park Dr.    Samna Lorie MO 31234  NULL VALUE

    Hello

    994122 wrote:

    Hello

    (1) how do to do this, use the substr and instr functions?

    Thank you

    You can't do all the work with SUBSTR and INSTR; you need regular expressions to obtain a string delimited by a #.

    Once you have such a string, then you can use SUBSTR and INSTR (instead of REGEXP_SUBSTR) to get the separate secondary strings:

    WITH got_delimited_string AS

    (

    SELECT REGEXP_REPLACE (val

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

    , '#\1'

    ) AS delimited_string

    FROM the data

    )

    got_pos AS

    (

    SELECT delimited_string

    , INSTR (delimited_string, "#", 1, 1) AS pos_1

    , INSTR (delimited_string, "#", 1, 2), pos_2

    , INSTR (delimited_string, "#", 1, 3) AS pos_3

    , INSTR (delimited_string, "#", 1, 4) AS pos_4

    , INSTR (delimited_string, "#", 1, 5) AS pos_5

    , INSTR (delimited_string, "#", 1, 6) AS pos_6

    OF got_delimited_string

    )

    SELECT SUBSTR (delimited_string, 1, pos_1 - 1) AS the name

    SUBSTR (delimited_string, pos_1 + 1, pos_2 - (pos_1 + 1)) AS address

    SUBSTR (delimited_string, pos_2 + 1, pos_3 - (pos_2 + 1)) AS city

    SUBSTR (delimited_string, pos_3 + 1, pos_4 - (pos_3 + 1)) AS State

    REPLACE (SUBSTR (delimited_string, pos_4 + 1, pos_5 - (pos_4 + 1))

    , '.'

    )                                                           AS zip

    SUBSTR (delimited_string, pos_5 + 1, pos_6 - (pos_5 + 1)) AS the County

    OF got_pos

    ORDER BY delimited_string

    ;

  • How to use Substr and Instr to get data from a file

    Hi I have a script

    I get a file like this

    1.20, ram, sales

    I get a file as these data as a column

    I want to divide these data into 4 different columns as

    1 20 sales of ram

    Hello

    This query will help you.

    Select

    SUBSTR (C1, 0, INSTR(C1,',')-1).

    SUBSTR (C1, INSTR (C1, ',') + 1, INSTR(C1,',',1,2)-INSTR(C1,',',1,1)-1),

    SUBSTR (C1, INSTR(C1,',',1,2) + 1, INSTR(C1,',',1,3)-INSTR(C1,',',1,2)-1).

    SUBSTR (C1, INSTR(C1,',',1,3) + 1, INSTR(C1,',',1,4)-INSTR(C1,',',1,3)-1)

    SUBSTR (C1, INSTR(C1,',',1,3) + 1)

    BeO

    Select 1, 20, ram, C1 double sales

    )

    Remember that a comma is not really safe as field separator

    Post edited by: DecaXD

  • A string into the text and numbers using SUBSTR and INSTR

    I have the sample data. I know it's terrible database designed for a combination of text and numbers in the same field, but I can't change the business process.

    That's what I have so far:

    set linesize 5000
    
    WITH table_data
         AS (SELECT 'R: JASON BOURNE 12341560' str FROM DUAL UNION ALL
             SELECT 'R: FATS DOMINO 23432342' str FROM DUAL UNION ALL
             SELECT 'R: MARTIN LUTHER KING 3334156' str FROM DUAL UNION ALL
             SELECT 'R: TOM CRUISE 6547123' str FROM DUAL UNION ALL
             SELECT 'R: TOMMY DE GROOT 1212124' str FROM DUAL UNION ALL
             SELECT 'R: GRIM REAPER 1345245' str FROM DUAL UNION ALL
             SELECT 'R: DOCTOR DEATH THE FIRST SMITH 24356178' str FROM DUAL)
    SELECT str
         , TRIM(SUBSTR(str, INSTR(str, ' ', 1, 1), INSTR (str, ' ', 1, 2) - INSTR (str, ' ', 1, 1))) first_name
         , REPLACE(SUBSTR(str, INSTR (str, ' ', 1, 2)+1, 999), SUBSTR(str,LENGTH(str)-6,7), '') last_name
         , SUBSTR(str,LENGTH(str)-6,7) emp_num
      FROM table_data;
    
    STR                                      FIRST_NAME    LAST_NAME                 EMP_NUM
    ---------------------------------------- -----------------------------------------------
    R: JASON BOURNE 12341560                 JASON         BOURNE 1                  2341560
    R: FATS DOMINO 23432342                  FATS          DOMINO 2                  3432342
    R: MARTIN LUTHER KING 3334156            MARTIN        LUTHER KING               3334156
    R: TOM CRUISE 6547123                    TOM           CRUISE                    6547123
    R: TOMMY DE GROOT 1212124                TOMMY         DE GROOT                  1212124
    R: GRIM REAPER 1345245                   GRIM          REAPER                    1345245
    R: DOCTOR DEATH THE FIRST SMITH 24356178 DOCTOR        DEATH THE FIRST SMITH 2   4356178
    
    7 rows selected.
    

    I need to:

    1 extract the first name - which is always the first name after the 'r' - I've got that little works very well.

    2 extract the name - should be the last word before the number, if e.g. for the last night, I wish only that 'SMITH' and 'KING' for the 3rd line and "GROOT" for the 5th line.

    3. remove the number at the end, regardless of the length - some of the examples above are 8 long numbers so my attempt above does not work.

    I can't use any REGEXP or REGEXP_SUBSTR because they are not registered in the EUL I'm using discoverer, I can only use INSTR AND SUBSTR.

    I was wondering if someone might be able to help please?

    Any advice much appreciated.

    Thank you

    AW, go on them, as it's Christmas, I'm feeling generous...

    SQL > ed
    A written file afiedt.buf

    1. WITH table_data (SELECT "r: JASON BOURNE 12341560' DOUBLE UNION ALL STR ')
    2. SELECT "r: FATS DOMINO 23432342' str OF DOUBLE UNION ALL.
    3. SELECT "r: MARTIN LUTHER KING 3334156' str OF DOUBLE UNION ALL.
    4. SELECT "r: TOM CRUISE 6547123' str OF DOUBLE UNION ALL.
    5. SELECT "r: TOMMY GROOT 1212124' str OF DOUBLE UNION ALL.
    6. SELECT "r: GRIM REAPER 1345245' str OF DOUBLE UNION ALL.
    7. SELECT "r: DOCTOR DEATH FIRST SMITH 24356178' FROM DUAL str.
    8                     )
    9 select substr (str, 1, instr(str,' ')-1) as a first name
    10, substr (substr (str, 1, instr(str,' ',-1)-1), instr (substr (str, 1, instr(str,' ',-1)-1),' ', 1) + 1) as last_name
    11, substr (str, instr (str, ' ',-1) + 1) as emp_num
    12 years of (select replace (str,'R: ') as str)
    table_data 13
    14*        )
    SQL > /.

    FIRST_NAME LAST_NAME EMP_NUM
    ---------------------------------------- ---------------------------------------- ----------------------------------------
    JASON BOURNE 12341560
    FATS                                     DOMINO                                   23432342
    MARTIN                                   KING                                     3334156
    TOM                                      CRUISE                                   6547123
    TOMMY                                    GROOT                                    1212124
    GRIM                                     REAPER                                   1345245
    DOCTOR SMITH 24356178

    7 selected lines.

  • using substr and instr

    Hi all

    create table abc (str varchar2 (10))

    insert into abc values ('ABC - DEF')

    Insert into abc values('ABC/DEF')

    Insert into abc values ('ABC DEF')

    Insert into abc values('ABC.) DEF')

    insert into abc values ('ABC DEF')

    I need to put as ABCDEF for all values, if possible using sustr and instr

    Thank you

    Three ways:

    Select replace (str, translate(str,'~ABCDEFGHIJKLMNOPQRSTUVWXYZ','~')) in abc;  -assuming a single character is there in your data...

    -generic way to remove all of the other characters keeping uppercase alphabets

    SELECT TRANSLATE (str, ' ~' |) TRANSLATE (str, ' ~ ABCDEFGHIJKLMNOPQRSTUVWXYZ ',' ~'), ' ~') of ABC;

    -Using regular expressions

    Select regexp_replace(str,'[^[:alpha:]]') in abc;

    See you soon,.

    Manik.

  • Use Substr and InStr

    I have created table:

    create table wekaRules_productmgr)
    The rule ID number,
    WekaRule varchar2 (500),
    VARCHAR2 (250) antecedent.
    VARCHAR2 (250) resulting.
    );

    The table contains the following data with insert statements:

    INSERT INTO wekaRules_productmgr (ID rule, WekaRule)
    VALUES (1, ' PM_PRICE_REDUCTION_TYPE = None 9828 == > PM_COUPON_TYPE = None 9828 conf: (1) lift: (1.06) conv: (576.86)') lev: (0.05) [576];

    INSERT INTO wekaRules_productmgr (ID rule, WekaRule)
    VALUES (2, ' PM_AD_TYPE = None 9684 == > PM_PRICE_REDUCTION_TYPE = None 9684 conf: (1) lift: (1.12) conv: (1063.13)') lev: (0.1) [1063];

    INSERT INTO wekaRules_productmgr (ID rule, WekaRule)
    VALUES (3, ' PM_AD_TYPE = None 9684 == > PM_COUPON_TYPE = None 9684 conf: (1) lift: (1.06) conv: (568.41)') lev: (0.05) [568];

    The values for the last two columns in the wekaRules_productmgr table is contained in the string values for each statement. For example, in the # 1 folder, the values are (from left to right):
    history = PM_PRICE_REDUCTION_TYPE = None
    result = PM_COUPON_TYPE = None


    I need to find a way to analyze the values in each record and update in the appropriate table columns. So to case # 1, I need to update columns with the values given above, such as the records would look like:

    Rule ID History Resulting          
    1 PM_PRICE_REDUCTION_TYPE = None PM_COUPON_TYPE = None
    2 PM_AD_TYPE = None PM_PRICE_REDUCTION_TYPE = None
    3 PM_AD_TYPE = None PM_COUPON_TYPE = None

    I have tried this solution, but cannot very well:

    UPDATE wekaRules_productmgr SET history =
    (SELECT SUBSTR (wekarule, 1, (INSTR(wekarule,' ',1,1)-1)) 'history')
    OF wekaRules_productmgr);

    I also have a similar one for the suite. Does anyone have any suggestions? Any help is appreciated. Thank you!

    I saw there is anonther detachment of you the same theme. If this can help you:

     SELECT
           regexp_substr(wekarule,'[a-zA-Z_]+ *= *[a-zA-Z_]+',1,1) antecedent,
           regexp_substr(wekarule,'[a-zA-Z_]+ *= *[a-zA-Z_]+',1,2) consequent,
           LTRIM(REGEXP_SUBSTR(wekarule, 'conf:\([^\)]+'), 'conf:(') conf,
           LTRIM(REGEXP_SUBSTR(wekarule, 'lift:\([^\)]+'), 'lift:(') lift,
           LTRIM(REGEXP_SUBSTR(wekarule, 'lev:\([^\)]+'), 'lev:(') lev,
           LTRIM(REGEXP_SUBSTR(wekarule, 'conv:\([^\)]+'), 'conv:(') conv
    FROM   wekaRules_productmgr;
    

    Published by: hm on 11.10.2010 11:29

  • Help on using substr and instr functions

    Hello

    I'm trying to go back to the first three letters of the first word and all the last word in a description field. For example, if the description is 'grilled steak' the query should return "steak gri. That's what I have so far:

    SELECT SUPPLIER_ID, PRODUCT_CODE, SUBSTR (DESCRIPTION, 1, 3). ' ' || SUBSTR (DESCRIPTION, INSTR (DESCRIPTION, ' ', 3)) AS A DESCRIPTION
    OF L_FOODS;

    Unfortunately, if the first word is the final word, it returns something like "sod soda." Does anyone have any advice or suggestions? Any help would be appreciated.

    Hi and welcome to the forum!

    It is always helpful if you identify your version of Oracle. The solution below depends on 10.1 and upward.

    What you could do is include a conditional around your instr/substr functions that checks the number of spaces between words. If it is greater or equal two one then there are at least two words. For example:

    WITH test_data AS
    (
         SELECT 'grilled steak' AS DESCRIPTION FROM DUAL UNION ALL
         SELECT 'large pepperoni pizza' AS DESCRIPTION FROM DUAL UNION ALL
         SELECT 'soda' AS DESCRIPTION FROM DUAL
    )
    SELECT     (CASE
              WHEN LENGTH(REGEXP_REPLACE(TRIM(DESCRIPTION),'[^[:space:]]','')) > 0
              THEN SUBSTR(DESCRIPTION,1,3) || SUBSTR(DESCRIPTION,INSTR(DESCRIPTION,' ',-1))
              ELSE SUBSTR(DESCRIPTION,1,3)
         END) AS DESCRIPTION
    FROM     test_data
    

    Results

    SQL> /
    
    DESCRIPTION
    -----------------------
    gri steak
    lar pizza
    sod
    

    : EDITION:

    I also wanted to add this:

    SUBSTR(DESCRIPTION, INSTR(DESCRIPTION, ' ', 3))
    

    May not return the expected results. If your description field contains more than two words he will return all remaining words not only the LAST Word. See my solution above for what I believe is the correct version.

    HTH!

  • Comparison of the two bays and by generating a new table. ???

    Hi guys

    can someone solve this problem. Please...

    I have two tables, a table of strings and other's selectedLayers array with the same source names(a,b,c) selected in the aftermath.

    Now I want to generate the new table by using the string in [mySelectedComps]. source.name.

    For example

    var callName = [' a b "," "];

    var mySelectedComps = app.project.activeItems.selectedLayers; (eg.i chose a, b, c of comps in afx)

    var newArray = [];


    If ([callName][] mySelectedComps. source.nameof ==) {}

    newArray.push ();

    }

    How iterate two tables at the same time or how to compare an element in an array Array1 with all elements of array2 until it returns true/false.and, then proceed to the next item in the table 1. ??

    I think that you just need nested loops, something like this (untested):

    for (var i = 0; i)< myselectedcomps.length;="">

    for (var j = 0; j)< callname.length;="">

    If (callName [j] is {mySelectedComps [i].source.name)}

    newArray.push (mySelectedComps [i]);

    break;

    }

    }

    }

    Dan

  • Insertion of the calculated values and values into a new table. How?

    Hi guys. Had a slight dilemma here. My problem is that:

    1. I have an average of two values (in the same column) for the 2 different lines (which is 7 days before the event and the other which is 14 days). I need to insert a new table

    WITH

    2. the data in some of the other columns of the lines of these two values I have on average.

    So, for example, I have the source table table S, with the values of Company_Name, Date, name of the Emp, salary, Date. I have to calculate the average salary, corresponding to the date criteria I described before. So I have to insert into another table (the average value) while keeping other data (Date, name of the Emp) etc.

    This is really confusing me. I think that the mix of simple db and sql pl theory is to play with my head.

    I know that the scenario is a bit confused, so please ask any questions! I'll check this thread very frequently!

    Frankly speaking, I'm lost.

    Please post some samples of entry and your required output in a formatted way.

    Kind regards.

    LOULOU.

  • Substr and InStr

    Hi all

    I have a table where a column has a data character in the format below:

    * '00003434' *.
    * '00123' *.
    * '0000045' *.

    If I want to eliminate all zeros on the left, how can I do using substr and instr? or is there an easier way?

    Thank you

    KK

    Try again with

    Select ltrim ('00003434 ', ' 0') of double;

  • Combination of substring and instring in RTF - dynamic signature images url

    I am unable to use a combination of substring and instring in RTF model.

    I have a BUYER_LAST_NAME column, which has a Jean Dupont value. I like to shoot 'john' on this channel.

    I tried to create a variable using <? xdoxslt:set_variable($_XDOCTX,_'new_name',_'')? >

    So I want to do a get variable using substr and InStr.

    <? xdoxslt:get_variable (substring _XDOCTX, BUYER_LAST_NAME, $(DOCUMENT_BUYER_LAST_NAME, 1, instring(BUYER_LAST_NAME,' ')-1))? >

    The command above does not work as a substring and instring aren't xdoxslt operations.

    I tried to do this using xdofx: <? xdofx:substr (BUYER_LAST_NAME, 1, Instr(BUYER_LAST_NAME,' ')-1)? >

    The above work, but I don't know how to make a variable defined using xdofx. Please help me on this.

    Published:

    I want to use this field in a dynamic signature display. But I can't call substring-before command as part of the url.

    URL: {(concat('${OA_MEDIA}','/purchase_order/signatures/',.//BUYER_FIRST_NAME,'_',.//BUYER_LAST_NAME,'.jpg')}

    I want to change the BUYER_LAST_NAME here.

    I'm working on

    URL: {concat (' ${OA_MEDIA} ',' / purchase_order/signatures /',. / / DOCUMENT_BUYER_FIRST_NAME, "_",. / /, '.jpg')}

    But it does not work.

    ->

    URL: {concat (' ${OA_MEDIA} ','/ purchase_order/signatures /',. / / DOCUMENT_BUYER_FIRST_NAME, '_', substring-before(.//DOCUMENT_BUYER_LAST_NAME, ' '), '.jpg')}

    who is working for me

  • RegExp_. Using substr

    Hi - I need to extract the string after the last ' / ' and everything before the last ' / '. Possible to do using substr and instr but I would like to know how this can be done using regexp_substr.

    for example: / Merchants/Retail/ShopBrand/Home/Holidays/Bed

    My requirement is to extract 'Reads', which is after the last ' / ' and '' / Merchants/Retail/ShopBrand/Home/Holidays which is before the last ' / '.

    Help, please

    Could you give the explanation as well to '. * /', '' ?

    We receive all the strings until the last ' / ' and substituting null

    And my second (not a Cleaver) option would be:

    SELECT REGEXP_REPLACE(REGEXP_SUBSTR('/Merchants/Retail/ShopBrand/Home/Holidays/Bed', '.*/'), '.$', '') FIRST_REQUIREMENT FROM DUAL;
    

    Here, we remove the last character. Take a look at the documentation to go further: http://docs.oracle.com/database/121/ADFNS/adfns_regexp.htm#ADFNS1003

    Kind regards.

  • How to extract 1 ASA and put them in the new table

    Hello

    Can someone tell me how to extract a table and put in the new table. (eg. I have a table with no 1 to 1000, I would extract only 1, 30, 60, 90,...)  ?

    Please advise me.

    Thank you

    concerning


  • Question to load data using sql loader in staging table, and then in the main tables!

    Hello

    I'm trying to load data into our main database table using SQL LOADER. data will be provided in separate pipes csv files.

    I have develop a shell script to load the data and it works fine except one thing.

    Here are the details of a data to re-create the problem.

    Staging of the structure of the table in which data will be filled using sql loader

    create table stg_cmts_data (cmts_token varchar2 (30), CMTS_IP varchar2 (20));

    create table stg_link_data (dhcp_token varchar2 (30), cmts_to_add varchar2 (200));

    create table stg_dhcp_data (dhcp_token varchar2 (30), DHCP_IP varchar2 (20));

    DATA in the csv file-

    for stg_cmts_data-

    cmts_map_03092015_1.csv

    WNLB-CMTS-01-1. 10.15.0.1

    WNLB-CMTS-02-2 | 10.15.16.1

    WNLB-CMTS-03-3. 10.15.48.1

    WNLB-CMTS-04-4. 10.15.80.1

    WNLB-CMTS-05-5. 10.15.96.1

    for stg_dhcp_data-

    dhcp_map_03092015_1.csv

    DHCP-1-1-1. 10.25.23.10, 25.26.14.01

    DHCP-1-1-2. 56.25.111.25, 100.25.2.01

    DHCP-1-1-3. 25.255.3.01, 89.20.147.258

    DHCP-1-1-4. 10.25.26.36, 200.32.58.69

    DHCP-1-1-5 | 80.25.47.369, 60.258.14.10

    for stg_link_data

    cmts_dhcp_link_map_0309151623_1.csv

    DHCP-1-1-1. WNLB-CMTS-01-1,WNLB-CMTS-02-2

    DHCP-1-1-2. WNLB-CMTS-03-3,WNLB-CMTS-04-4,WNLB-CMTS-05-5

    DHCP-1-1-3. WNLB-CMTS-01-1

    DHCP-1-1-4. WNLB-CMTS-05-8,WNLB-CMTS-05-6,WNLB-CMTS-05-0,WNLB-CMTS-03-3

    DHCP-1-1-5 | WNLB-CMTS-02-2,WNLB-CMTS-04-4,WNLB-CMTS-05-7

    WNLB-DHCP-1-13 | WNLB-CMTS-02-2

    Now, after loading these data in the staging of table I have to fill the main database table

    create table subntwk (subntwk_nm varchar2 (20), subntwk_ip varchar2 (30));

    create table link (link_nm varchar2 (50));

    SQL scripts that I created to load data is like.

    coil load_cmts.log

    Set serveroutput on

    DECLARE

    CURSOR c_stg_cmts IS SELECT *.

    OF stg_cmts_data;

    TYPE t_stg_cmts IS TABLE OF stg_cmts_data % ROWTYPE INDEX BY pls_integer;

    l_stg_cmts t_stg_cmts;

    l_cmts_cnt NUMBER;

    l_cnt NUMBER;

    NUMBER of l_cnt_1;

    BEGIN

    OPEN c_stg_cmts.

    Get the c_stg_cmts COLLECT in BULK IN l_stg_cmts;

    BECAUSE me IN l_stg_cmts. FIRST... l_stg_cmts. LAST

    LOOP

    SELECT COUNT (1)

    IN l_cmts_cnt

    OF subntwk

    WHERE subntwk_nm = l_stg_cmts (i) .cmts_token;

    IF l_cmts_cnt < 1 THEN

    INSERT

    IN SUBNTWK

    (

    subntwk_nm

    )

    VALUES

    (

    l_stg_cmts (i) .cmts_token

    );

    DBMS_OUTPUT. Put_line ("token has been added: ' |") l_stg_cmts (i) .cmts_token);

    ON THE OTHER

    DBMS_OUTPUT. Put_line ("token is already present'");

    END IF;

    WHEN l_stg_cmts EXIT. COUNT = 0;

    END LOOP;

    commit;

    EXCEPTION

    WHILE OTHERS THEN

    Dbms_output.put_line ('ERROR' |) SQLERRM);

    END;

    /

    output

    for dhcp


    coil load_dhcp.log

    Set serveroutput on

    DECLARE

    CURSOR c_stg_dhcp IS SELECT *.

    OF stg_dhcp_data;

    TYPE t_stg_dhcp IS TABLE OF stg_dhcp_data % ROWTYPE INDEX BY pls_integer;

    l_stg_dhcp t_stg_dhcp;

    l_dhcp_cnt NUMBER;

    l_cnt NUMBER;

    NUMBER of l_cnt_1;

    BEGIN

    OPEN c_stg_dhcp.

    Get the c_stg_dhcp COLLECT in BULK IN l_stg_dhcp;

    BECAUSE me IN l_stg_dhcp. FIRST... l_stg_dhcp. LAST

    LOOP

    SELECT COUNT (1)

    IN l_dhcp_cnt

    OF subntwk

    WHERE subntwk_nm = l_stg_dhcp (i) .dhcp_token;

    IF l_dhcp_cnt < 1 THEN

    INSERT

    IN SUBNTWK

    (

    subntwk_nm

    )

    VALUES

    (

    l_stg_dhcp (i) .dhcp_token

    );

    DBMS_OUTPUT. Put_line ("token has been added: ' |") l_stg_dhcp (i) .dhcp_token);

    ON THE OTHER

    DBMS_OUTPUT. Put_line ("token is already present'");

    END IF;

    WHEN l_stg_dhcp EXIT. COUNT = 0;

    END LOOP;

    commit;

    EXCEPTION

    WHILE OTHERS THEN

    Dbms_output.put_line ('ERROR' |) SQLERRM);

    END;

    /

    output

    for link -.

    coil load_link.log

    Set serveroutput on

    DECLARE

    l_cmts_1 VARCHAR2 (4000 CHAR);

    l_cmts_add VARCHAR2 (200 CHAR);

    l_dhcp_cnt NUMBER;

    l_cmts_cnt NUMBER;

    l_link_cnt NUMBER;

    l_add_link_nm VARCHAR2 (200 CHAR);

    BEGIN

    FOR (IN) r

    SELECT dhcp_token, cmts_to_add | ',' cmts_add

    OF stg_link_data

    )

    LOOP

    l_cmts_1: = r.cmts_add;

    l_cmts_add: = TRIM (SUBSTR (l_cmts_1, 1, INSTR (l_cmts_1, ',') - 1));

    SELECT COUNT (1)

    IN l_dhcp_cnt

    OF subntwk

    WHERE subntwk_nm = r.dhcp_token;

    IF l_dhcp_cnt = 0 THEN

    DBMS_OUTPUT. Put_line ("device not found: ' |") r.dhcp_token);

    ON THE OTHER

    While l_cmts_add IS NOT NULL

    LOOP

    l_add_link_nm: = r.dhcp_token |' _TO_' | l_cmts_add;

    SELECT COUNT (1)

    IN l_cmts_cnt

    OF subntwk

    WHERE subntwk_nm = TRIM (l_cmts_add);

    SELECT COUNT (1)

    IN l_link_cnt

    LINK

    WHERE link_nm = l_add_link_nm;

    IF l_cmts_cnt > 0 AND l_link_cnt = 0 THEN

    INSERT INTO link (link_nm)

    VALUES (l_add_link_nm);

    DBMS_OUTPUT. Put_line (l_add_link_nm |) » '||' Has been added. ") ;

    ELSIF l_link_cnt > 0 THEN

    DBMS_OUTPUT. Put_line (' link is already present: ' | l_add_link_nm);

    ELSIF l_cmts_cnt = 0 then

    DBMS_OUTPUT. Put_line (' no. CMTS FOUND for device to create the link: ' | l_cmts_add);

    END IF;

    l_cmts_1: = TRIM (SUBSTR (l_cmts_1, INSTR (l_cmts_1, ',') + 1));

    l_cmts_add: = TRIM (SUBSTR (l_cmts_1, 1, INSTR (l_cmts_1, ',') - 1));

    END LOOP;

    END IF;

    END LOOP;

    COMMIT;

    EXCEPTION

    WHILE OTHERS THEN

    Dbms_output.put_line ('ERROR' |) SQLERRM);

    END;

    /

    output

    control files -

    DOWNLOAD THE DATA

    INFILE 'cmts_data.csv '.

    ADD

    IN THE STG_CMTS_DATA TABLE

    When (cmts_token! = ") AND (cmts_token! = 'NULL') AND (cmts_token! = 'null')

    and (cmts_ip! = ") AND (cmts_ip! = 'NULL') AND (cmts_ip! = 'null')

    FIELDS TERMINATED BY ' |' SURROUNDED OF POSSIBLY "" "

    TRAILING NULLCOLS

    ('RTRIM (LTRIM (:cmts_token))' cmts_token,

    cmts_ip ' RTRIM (LTRIM(:cmts_ip)) ")". "

    for dhcp.


    DOWNLOAD THE DATA

    INFILE 'dhcp_data.csv '.

    ADD

    IN THE STG_DHCP_DATA TABLE

    When (dhcp_token! = ") AND (dhcp_token! = 'NULL') AND (dhcp_token! = 'null')

    and (dhcp_ip! = ") AND (dhcp_ip! = 'NULL') AND (dhcp_ip! = 'null')

    FIELDS TERMINATED BY ' |' SURROUNDED OF POSSIBLY "" "

    TRAILING NULLCOLS

    ('RTRIM (LTRIM (:dhcp_token))' dhcp_token,

    dhcp_ip ' RTRIM (LTRIM(:dhcp_ip)) ")". "

    for link -.

    DOWNLOAD THE DATA

    INFILE 'link_data.csv '.

    ADD

    IN THE STG_LINK_DATA TABLE

    When (dhcp_token! = ") AND (dhcp_token! = 'NULL') AND (dhcp_token! = 'null')

    and (cmts_to_add! = ") AND (cmts_to_add! = 'NULL') AND (cmts_to_add! = 'null')

    FIELDS TERMINATED BY ' |' SURROUNDED OF POSSIBLY "" "

    TRAILING NULLCOLS

    ('RTRIM (LTRIM (:dhcp_token))' dhcp_token,

    cmts_to_add TANK (4000) RTRIM (LTRIM(:cmts_to_add)) ")" ""

    SHELL SCRIPT-

    If [!-d / log]

    then

    Mkdir log

    FI

    If [!-d / finished]

    then

    mkdir makes

    FI

    If [!-d / bad]

    then

    bad mkdir

    FI

    nohup time sqlldr username/password@SID CONTROL = load_cmts_data.ctl LOG = log/ldr_cmts_data.log = log/ldr_cmts_data.bad DISCARD log/ldr_cmts_data.reject ERRORS = BAD = 100000 LIVE = TRUE PARALLEL = TRUE &

    nohup time username/password@SID @load_cmts.sql

    nohup time sqlldr username/password@SID CONTROL = load_dhcp_data.ctl LOG = log/ldr_dhcp_data.log = log/ldr_dhcp_data.bad DISCARD log/ldr_dhcp_data.reject ERRORS = BAD = 100000 LIVE = TRUE PARALLEL = TRUE &

    time nohup sqlplus username/password@SID @load_dhcp.sql

    nohup time sqlldr username/password@SID CONTROL = load_link_data.ctl LOG = log/ldr_link_data.log = log/ldr_link_data.bad DISCARD log/ldr_link_data.reject ERRORS = BAD = 100000 LIVE = TRUE PARALLEL = TRUE &

    time nohup sqlplus username/password@SID @load_link.sql

    MV *.log. / log

    If the problem I encounter is here for loading data in the link table that I check if DHCP is present in the subntwk table, then continue to another mistake of the newspaper. If CMTS then left create link to another error in the newspaper.

    Now that we can here multiple CMTS are associated with unique DHCP.

    So here in the table links to create the link, but for the last iteration of the loop, where I get separated by commas separate CMTS table stg_link_data it gives me log as not found CMTS.

    for example

    DHCP-1-1-1. WNLB-CMTS-01-1,WNLB-CMTS-02-2

    Here, I guess to link the dhcp-1-1-1 with balancing-CMTS-01-1 and wnlb-CMTS-02-2

    Theses all the data present in the subntwk table, but still it gives me journal wnlb-CMTS-02-2 could not be FOUND, but we have already loaded into the subntwk table.

    same thing is happening with all the CMTS table stg_link_data who are in the last (I think here you got what I'm trying to explain).

    But when I run the SQL scripts in the SQL Developer separately then it inserts all valid links in the table of links.

    Here, she should create 9 lines in the table of links, whereas now he creates only 5 rows.

    I use COMMIT in my script also but it only does not help me.

    Run these scripts in your machine let me know if you also get the same behavior I get.

    and please give me a solution I tried many thing from yesterday, but it's always the same.

    It is the table of link log

    link is already present: dhcp-1-1-1_TO_wnlb-cmts-01-1

    NOT FOUND CMTS for device to create the link: wnlb-CMTS-02-2

    link is already present: dhcp-1-1-2_TO_wnlb-cmts-03-3
    link is already present: dhcp-1-1-2_TO_wnlb-cmts-04-4

    NOT FOUND CMTS for device to create the link: wnlb-CMTS-05-5

    NOT FOUND CMTS for device to create the link: wnlb-CMTS-01-1

    NOT FOUND CMTS for device to create the link: wnlb-CMTS-05-8
    NOT FOUND CMTS for device to create the link: wnlb-CMTS-05-6
    NOT FOUND CMTS for device to create the link: wnlb-CMTS-05-0

    NOT FOUND CMTS for device to create the link: wnlb-CMTS-03-3

    link is already present: dhcp-1-1-5_TO_wnlb-cmts-02-2
    link is already present: dhcp-1-1-5_TO_wnlb-cmts-04-4

    NOT FOUND CMTS for device to create the link: wnlb-CMTS-05-7

    Device not found: wnlb-dhcp-1-13

    IF NEED MORE INFORMATION PLEASE LET ME KNOW

    Thank you

    I felt later in the night that during the loading in the staging table using UNIX machine he created the new line for each line. That is why the last CMTS is not found, for this I use the UNIX 2 BACK conversion and it starts to work perfectly.

    It was the dos2unix error!

    Thank you all for your interest and I may learn new things, as I have almost 10 months of experience in (PLSQL, SQL)

  • SUBSTR and INSTR function

    Hi gurus,

    I have the data as follows:

    data
    -----------------------------------------------------------------------------------------------------------------------
    ' BIDIE01H / TXT:ZUNE = HA011, CellIndex = 144 /CAI:452 - 01-32201-47001 / CAI:45201F7dc9b79a'
    ' BIDIE01H / TXT:ZUNE = HA111, CellIndex = 124 /CAI:452 - 01-32201-471 / CAI:45201F7dc9b79b'


    and I'm writing a SQL results:

    CAI
    ---------
    452 01-32201-47001
    452 01-32201-471

    Any idea to do? I tried around with SUBSTR and INSTR functions but not yet sucessed.

    Thank you
    Alex

    something like:

    with my_tab as (select 'BIDIE01H/TXT:ZUNE=HA011, CellIndex=144 /CAI:452-01-32201-47001/CAI:45201F7dc9b79a' col1 from dual union all
                    select 'BIDIE01H/TXT:ZUNE=HA111, CellIndex=124 /CAI:452-01-32201-471/CAI:45201F7dc9b79b' col1 from dual)
    -- end of mimicking your data: USE SQL below:
    select substr(col1, instr(col1, '/CAI:', 1) + 5, instr(col1, '/CAI:', 1, 2) - instr(col1, '/CAI:', 1) - 5 ) CAI
    from my_tab
    
    CAI
    --------------------------------------------------------------------------------
    452-01-32201-47001
    452-01-32201-471     
    

Maybe you are looking for

  • I have a problem signing in itunes

    I have a problem with iTunes

  • Why people recommend two apple ID

    I hear a lot of people, they also offer to make me more than one identifier apple, one is to purchase items and other apple ID to use with icloud imessage and facetime can someone explain please I Heve one and use it to do everything

  • Restore Iphone6s +.

    I just bought my new Iphone6s +. I want to restore all the information from my old iphone to my new. But iTunes show me 'the iPhone is useless because it requires a newer version of iTunes. Go to www.itunes.com to download the latest version of iTune

  • Support for Windows XP. What is the best OS to install, Windows 8, 7, 8.1?

    I have Windows XP Professional and see that Windows XP will support ending April 8, 2014. My question is quite simple: what is the best operating system to install instead of XP? Is - this Windows 8, Windows 7 or Windows 8.1? I don't want a touchscre

  • House broken xp disc

    I have a genuine product key and family xp disc but the disc is damaged and I need to get a replacement one can get it from microsoft and how do I do this please. all advice welcome