Question

Continue...............

Asked by: khushi2003

That posting was getting large and taking whole time to download the page so...i have moved here.

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2004-04-09 at 06:16:05ID20948849
Topic

Oracle Database

Participating Experts
1
Points
20
Comments
4

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Downloading whole site...
    Hello all! I wasn't on EE really long... and now I got a question! I got one link: http://physnet.uni-oldenburg.de/PhysNet/education.html How can I transfer whole site to my computer so I can browse it offline? I need all animations, and the most complicated, Java Applets....
  2. Download
    I'm a bit lost.... Completely totally lost to be honest! All the info is right there on the web, but I'm too much of a beginner I guess: a beginning developer. Done some courses SQL and PL/SQL and downloaded (some time ago) 9i stuff to get a server + client running on XP and ...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: pratikroyPosted on 2004-04-12 at 03:12:51ID: 10804337

In my TAB_EX table I have the following records :

ID  NAME               COMP_NAME                 FLD1                                DISTRICT
--- ------------------ ------------------------- ----------------------------------- ---------------
1   Alan Border                                  1 Ada Street                        Salt Lake
2   Steve Bucknor                                1 A Kalinda Street                  Salt Lake
3   Tony Day                                     1/13 Burrawang Street               Salt Lake
4   Phil Hampson                                 1/21-23 Chelmsford Road             Salt Lake
5   John Reid                                    10/1a Frederick Street              Salt Lake
6   Steve Wright                                 161? Lang Street                    Salt Lake
7   Jason Gillespie                              368 Cnr Barker & Anzac Pde          Salt Lake
8   Greg Chapman                                 5/70-74/ Wilson Street              Salt Lake
9   Paul Radcliffe                               Shop 2 4-14 Claudia Road            Salt Lake
10  George Hemmingway                            PO Box 558                          Salt Lake
11  Dave Mathews                                 Lot 4 Mungerie Road                 Salt Lake
12  Jonty Rhodes                                 Level 4/65 Albert Avenue            Salt Lake
13  Clive Llyode                                 Cnr Warf Rd & Hollywood Rd          Salt Lake
14  John Davies                                  Unit 85 51 Little Willandra Rd      Salt Lake
15  Stephen Matthews                             Suite 2 Ground Floor                Salt Lake
16  Chris Harris                                 Street                              Salt Lake
17                     Anzac Solicitors          Burwood Road                        Salt Lake
18                     Joe & Joyce Travels       Paramatta Street                    Salt Lake
19  Ruth Hughes                                  Harmondsworth Street                Salt Lake
20                     Greenwood Technologies    Cranston Drive                      Salt Lake
21                     Haywire News Ltd          Martindale Road                     Salt Lake
22  Mark Jones                                   12 Ada Street                       Wellington
23  Peter Radcliffe                              14 Ada Street                       Bhubneshwar
24  Michael Chang                                15 Ada Street                       Kolkata
25  Chris Gayle                                  18 Ada Street                       Darjeeling
26  Peter Gibson                                 10a M'cac Street                    Salt Lake
27  Mike Atherton                                11 Up-town Road                     Salt Lake
28                     Ranbaxy Ltd               upper & lower Street                Salt Lake
29                     Glaxo Smith Cline         Hill Road & downhill Road           Salt Lake
30                     20th Century Fox          Dance Pde & mahal Street            Salt Lake

30 rows selected.


After executing the code I get the following records in TAB_EX1 :

ID  NAME               COMP_NAME                 ROADNUM         ROADNAME                  POSTCODE
--- ------------------ ------------------------- --------------- ------------------------- --------
1   Alan Border                                  1               Ada Street                123345
2   Steve Bucknor                                1               A Kalinda Street          123345
3   Tony Day                                     1/13            Burrawang Street          123345
4   Phil Hampson                                 1/21-23         Chelmsford Road           123345
5   John Reid                                    10/1a           Frederick Street          123345
6   Steve Wright                                 161             Lang Street               123345
8   Greg Chapman                                 5/70-74         Wilson Street             123345
9   Paul Radcliffe                               Shop 2 4-14     Claudia Road              123345
10  George Hemmingway                                            PO Box 558                123345
11  Dave Mathews                                 Lot 4           Mungerie Road             123345
12  Jonty Rhodes                                 Level 4/65      Albert Avenue             123345
14  John Davies                                  Unit 85 51      Little Willandra Rd       123345
17                     Anzac Solicitors                          Burwood Road              123345
18                     Joe & Joyce Travels                       Paramatta Street          123345
20                     Greenwood Technologies                    Cranston Drive            123345
21                     Haywire News Ltd                          Martindale Road           123345
24  Michael Chang                                15              Ada Street                123348
25  Chris Gayle                                  18              Ada Street                123350
26  Peter Gibson                                 10a             M'cac Street              123345
27  Mike Atherton                                11              Up-town Road              123345
28                     Ranbaxy Ltd                               upper & lower Street      123345
29                     Glaxo Smith Cline                         Hill Road & downhill Road 123345
30                     20th Century Fox                          Dance Pde & mahal Street  123345

