Skip to content
Advertisement

Pl sql Proc or update statement for address correction from abbreviation to fullform

we have 2 tables employee and address_check in oracle database. we have a scenario where we need to check whether person address is not full form in address columns and we need to check another table for the abbreviation and full_forms to replace abbreviation to full_forms . we have to do this on daily basics for the new employees . So we need an update or insert statement to this copy address_l1 column value to address_l1_c with full_form .

we have to create a insert/update statement or pl sql procedure where it should check person address columns and find out if any abbreviations are present and if abbreviation are present . It should check that abbreviation present in address_check table and find its full form and get that full form and replace it in address_l1_c .

example and sample data as below:

enter image description here

Advertisement

Answer

This is your sample data and the way to extract the abbreviation. This option presumes that it is the last “word” (w+$) in the address. If it is located elsewhere, you’ll get wrong result.

Now, join extracted abbreviation with another table to get its full form. As it is unknown whether someone will enter “CT” or “Ct” or “ct”, I used the lower function to match those values. Outer join is used for abbreviations that don’t exist:

Finally, substitute abbreviations with their full forms (see comments within the code):

This is the first part of the story. Note that it works for sample data; if it changes or doesn’t match what you posted, this code will have to be adjusted (for example, remove superfluous spaces).

As of:

we have to create a insert/update statement

  • that would be a MERGE statement; easier to use than separate UPDATE + INSERT

For example:

we have to do this on daily basis

  • use a scheduler, i.e. the DBMS_SCHEDULER (or DBMS_JOB) built-in package. In order to use it, put your code into a stored procedure which will then be called by that utility.

In its simplest option, you’d put the above merge statement into a procedure as is:

Schedule it to run every day at noon:

That’s all, more or less.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement