UPDATE without repeating subquery

Hello

Is it possible to do this UPDATE without two copies of the same auxiliary request?

I'm trying to update table_x.name when there is another line in the same table that has exactly the same name, but with apostrophes.
For example, the table contains:
        ID NAME
---------- --------------------------------------------------
         1 Fisherman's Landing
        11 Fishermans Landing
I want to update the row with id = 11 to have the name of id = 1, because they are identical (case-sensitive) except for the apostrophe.

The script below does what I want, but I wonder if it is a good way to do it without repeating the scalar subquery in the EXISTS subquery.
MERGER will trigger ORA-38104 if you attempt to update a column that is used in the condition WE.

Test script:
CREATE TABLE     table_x
(      id     NUMBER
,      name     VARCHAR2 (50)
);

-- Rows below should be UPDATEd if and only if id > 10.

-- One long name and one short name
INSERT INTO table_x (id, name) VALUES (1,     'Fisherman''s Landing');
INSERT INTO table_x (id, name) VALUES (11,     'Fishermans Landing');

-- One long, two short
INSERT INTO table_x (id, name) VALUES (2,     'M''Cormack');
INSERT INTO table_x (id, name) VALUES (21,     'MCormack');
INSERT INTO table_x (id, name) VALUES (22,     'MCormack');

-- Two long; one short
INSERT INTO table_x (id, name) VALUES (3,     'Tan''sur');
INSERT INTO table_x (id, name) VALUES (4,     'Tan''sur');
INSERT INTO table_x (id, name) VALUES (31,     'Tansur');

INSERT INTO table_x (id, name) VALUES (5,     'Didn''t find a match');
INSERT INTO table_x (id, name) VALUES (6,     'Did not find a match');

-- Mulitple apostrophes
INSERT INTO table_x (id, name) VALUES (7,     'L''Hopital''s Rule');
INSERT INTO table_x (id, name) VALUES (71,     'LHopitals Rule');

-- When the long version is not unique, take the MIN (81 <= 8)
INSERT INTO table_x (id, name) VALUES (8,      'Can''t and Wont');
INSERT INTO table_x (id, name) VALUES (9,      'Cant and Won''t');
INSERT INTO table_x (id, name) VALUES (81,      'Cant and Wont');


COMMIT;

PROMPT     ==========  Before UPDATE  ==========

SELECT     *
FROM     table_x
ORDER BY     name;


PROMPT     ==========  UPDATE  ==========

UPDATE     table_x     m
SET     name = (
            SELECT     MIN (name)
            FROM     table_x
            WHERE     name     LIKE '%''%'
            AND     m.name     = REPLACE (name, '''')
            )
WHERE   EXISTS (
            SELECT     null
            FROM     table_x
            WHERE     name     LIKE '%''%'
            AND     m.name     = REPLACE (name, '''')
            );

SELECT     *
FROM     table_x
ORDER BY     name;
The script above updates 6 ranks where id > 10, leaving this to thable_x:
        ID NAME
---------- --------------------------------------------------
        81 Can't and Wont
         8 Can't and Wont
         9 Cant and Won't
         6 Did not find a match
         5 Didn't find a match
         1 Fisherman's Landing
        11 Fisherman's Landing
         7 L'Hopital's Rule
        71 L'Hopital's Rule
        22 M'Cormack
        21 M'Cormack
         2 M'Cormack
        31 Tan'sur
         3 Tan'sur

I don't know that I would implement the report to the original, but the question was 'you can' so I'll skip the rest for now ;)