23 rows selected.

And following records are inserted in Error table :

ID  NAME               COMP_NAME            FLD1                         DISTRICT      ERRMSG
--- ------------------ -------------------- ---------------------------- ------------- -------------
7   Jason Gillespie                         368 Cnr Barker & Anzac Pde   Salt Lake     Road Number not provided for personal address
13  Clive Llyode                            Cnr Warf Rd & Hollywood Rd   Salt Lake     Road Number not provided for personal address
15  Stephen Matthews                        Suite 2 Ground Floor         Salt Lake     Invalid Road Name
16  Chris Harris                            Street                       Salt Lake     Invalid address format
19  Ruth Hughes                             Harmondsworth Street         Salt Lake     Road Number not provided for personal address
22  Mark Jones                              12 Ada Street                Wellington    No Data Found for District in PINCODES table
23  Peter Radcliffe                         14 Ada Street                Bhubneshwar   No Data Found for District in PINCODES table

7 rows selected.

You may notice, that the addresses like M'cac Street, upper & lower Street, Hill Road & downhill Road and Dance Pde & mahal Street are validated properly, and are put in the right fields.

Following is the final code that I have executed :

--create or replace procedure proc_tab_ex as
declare
    v_roadno   varchar2(50);
    v_roadnm   varchar2(200);
    v_lastnum  varchar(100);
    v_tempnm   varchar2(200);
    v_addrtyp  varchar2(30);
    v_postcode varchar2(30);
    v_errmsg   varchar2(250);

    cursor c1 is
    select * from tab_ex;

    FUNCTION f_addr_type ( fulladdr varchar2)
    RETURN VARCHAR2 IS
     v_space VARCHAR2(30);
    BEGIN
        IF INSTR(fulladdr, 'Cnr') > 0 THEN
            v_space := 'Cnr';
        END IF;
        IF INSTR(fulladdr, 'Shop') > 0 THEN
            v_space := 'Shop';
        END IF;
        IF INSTR(fulladdr, 'PO Box') > 0 THEN
            v_space := 'PO Box';
        END IF;
        IF INSTR(fulladdr, 'Lot') > 0 THEN
            v_space := 'Lot';
        END IF;
        IF INSTR(fulladdr, 'Level') > 0 THEN
            v_space := 'Level';
        END IF;
        IF INSTR(fulladdr, 'Unit') > 0 THEN
            v_space := 'Unit';
        END IF;
        RETURN v_space;
    END f_addr_type;

    PROCEDURE p_pincode (i_district IN varchar2, o_postcode OUT varchar2, o_errmsg OUT varchar2) IS
     v_msg VARCHAR2(250);
    BEGIN
        BEGIN
            SELECT POSTCODE
            INTO   o_postcode
            FROM   tab_pins
            WHERE  DISTRICT = i_district
            AND STATE       = 'West Bengal'
            AND CATEGORY    = 'Courier Service'
            AND ROWNUM      = 1;
        EXCEPTION
        WHEN NO_DATA_FOUND THEN
            o_errmsg:='No Data Found for District in PINCODES table';
        WHEN OTHERS THEN
            o_errmsg:='Others Exception raised for the district';
        END;
    END p_pincode;

    FUNCTION f_logerr (tabexrec tab_ex%rowtype, i_errmsg varchar2)
    RETURN VARCHAR2
    IS
    v_space VARCHAR2(30);
    BEGIN
        insert into tab_ex_err
        (ID, NAME, COMP_NAME, FLD1, DISTRICT, ERRMSG)
        values
        (tabexrec.id, tabexrec.NAME, tabexrec.COMP_NAME, tabexrec.FLD1, tabexrec.DISTRICT, i_errmsg);
        RETURN v_space;
    END f_logerr;


BEGIN -- Main Block
    for c1_rec in c1
    loop
        -- First check whether the District is valid (the one that we are looking for)
        IF c1_rec.DISTRICT IS NULL THEN
            v_errmsg := 'District is not provided';
            v_errmsg := f_logerr(c1_rec,v_errmsg);
            goto loop_next;
        ELSE
            p_pincode(c1_rec.district, v_postcode, v_errmsg);
            IF v_errmsg IS NOT NULL THEN
                v_errmsg := f_logerr(c1_rec,v_errmsg);
                goto loop_next;
            END IF;
        END IF;

        -- Check the format of the address
        v_addrtyp := f_addr_type (c1_rec.fld1);

        -- Case 1. "Cnr"
        --         ignore everything before "Cnr" and put the rest in the house/road name
        IF v_addrtyp = 'Cnr' THEN
            v_roadno := '';
            v_roadnm := substr(c1_rec.fld1, INSTR(c1_rec.fld1, 'Cnr')+ 4);
            goto proc_next;
        END IF;

        -- Case 2. "Shop" -- Case 4. "Lot" -- Case 5. "Level" -- Case 6. "Unit"
        IF v_addrtyp IN ('Shop','Lot','Level','Unit','House') THEN
            -- Find the last number in the string
            v_lastnum := substr(trim(translate(upper(c1_rec.fld1),
                         '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ', '0123456789')),-1);
            v_roadno  := substr(c1_rec.fld1,1,INSTR(c1_rec.fld1,v_lastnum,-1));
            v_roadnm := substr(c1_rec.fld1, INSTR(c1_rec.fld1,v_lastnum,-1)+1);
            goto proc_next;
        END IF;

        -- Case 3. "PO Box"
        --         Put everything in road name
        IF INSTR(c1_rec.fld1, 'PO Box') > 0 THEN
            v_roadno := '';
            v_roadnm := c1_rec.fld1;
            goto proc_next;
        END IF;

        -- If none of the above cases, then its the normal address.
        -- Find the last number in the string
        -- If none of the above cases, then its the normal address.
        v_roadno := substr(c1_rec.fld1, 1, instr(c1_rec.fld1, ' '));
        v_roadnm := substr(c1_rec.fld1, instr(c1_rec.fld1, ' '));

        v_lastnum := substr(trim(translate(upper(v_roadno),
                     '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ', '0123456789')),-1);

        IF v_lastnum is null THEN
             v_roadno := NULL;
             v_roadnm := c1_rec.fld1;
        END IF;

