Update and request for insertion

I'm unable to write the query to update or insert or both the column of a table with the value on the other table once he finds an exact match

So here's the table data and sample to create.
create table code1 
(
    codeid number,
    codedesc varchar2(60)
);
 
Insert into code1 values ( 1,'R1 CONTRACTS');
 
Insert into code1 values ( 2,'R2 CONTRACTS');
 
Insert into code1 values ( 3,'R3 CONTRACTS');
 
Insert into code1 values ( 4,'R5 CONTRACTS');
 
Insert into code1 values ( 5,'R9 CONTRACTS');
 
Insert into code1 values ( 6,'R10 CONTRACTS');

Insert into code1 values ( 7,'R1');
 
Insert into code1 values ( 8,'R1 DEPT');
 
Insert into code1 values ( 9,'R1 SS');
 
create table table1 
(   
    tablekey number,
    prefix  varchar2(25),
    codedesc    varchar2(60)
);
 
Insert into table1(tablekey,prefix) values (1,'1001PAC');
 
Insert into table1(tablekey,prefix) values (2,'1001MXT');
 
Insert into table1(tablekey,prefix) values (3,'1002PAE');
 
Insert into table1(tablekey,prefix) values (4,'1003PCS');
 
Insert into table1(tablekey,prefix) values (5,'1004BDX');
 
Insert into table1(tablekey,prefix) values (6,'1005PAC');
 
Insert into table1(tablekey,prefix) values (7,'1006PAC');
 
Insert into table1(tablekey,prefix) values (8,'1007LDR');
 
Insert into table1(tablekey,prefix) values (9,'1009LCR');
 
Insert into table1(tablekey,prefix) values (10,'1010LBR');
 
Insert into table1(tablekey,prefix) values (11,'ABCDEF');
I'm writing a query that would update the value of column - codedesc (currently Null) of the table1 table: after it is a string of column - table code1 codedesc.

If it finds several match then it should update a line with the first matching string and insert the other row in double with the second matching string