ME_XE?MERGE INTO table_x x
  2  USING
  3  (
  4     SELECT
  5        id,
  6        FIRST_VALUE(name) OVER (PARTITION BY REPLACE(name, '''', NULL) ORDER BY ID ASC) AS new_name
  7     FROM  table_x
  8  ) y
  9  ON (x.id = y.id)
 10  WHEN MATCHED THEN UPDATE
 11     SET x.name = y.new_name
 12     WHERE LENGTH(x.name) != LENGTH(y.new_name);

6 rows merged.

Elapsed: 00:00:00.01
ME_XE?

Published by: Tubby on May 14, 2009 13:27

sad, the forum always eat my <> is not equal to...

Tags: Database

Similar Questions

  • Windows Update fails repeatedly to install updates KB3079904 and six other people, keep trying for 3 weeks now

    Drop support for Windows Vista is apparently present but perhaps without notice.

    Three weeks since July 14, 2015 Windows Update has repeatedly tried and failed to install seven updates. Three other updates cannot be installed while in time (KB3072633, KB3057154, KB3065979) but was finally installing manually through Microsoft Download Center.  Further attempts by MDC didn't settle because "the update does not apply to your system" (KB3070102, KB3067903).  KB3072630 update did not show an available option of Windows Vista.  The remaining updates would download a version of Vista but just have not installed (KB3070102, KB3079904, KB309392, KB3067505 and KB3065822, which is a Cumulative of IE9 for Windows Vista update).

    With no fix that works my PC will apparently try to download these and other updates in perpetuity.  Some files, such as KB915597, is constantly to be installed and reinstalled successfully during this time.

    I tried to upgrade Vista on TOSHIBA to my mother, it runs cpu to slow to 46%, I'm sure I need of more memory, my concern is that I just tried to upgrade on my HP17 for the new completely WIN10 have not upgraded, but froze on a continuous flashing, cannot access via ctrl alt esc file insight and nothing moves percentages are 0 nothing downloaded? or downloaded?

  • Oracle to update without waiting

    Hi all..

    Can you a pls tell me in which case we must use to update without waiting in the sliders.
    my understanding is to activate locks on top of records selected by the cursor using for update.
    but haven't knowlodge on the NOWAIT clause. Can pls tell me exactly in this case you must use the nowait clause.

    Thanks in advance,
    Sanjeev.

    Hi Hassan,.

    There are 3 choices

    1 NOWAIT, you set this, if you do not want to wait for the locks.
    Enough if 1 rank is not available to you, you will get an ORA-54.

    2. you can wait until ' n seconds. After "n" seconds, you do not have the lines
    you will get an ORA-30006.

    3 new feature - officially - in Oracle 11 g! SKIP LOCKED!
    Sometimes it's good for us that one TRIES to lock all lines, but not problem, if there is some lines
    which are available to us.
    In this case, we are changing all that remaining availabe lines will be ignored.
    Later - maybe - we try to repeat our process for the remaining lines.
    Of course, we mark our lines changed in some way (e.g. with flag)
    Note that this feature is available in Oracle 10 g (unofficially)!

    Best regards
    Laszlo
    (Trainer SQL and PL/SQL in Hungary)

  • As it can be seen in the OS 3 Web page will be available today, 13 September. However my Watch App does not seem to see the update according to the availability. When I go to software update, he repeats that my watch is up-to-date with OS 2.2.2. OS3 will

    As it can be seen in the OS 3 Web page will be available today, 13 September. However my Watch App does not seem to see the update according to the availability. When I go to software update, he repeats that my watch is up-to-date with OS 2.2.2. OS3 will be available today?

    Hello

    Yes - Apple advises that watch OS 3 is scheduled to be released sometime today.

  • How can I use Office Update without the Office CD?

    How can I use Office Update without the Office CD? On the microsoft Web site, I clicked the options which mean that I would not need the CD (which was not provided with the laptop), but poartway through the service pack update, I get a request for the Office 2000 Professional CD.

    Any suggestions?

    Hello

    Did you mean an office or a note?
    As far as I know the a Note is part of the recovery Image and the CD is not supplied with the unit. In addition, Toshiba units are not delivered with the Office 2000 software.

    However, have you checked to aid either in Word update function?

    You will find an option called verification of updates
    http://Office.Microsoft.com/en-us/officeupdate/default.aspx

    Good bye

  • can quicken 2007 run on El Capitan (i.e., os 10.11)? I have one currently using Yosemite and you want to update without losing the use of Quicken 2007. I don't like the new version of Quicken.

    Can quicken 2007 run on El Capitan (i.e., os 10.11)? I have one currently using Yosemite and you want to update without losing the use of Quicken 2007. I don't like the new version of Quicken.

    Join the club of those of us who don't like Quicken 2015 or 2016 Quicken; even if I bought it for a 40% discount offered by Intuit!  I was just disappointed by Q2016 compared to Quicken 2007!

    If you have upgraded to the 16.2.3, version it will work well in El Capitan!

  • Software Safari 9.0.3 update keeps repeating

    Software Safari 9.0.3 update keeps repeating

    This procedure will remove some temporary and cache files. The files are generated automatically and do not contain any of your data. Sometimes they can become corrupted and cause problems like yours.

    Please, back up all data and read this message before doing anything.

    Triple-click anywhere in the line below on this page to select this option:

    /var/folders/zz/zyxvpxvq6csfxvn_n00000s0000068

    Right-click or Ctrl-click on the highlighted line and select

    Services ▹ reveal in Finder (or just to reveal)

    the contextual menu.* file should open with a selected subfolder. The subfolder has a long name beginning with "zyx" and ending with "68". Place this subfolder in the trash. Do not move other subfolders with similar names. You may be prompted for administrator login password. Restart the computer and empty the trash.

    * If you do not see the item context menu copy the selected text in the Clipboard by pressing Control-C key combination. In the Finder, select

    Go ▹ go to the folder...

    from the menu bar and paste it into the box that opens by pressing command + V. You won't see what you pasted a newline being included. Press return.

  • Is there a way of decompression Tempro updates without having to buy Winzip?

    Is there a way of decompression Tempro updates without having to buy Winzip?
    And why the files are downloaded in this way? Why no exec simple files from Microsoft?
    Thanks for any help
    Stem

    Hello

    You n don't need to buy anything.
    WinZip is free. You can also use the WinRAR.
    You notice just a pop who recommend buying a full version, but it is not necessary to decompress single packages.

    As I have said; install WinRAR. I use this tool too. in my opinion it of better than Winzip.

    Welcome them

  • How to clean WInSXS folder was updated without having to install on Server 2008 diskcleanup

    My question is possible to manually remove updates without installing diskcleanup on my 2008 R2 Windows server or any other server.  The reason is that they said that install diskcleanup causes the disk compression so I need to find alternative solutions to clean up the disk space.  I recently downloaded TreeSize Pro (freeware) on my Windows 7 computer to test.  The program works well by showing you which files are used, but it seems the Winsxs folder is a good place to start, or maybe it isn't.  I just basically want to delete files on another server of companies without users calling to complain that they lack shortcuts etcs and need a place to start.

    Also is there a way to run speaker program via web or you must have something running on the real server?

    Thank you

    Hi James,

    Welcome to the Microsoft community.

    It is a forum of consumer of Windows. For assistance on issues with Windows Server 2008, you can always post queries on Windows Server forum:

    https://social.technet.Microsoft.com/forums/WindowsServer/en-us/home?category=WindowsServer

    Feel free to send more requests to Windows.

  • Can't update without Windows of self-destruction!

    After the update a few weeks ago... Bad software removal tool... My father PC had white exclamation points all on that screen P.O.S.T.... then the screen would go and NOTHING...! Restart, and then go to the Startup Repair tool... Windows Startup Repair tool cannot fix... you want to restore?... long story short... so the only thing that worked was a REINSTALL FACTORY...

    NOW... I can't update anything... Update Windows and not even a no driver for the graphics card! If I... I will return to white exclamation on fullscreen P.O.S.T.... then NOTHING... points! I've restored the system several times and tried to update, only to have this accident to happen once I update... There's something like 83 updates and it's too much to try to step up to the problem... Heck I think is not yet get it until the first service pack!

    On top of OFF... Microsoft tool for support does not even recognize its product ID... even when I enter it manually... all YES, I'm in the correct information!

    As you can imagine, it's really a bad situation and bad support (no I don't want to pay Microsoft an another $50) it made it worse. After buying Windows since Win95, Xbox, 4 Xbox 360 (thanks to free material you knew was broken) and a Zune... I really think to change and do not return!

    Someone at - he lived it and managed to isolate the problem... I have the exact system he has, even screen, same graphics card, etc... and I am able to update without ANY problem!

    Thanks in advance! And sorry if I'm angry... I worked on it for about the last three weeks!

    Dan

    If you have a brand of computer, HP, Dell, etc, you are not eligible free Microsoft Support.

    All support is the manufacturer of your computer.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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

    How to reset the Windows Update components?

    http://www.Microsoft.com/downloads/en/default.aspx

    Also, try to put the KB numbers in the search at the above link > then download them manually.

    If the above does not solve it:

    Windows Update Forum:

    It comes with Vista, upgrade install and activate Forum.

    You will get the best help for any problem of Update/Service Pack in the Windows Update Forum; the link below:

    http://social.answers.Microsoft.com/forums/en-us/vistawu/threads

    When you repost here, kindly include the Error Codes, and exactly what is happening when you try to update.

    In this way, you will receive the best help.

    See you soon

    Mick Murphy - Microsoft partner

  • Windows Update keeps repeating.

    I have Windows XP SP3 OS. I have the auto update feature set. Windows is my default firewall. Successfully and recently I downloaded and installed the following updates:

    A security update for Microsoft .NET Framework 3.0 SP2 on Windows server 2003 and Windows XP x 86 (KB2832411).

    Microsoft .NET Framework 3.5 SP1 and the .NET Framework 3.5 family Update for versions of .NET 2.0 to 3.5 (KB951847) x 86.

    The problem is one or both come back as new updates. I have installed at least three times, and yet I still get the repetitions.

    Can someone tell me how to prevent the repetition of these updates?

    Hi 10crackers, thanks for the help. Your suggestion has helped to solve the problem I had. First I ran the repair of Microsoft .NET Framework tool, but who has not remedied the problem. I was about to follow your next steps suggested to uninstall the .NET Framework 3.5 and others, but before doing that I decided to see what updates have been installed in Add/Remove programs. Security update for Microsoft .NET Framework 3.0 SP2 Windows Server 2003 and Windows XP x 86 (KB2832411) has been installed in fact but kept repeating the offer to install a new update. To my surprise, Microsoft .NET Framework 3.5 SP1 and the .NET Framework 3.0 versions of .NET 2.0 to 3.5 Family Update (KB951847) x 86 was not installed that each Setup attempt has been highlighted as a successful download and installation. Once I saw KB951847 update has not been installed I just went to Windows Update and select custom scan as you suggest. And KB951847 was the only necessary update. Once I downloaded and installed this update offer repeated editing has ceased. This update has been done a few hours ago now, and so far no repeated updates offers. Even if I did have to uninstall all .NET frameworks you suggested, I have still Bravo will give you to send me to the Add/Remove Programs then Windows updates. These are the right things.

    Thanks for your help. I guess why you make a lot of money.

  • Update Windows repeatedly asks me to download updates

    Update Windows repeatedly asks me to download the updates on Office 2007 2 and 1 Excel 2003 update, although the update history shows these updates succeeded (properly installed).

    KB2760588, KB2810048, KB2760411

    I've finally just marked them as hidden so updates it wouldn't keep bugging me, until I can find an answer or a revised update is published (already happened).

    See this thread: http://answers.microsoft.com/en-us/windows/forum/windows_xp-windows_update/on-xp-pro-kb2760411-kb2760588-and-kb2810048-will/354cf9ff-dd70-4cd6-875d-734f816ee577

    It has the most members complain.

    Joe

  • KB 2633880 update fails repeatedly

    update fails repeatedly

    Microsoft Fix - it 50202 # is not directly on the site to update. But you can viewed in the following

    See this MS support article http://support.microsoft.com/kb/910339

    Less to troubleshoot / method 1

    Please see full article.

    Let us know if that helps.

  • To get the updates without sp3

    When I do a system restore, I used to be able to get updates without installed SP3.  Is there a way to get the updates without SP3? Is it possible to get the smaller version from 1 computer to SP3 updates? I can only find the network version. I tried to turn on updates, but he didn't send me a.

    Hi Larry132,

    Ignore the warning of network installation and download and install it. It works very well.

  • Why did Windows using stealth tactics and install updates without permission or notice?

    Why did Windows using stealth tactics and install updates without permission or notice?
    It becomes a regular event, it also seems to restart in the middle of the night to set up these updates. I don't know what the intention but
    [Vista 32 bit] I returned this intrusion in the files to my PC and I always despise microsoft to decide to act like a pirate.  I'll give microsoft some time to answer this, but I expect to be as horrible as they are usually with the customer service.   So in a few weeks, I'll start to smear the name of microsoft as much as possible and sway anyone my possible to buy non-Microsoft products.

    Read here:

    Microsoft Update product team blog: Windows Update and automatic reboots

    http://blogs.technet.com/Mu/archive/2008/10/02/Windows-Update-and-automatic-reboots.aspx>

    Change how Windows installs or notifies you of updates

    http://Windows.Microsoft.com/en-us/Windows7/change-how-Windows-installs-or-notifies-you-about-updates>

    If you select the download updates but let me choose... option, no update will install without your approval. Suppose an update will require a reboot and does not approve the installation of an update until & unless you are ready to restart.

    You can change the AU for the "updates but let me choose whether to download and install them" setting. Once you have done this, you will need to approve the updates are downloaded, the updates are installed and where they are installed.

    I prefer "check for updates but let me choose whether to download and install them" setting.

    UTC/GMT is 13:33 Tuesday, January 31, 2012

Maybe you are looking for