/*
        v_lastnum := substr(trim(translate(upper(c1_rec.fld1),
                     '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ', '0123456789')),-1);
        v_roadno  := substr(c1_rec.fld1,1,INSTR(c1_rec.fld1,v_lastnum,-1));
        v_roadnm := substr(c1_rec.fld1, INSTR(c1_rec.fld1,v_lastnum,-1)+1);
*/

        IF v_roadno IS NULL AND v_roadnm IS NULL THEN
            v_roadnm := c1_rec.fld1;
        END IF;

        <<proc_next>>
        v_roadno := trim(v_roadno);
        v_roadnm := trim(v_roadnm);
        -- last thing, check if the last character of road number is '/' or '?'. Strip if this is the case
        IF substr(v_roadno,-1) = '/' OR substr(v_roadno,-1) = '?' THEN
            v_roadno := substr(v_roadno,1,length(v_roadno)-1);
        END IF;

        IF instr(v_roadnm,' ') > 0 THEN
            -- If road name has more than one word then check if it has
            -- one of the valid values - Rd, Road, Avenue, Street, Pde or PO BOX
            IF instr(v_roadnm, 'Rd') > 0
            OR instr(v_roadnm, 'Road') > 0
            OR instr(v_roadnm, 'Avenue') > 0
            OR instr(v_roadnm, 'Ave') > 0
            OR instr(v_roadnm, 'Street') > 0
            OR instr(v_roadnm, 'Pde') > 0
            OR instr(v_roadnm, 'PO Box') > 0
            OR instr(v_roadnm, 'Drive') > 0
            OR instr(v_roadnm, 'Hwy') > 0
            THEN -- THIS IS A VALID RECORD. Insert into TAB_EX1

                -- If Road Number is null and company name does not exist (i.e., a personal address) then its invalid
                IF v_roadno IS NULL and c1_rec.comp_name IS NULL AND INSTR(v_roadnm, 'PO Box') <= 0 THEN
                    dbms_output.put_line(v_roadno || chr(9) || chr(9) || '|' || chr(9) || v_roadnm || '****Problem');
                    v_errmsg := 'Road Number not provided for personal address';
                    v_errmsg := f_logerr(c1_rec,v_errmsg);
                    goto loop_next;
                END IF;

                dbms_output.put_line(v_roadno || chr(9) || chr(9) || '|' || chr(9) || v_roadnm);

                INSERT INTO tab_ex1
                (ID, NAME, COMP_NAME, ROADNUM, ROADNAME, POSTCODE)
                VALUES
                (c1_rec.ID, c1_rec.NAME, c1_rec.COMP_NAME, v_roadno, v_roadnm, v_postcode);

            ELSE
                dbms_output.put_line(v_roadno || chr(9) || chr(9) || '|' || chr(9) || v_roadnm || '****Problem');
                v_errmsg := 'Invalid Road Name';
                v_errmsg := f_logerr(c1_rec,v_errmsg);
            END IF;
        ELSE
            dbms_output.put_line(v_roadno || chr(9) || chr(9) || '|' || chr(9) || v_roadnm || '****Problem');
            v_errmsg := 'Invalid address format';
            v_errmsg := f_logerr(c1_rec,v_errmsg);
        END IF;

        <<err_rec>>
        NULL;

        <<loop_next>>
        NULL;
    end loop;
end;
/

Hope this will now work for you.

You may notice, that the addresses like M'cac Street, upper & lower Street, Hill Road & downhill Road and Dance Pde & mahal Street are validated properly, and are put in the right fields.

Just in case if it does'nt, then please give me the details of records that I should use to simulate the problems that you are getting.

 

by: khushi2003Posted on 2004-04-12 at 05:04:33ID: 10804701

Did change middle of the code into commet

 

by: pratikroyPosted on 2004-04-12 at 06:06:50ID: 10805004

I did'nt get it ? Are there some problems ?

 

by: pratikroyPosted on 2004-04-12 at 07:00:24ID: 10805361

You mean, you just commented a couple of lines in the middle of the code ? If you go carefully through my code you will realise that I just did'nt comment, but I had changed some code as well. Please let me know if you have done all the changes in your code as well, and still having problems.

In the previous code, this is what was happening (which was a problem) :

        -- If none of the above cases, then its the normal address.
        -- Find the last number in the string
        v_lastnum := substr(trim(translate(upper(c1_rec.fld1),
                     '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ', '0123456789')),-1);
        v_roadno  := substr(c1_rec.fld1,1,INSTR(c1_rec.fld1,v_lastnum,-1));
        v_roadnm := substr(c1_rec.fld1, INSTR(c1_rec.fld1,v_lastnum,-1)+1);

        IF v_roadno IS NULL AND v_roadnm IS NULL THEN
            v_roadnm := c1_rec.fld1;
        END IF;

The above code was changed to :

       -- If none of the above cases, then its the normal address.
        -- Find the last number in the string
        -- If none of the above cases, then its the normal address.
        v_roadno := substr(c1_rec.fld1, 1, instr(c1_rec.fld1, ' '));
        v_roadnm := substr(c1_rec.fld1, instr(c1_rec.fld1, ' '));

        v_lastnum := substr(trim(translate(upper(v_roadno),
                     '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ', '0123456789')),-1);

        IF v_lastnum is null THEN
             v_roadno := NULL;
             v_roadnm := c1_rec.fld1;
        END IF;

/*
        v_lastnum := substr(trim(translate(upper(c1_rec.fld1),
                     '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ', '0123456789')),-1);
        v_roadno  := substr(c1_rec.fld1,1,INSTR(c1_rec.fld1,v_lastnum,-1));
        v_roadnm := substr(c1_rec.fld1, INSTR(c1_rec.fld1,v_lastnum,-1)+1);
*/

        IF v_roadno IS NULL AND v_roadnm IS NULL THEN
            v_roadnm := c1_rec.fld1;
        END IF;

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...