The logic for the match is, - take - 2nd column of table-codedesc code value and get 2 characters. For example, when the string is - R1 CONTRACTS, the string will be 1. (Select substr ("R1 CONTRACTS, 2, 2) of the double). -Output will be 1.

Now,.
Look in table 1 for the 3rd position of the prefix that corresponds to the string returned by the query above. So, if the prefix is '1001PAC', it should look for 2 value of figures from the 3rd position. So, in this case it will be 01. Digitally 01 and 1 are equal, then the match is found for this line in the table1 table, so we will need to update the value of the column codedesc with the "contracts of R1.
tablekey,    prefix            codedesc    
---------- ------------------------------------------------------------
 
      1               1001PAC     R1 CONTRACTS    -- Needs to be update with this value. 
      2               1001PAC     R1     -- This row needs to be inserted 
      3               1001PAC     R1 DEPT     -- This row needs to be inserted 
      4               1001PAC     R1 SS     -- This row needs to be inserted 
      5               1002PAE     R2 CONTRACTS
...
      11             ABCDEF                                --Null ( No Need to update when no match found).
Some time I have a similar scenario (update only and not insertion) and Frank's Script took care. So I was wondering if I could / Merge Into to achieve statement change.
MERGE INTO     table1          dst
USING   (
          SELECT  LPAD ( RTRIM ( SUBSTR ( codedesc
                                 , 2
                               , 2
                               )
                          )
                     , 2
                     , '0'
                     )          AS match_key
          ,     codedesc
          FROM     code1
     )               src
ON     (src.match_key     = SUBSTR ( dst.prefix
                       , 3
                     , 2
                     )
     )
WHEN MATCHED THEN UPDATE
     SET     dst.codedesc     = src.codedesc
;
SQL> select * from v$version;
 
BANNER
----------------------------------------------------------------
Oracle Database 10g Release 10.2.0.4.0 - 64bit Production
PL/SQL Release 10.2.0.4.0 - Production
CORE    10.2.0.4.0      Production
TNS for Linux: Version 10.2.0.4.0 - Production
NLSRTL Version 10.2.0.4.0 - Production
Appreciate your help.

glad it worked for you
Sorry I did not respond as I left work just before responded you

Tags: Database

Similar Questions

  • How to get a list of all available updates and dependencies for the MS products

    We are currently working on a patch report (compliance policies).
    We need to scan all workstations for the patches installed (already DONE!).
    Now we need to get a XML / List / or something telling us all the patches to release MS, affected software and dependence.
    Any help?

    See if this sugesstion can help you to:

    http://social.answers.Microsoft.com/forums/en-us/vistawu/thread/6da1bc16-9919-4762-85D5-95dee3aa15fd

    Take a look at this link and see if it helps-

    http://social.answers.Microsoft.com/forums/en-us/vistawu/thread/a75f8d76-8689-4661-A546-90b555d80c9d>

    Windows XP security updates and patches for 2010

    http://www.softwarepatch.com/Windows/Windows-XP-security-updates-2010.html>

    03/23 / 1107:12: 05:00

  • Updates and extension for Dreamweaver CS5 do not install it? Someone at - he had problems with this before?

    Updates and extension for Dreamweaver CS5 do not install it? Someone at - he had problems with this before?

    Thank you Nancy for looking into this for me.  I have since adopted the web site of the company management

    Dream Weaver is a management tool of the great for the task I have on hand.

    Michael J. Lynch | Engineering support services

    Controls of Huntingtonhttp://www.huntingtoncontrols.com/>

    60 glacier Drive, Suite 2000 | Westwood | MY | 02090

    O: 781.535.6857x1025 | Direct line: 781.428.3310 | C: 617.334.4753

  • Kb 2656368 updates and kb2686827 for. Neframe work offered several times

    Title: kb2656368 and updates kb2686827 of origin "successfully" installed many times

    Kb2656368 and kb2686827 updates are constantly trying to update and have been installed 'successfully' repeatedly that they will not disappear, tried all ps previous publication on this problem

    Hello

    Method 1:

    Follow the steps from the link below and check if the problem persists.

    Solve common installation issues in Windows Update, Microsoft Update and Windows Server Update Services
    http://support.Microsoft.com/kb/906602

    Method 2:

    .NET Framework work uninstall and reinstall

    (a) download dotnetfx_cleanup_tool.zip from the following site:
    http://blogs.msdn.com/CFS-file.ashx/__key/CommunityServer-components-PostAttachments/00-08-90-44-93/dotnetfx_5F00_cleanup_5F00_tool.zip

    (b) when you are prompted, click Open, and then click retrieve now.

    (c) in which you extracted the files, double-click cleanup_tool.exe.

    (d) If you are prompted for an administrator password or a confirmation, provide the password, and then click continue.

    (e) in the you want to run the .NET Framework Setup Cleanup Utility? Message, click Yes.

    Note: this tool may be in English only, but it also works for other language versions of Windows.

    (f) click Yes to accept the license agreement.

    (g) in the window cleaning product, click on the drop-down list, select Remove all versions of .NET Framework and then click clean now.

    (h) Note: the cleaning tool will not let you delete the .NET Framework 2.0 in Windows Vista or later versions of Windows because the .NET Framework is installed as a component of the operating system.

    (i) after the .NET Framework is removed, restart the computer

    Download NET Framework 3.5 SP1 (this will also install the .NET Framework 2.0 SP2 and the .NET Framework 3.0 SP2) Microsoft .NET Framework 3.5 Service Pack 1

    (j) restart the computer.

    (k) to visit once again, Windows Update and then search for and install updates.

    Hope this information helps.

  • Windows Update causing screen to go back and request for boot disk

    laptop Windows 7 Home premium.  When I get windows updates, they eventually turn off my computer, and then restart.  Happens to the password acer page, and after he typed my password, instead of windows startup, which normally, it is used to do the same with the updates, now it turns off the computer and comes back with a back screen, type, then at the end of it, it says to insert a boot disk.  How can I prevent this from happening. Why not just open windows as it used to do?  (if I remove the battery from the laptop and it stops completely it will finally boot normally and go to windows, hense I am able to write this, but I don't want to do all of this to return to windows.)  Thanks for any help you can provide.  TJ

    Hello

    I suggest to refer to this link and follow the instructions in the link below and check, if this can help:

    http://Windows.Microsoft.com/en-us/Windows-Vista/troubleshoot-problems-with-installing-updates

    It will be useful.

  • Ideas and requests for updated Firmware Sony DSC-RX10

    I stay with her to see what fits with the first update of the firmware so I really video features of the large sensor RX10... I focus mainly on the video related updates in this post:

    Menus require a page of favorites to store frequently used functions as connection or wifi card format... Maybe the fn could be broadened to include these selections?

    In Aperture priority mode, it would be useful to define a minimum-Max shutter speed range. In this mode, only the camera often falls to 1/30 that blurs any sort of same subject in slow motion. So, it would be good to have a little more control in this setting without switching to the full manual. It goes same for shutter priority: I would like to specify a range of opening similar to the Auto ISO function

    Add video update options. Outside of a fixed object or interview situation, holding the focus is scary compared to video cameras small sensor and it is very similar to the focus on any DSLR I used for the video. In the auto focus mode S and C background often focus instead of the object in the foreground, if there is a lot of movement, and then the update has had a lot of delay, find the subject in the foreground even when centered in the frame... So, I had to stick to a manual focus for the videos so far. I like the tracking feature, but it is difficult to engage in video mode...

    Development let grow while shooting video. I can't understand how to enlarge a section of the image in manual focus mode when shooting video (you can when shooting still images). I thought this would be a feature of work in video mode, as well...

    Hello jefbak,.

    We appreciate the comments that you have provided about the characteristics of our DSC-RX10. This feedback helps us understand how we can improve our products. You can share these ideas to our page to join the Inspiration which is frequently visited by our experts and engineers.

  • For the last week or three Firefox updated two or three times for each update and sometimes for no apparent reason...

    For the last week or three Firefox updates two or three times for each update. Sometimes it refreshes without obvious reason. For example, I'll be in the middle of typing in the message forum block & it refreshes. Or by filling out an online form. Or simply viewing a page.

    You can check for problems caused by an extension that is not working properly.

    Start Firefox in Safe Mode to check if one of the extensions (Firefox/tools > Modules > Extensions) or if hardware acceleration is the cause of the problem (switch to the DEFAULT theme: Firefox/tools > Modules > appearance).

    • Do NOT click on the reset button on the startup window Mode without failure.
  • 10.11.2 El Capitan: Mail keeps quit and request for rebuild

    Hi all

    everything must be that the latest version of the OS X Mail 10.11.2, problem keeps quit and demand to rebuild. before leaving, she said "there is a problem with your mailbox". This occurs since the release of El Capitan. but there is nothing in the Yosemite (10.10).

    I have a problem very annoying in both my iMAC and MBP. one has the solution for that?

    and I don't know why Apple is not fix this problem after two critical update in 10.11?

    Apple, please answer this!  El Capitan really hurts my daily duties.

    Me too. Just installed ElCapitan and Mail is simply impossible. Preview pane is there, but no bodies in the messages. "Download 13 of 46 messages" or something like is always in the activity window. Reopen it changes every time I post. then reopen, I have duplicates of messages I deleted previously.

    It has something to do with icloud, but I don't know how to fix it.

    This discussion of October might be relevant... I'll try to work through it.

    Re: Mail: El Capitan: Emails not shown

  • Installation problem: other updates and security for Windows Vista (KB981852)

    In my history of update, this update shows as installation again and again "with success" since August, but he is still listed as an update to install.  This also applies to Windows Vista Service Pack 2 (kb948465), who has reportedly updated several times and still is listed as an update.

    Some info: I'm currently using Norton 360 - like Firewall and antivirus.  I also run Spyware Doc.  I was attacked last year, computer failed and I had to wipe my computer. (Assistance with this manufacturer.)  I'm not sure it solved the problem.  Since then, I have had problems with the computer running the browser to leave/run slowly, slowly, the problems to open programs.  This may be due to the loop of 'Windows update '?

    Thanks for any help.

    Hi Silk_Tea,

    First let's start with the question of the update of Windows. You can read the following article and try the steps and check whether you can solve the problem or not.

    Troubleshooting Windows Update or Microsoft Update when you are repeatedly offered an update

    http://support.Microsoft.com/kb/910339

    Hope this information is useful.

    Jeremy K
    Microsoft Answers Support Engineer
    Visit our Microsoft answers feedback Forum and let us know what you think.

    If this post can help solve your problem, please click the 'Mark as answer' or 'Useful' at the top of this message. Marking a post as answer, or relatively useful, you help others find the answer more quickly.

  • I'm trying to do a windows update and failed for HOURS... error code 0 x 643

    I'm doing a windows update for "Microsoft .NET Framework 3.5 Service Pack 1 and the .NET Framework 3.5 Family Update for versions of .NET 2.0 to 3.5 (KB951847) x 86 and I still receive error code 0 x 643.»  I have a software specific for a scanner that I need on my computer and that it stops.  I tried links .NET to install a similar position and it is just coming up with an error.  Help, please!

    A KB976982 was created to solve problems of corruption automatically MSI software update registration.

    The KB includes an automated Microsoft Fix it 50123 that corrects the problem.

    Look at the following KB: http://support.microsoft.com/kb/976982>

    Suggest you download and save the fix it.

    Then close all open programs and browsers before running MS fix 50123.msi.

    I also recommend taking off of USB keys (for example, flash drives) or any other external media, as this takes place.

    UTC/GMT is 07:08 Tuesday, July 31, 2012

  • Switcher with two facets for the recording of the update and one for folder creation

    Hello world

    I have a little problem.

    I use a mixer so that the function of the key, I click on the form is either loaded with the row of data update or a new form.

    I use two facet on which support the current line using an executewithparams and a different side with just a form of creation.


    But each form are blank



    It is with my links and executables that they must be in a specific order or what

    Help, please


    Concerning
    Lutchumaya

    Hello

    as signaller is not the right choice. If you use the ADF BC, then the same form is used for both and all you need to do is call createInsert as an operation at the opening of the Form by creating a new line and calling setCurrentRowWithKey when opening it to change

    Frank

  • request for insertion of product key, do not accept the product key code

    computer does not accept the code product key on the underside of the top of the Tower

    Windows Update has nothing to with the upgrade of Windows. Please repost your question in the support forum: http://social.answers.microsoft.com/Forums/en-US/w7install/threads ~ Robear Dyer (PA Bear) ~ MS MVP (that is to say, mail, security, Windows & Update Services) since 2002 ~ WARNING: MS MVPs represent or work for Microsoft

  • Use of broadband - Adobe Photoshop and Lightroom;  and request for bridge

    Hello

    I recently picked up a subscription to creative cloud for Photoshop and Lightroom.

    First question: I use bandwidth every time I have to edit an image in Photoshop?  Or is it just on bandwidth for the download/installation of the original application?

    Second question: there is a menu option in Photoshop to browse in Bridge.  East bridge of course included in the subscription of Photoshop?  Or bridge needs to be purchased separately.  If so, what is the cost in £ GBP.

    Thanks for your help.

    Fiona

    Hello Fiona,

    The bandwidth of your Internet connection will be used only for the initial download of the application. Rest depends on where you download any other stuff from the internet or not.

    Work on an application that requires not necessarily the Internet.

    The bridge is a part of the plan of photography.

    (What applications are included in the plan of creative photography Cloud?)

    Kind regards

    Sheena

  • Graphics update and memory for my A30 161

    My Satellite A30 161 uses 64MBRadeon and 512 MB of memory, the way I use it from the moment looks like im will need an upgrade on my chart and memory. Toshiba can this do?

    Hello

    I think that your graphics card shares its main memory with your RAM and you should be able to adjust the amount of memory allocated to your VGA card since then in the BIOS. The maximum value allowed is 128 MB and can be selected in UMA memory allocation in your BIOS settings. Note that it will have to reduce your available RAM as a result.

    HTH

  • approximate number of inserts, updates and deletions

    Hello
    in 10 g with STATISTICS_LEVEL = TYPICAL
    How to see the approximate number of inserts, updates, and deletes for a specific table?

    Thank you.

    This table has been abandoned - but segment still exists – and 'strange' name comes from the management of the recyclebin.

    Nicolas.

Maybe you are looking for

  • WHERE IS THE REAL FORUM? I CAN NOT FIND!

    Earlier, I installed the latest version of Firefox and, now, the order of bars, working downwards, is... 1 bar.2. tab bar.3. navigation bar.4. bookmarks toolbar. .. When I don't have the tab bar UNDER the bookmarks toolbar, where I still have it. How

  • Envy 15-j101tu: Sata 3 capable?

    Hi all, I just want to know if my laptop supports sata3, I want to install a sandisk extreme pro 480 GB ssd. I phoned two people from hp on the phone at specific times, we say yes to sata3 and the other said only sata1. I have fustraiting as the slow

  • How all the messages can be deleted in Windows Live Mail?

    In Windows Live Mail, we can dump the unwanted and deleted mail folders.  I want to empty the messages and can not find any help.Maggie472

  • Impossible to install Catalyst Control Center

    Hello. I have a HP Pavilion dv7-6059eo with Windows 7 64 bit. My GPU is a Radeon HD 6770 M. I had this problem for 2 months without being able to solve this problem, so help would be greatly appreciated. I got the AMD graphics drivers that I download

  • the best way to deal with the changed values maskMode?

    Hi peopleI just found out that the values listed for maskModes have changed between CC14 and CC15 who broke most of my scripts of masking.IE MaskMode.ADD in CC14 has the value 6413 but CC15 is 6813.What is the best way to deal with this? is there a s