What is the best method?

Hi,
Please find the queries below;
SQL> create table aat1(key1 number(5), verno number(5),text1 varchar2(100),text2
varchar2(100))
  2  /
Table created.
SQL> alter table aat1 add constraint aap1 primary key (key1,verno)
  2  /
Table altered.
SQL> alter table aat1 add constraint aau1 unique (verno,text1)
  2  /
Table altered.
SQL> select * from aat1;
      KEY1      VERNO       TEXT1   TEXT2
         1          0         ABC       DEF
         1          1         ABC       TTT
         2          0         ZZZ       MMM
SQL> create table aat2 as select * from aat1;
Table created.
SQL> alter table aat2 drop column verno;
Table altered.
SQL> alter table aat2 drop column key1;
Table altered.
SQL> update aat2 set text1 = 'XXX' where text1='ZZZ';
1 row updated.
SQL> delete aat2 where text2 = 'TTT';
1 row deleted.
SQL> update aat2 set text2 = 'IOU' where text2 = 'DEF';
1 row updated.
SQL> select * from aat2;
TEXT1            TEXT2
ABC                IOU
XXX                MMMNow what I want is;
1. Whatever record in both the tables having matching text1 value that should have a new record in aat1 with verno as 0 and the previous record/records' verno should be verno+1 keeping key1 value as same in aat1.
2. The text2 value of aat2 will be the updated value for text2 field of this new inserted record in aat1.
3. If any non matching text1 is there that should also be entered into aat1 where verno will be 0 and a new key1(could be taken from oracle sequence in practical scenario).
This is what I have done. I would need suggestion if this can be done in a more performance effective way.Basically any better way of doing this thing.
SQL> update aat1 a set a.verno = a.verno + 1 where a.text1 = (select distinct b.text1 from aat2 b where b.text1 = a.text1 )
  2  /
2 rows updated.
SQL> select * from aat1;
      KEY1      VERNO        TEXT1   TEXT2
         1          1        ABC       DEF
         1          2        ABC       TTT
         2          0        ZZZ       MMM
SQL> insert into aat1 select a.key1,0,b.text1,b.text2 from aat1 a,aat2 b where a.text1 = b.text1 and a.verno = 1 ;
1 row created.
SQL> select * from aat1;
      KEY1      VERNO TEXT1    TEXT2
         1          1        ABC       DEF
         1          2        ABC       TTT
         2          0        ZZZ       MMM
         1          0        ABC       IOU
SQL> MERGE INTO aat1 a
  2    USING aat2 b
  3      ON (a.text1 = b.text1)
  4    WHEN NOT MATCHED THEN
  5      INSERT (key1,verno,text1,text2)
  6      VALUES (3,0,b.text1,b.text2)
  7  /
1 row merged.
SQL> select * from aat1 order by key1,verno;
      KEY1      VERNO TEXT1   TEXT2
         1          0 ABC          IOU
         1          1 ABC          DEF
         1          2 ABC          TTT
         2          0 ZZZ          MMM
         3          0 XXX          MMM
SQL>Please help me.
regards,
Dipankar.

None other than what is already done.!
Just add this hint and check the performance/explain plan/tkprof.
MERGE /*+ parallel(table_name,10) append */
Nothing other than this.!
Ss

Similar Messages

  • I'm moving to an imac from a PC. I want to move my itunes library from the PC to my new imac. What is the best method and where can I find instructions?

    I'm moving to an imac from a PC. I want to move my itunes library from the PC to my new imac. What is the best method and where can I find instructions?

    Move iTunes from PC to MAC, http://www.macworld.com/article/146958/2010/03/move_itunes_windows_mac.html

  • What is the best method of backing up my digital files (catalog) in the Photoshop Elements Organizer

    What is the best method or service for backing up my digital files (catalog) in the Organizer from Photoshop Elements 12. Since there no longer is  the automatic  Elements sync available I do not know what to choose. I have tried to back this up using my external drive, but I cannot find the digital images per se. I see the entire program but not the catalog of pictures. Also, I have a windows operating system and Adobe  Revel offers no edit capabilities with this OS.

    I'm in a similar situation including movies I've purchased from iTunes...
    Here's my setup:
    I have all my iTunes data (music, movies, etc.) as well as about 10 GB of photos stored on a nework storage device that uses RAID-5 with SATA disks. This is basically a little toaster-sized NAS machine with four hard drives in it (www.infrant.com). If one of these drives dies, I get alerted and can insert a new one without missing a beat since the data is stored redundantly across all drives. I can also just yank out any one of the four drives while the thing is running and my data is still safe (I tried this after I bought it as a test).
    That's how I prevent problems with a single disk... Redundancy
    Now onto "backups"...
    Nightly, my little RAID toaster automatically backs itself up to an attached 250GB USB drive. However, these backups are only of my critical data... documents, photos and home movies... I don't bother backing up my "Hollywood" movies since I can live without them in a disaster.
    ... I actually don't permanently store anything I care about on a laptop or a desktop. It all goes on the NAS box (Network Sttached Storage) and then my other computers use it as a network drive. It's attached via Gigbait to my main computer and via wireless to most everything else.
    My achilles heel is that I don't store anything outside of my house yet. If I was smart, I'd alternate two USB drives attached to my NAS box and always keep one of them somewhere else (Safe Deposit Box?).
    ...and that's just one way to do it.
    -Brian

  • What is the best method to store session variables

    As the title says, what is the best method to store session
    variables in a Production environment?
    I have been reading the posts on sessions and have been
    getting different ideas on where to store session variables, in a
    db, registery, cookies etc etc
    Can someone clarify possible best practice on this matter?
    Matrix

    From my experience, db is the best to store client variable
    data. Registry will cause you trouble in future (when data gets
    overloaded) and cookies will not serve the purpose for a few % of
    your users.

  • What is the best method for moving iTune Libraries from Old to New Computer

    Hello,
    Thanks in advance for any assistance you may offer.
    My Sony Vaio Desktop recently died and untimely death, so I just purchased an HP Notebook. I was trying to wait out the release of the possible update of the Macbook line. However the old computer didn't agree. This HP will tie me over till a new release.
    I've been doing weekly backups for over 3 years with a backup drive from Western Digital. At this point I just want to transfer my music in iTunes and applications from the App store that are loaded on to my iPod Touch into the new computer and then reauthorize and sync.
    My question is what's the best method. Oh another problem I'm having includes the latest iPhone & iPod Touch software problem of 3rd party apps not working along with the vanishing of my music on the Touch.
    Any guidance would be much appreciated.

    Open up a fresh copy of iTunes. Point iTunes in the direction of your Western Digital Harddrive. Import Folders.
    1. New Copy
    2. Edit -> Preferences -> Advanced -> General -> Change -> <the address of the iTunes library on WD>
    3. File -> Add Folder to Library -> <Select iTunes folder on WD>
    Always keep a backup of your iTunes Library file and the iTunes XML Document. If you have those, then it might be just as simple as copying those to your iTunes file folder. If you are not sure where they are, then do a search for iTunes.xml.

  • HT1382 What is the best method to backup an Iphone 3G and then install newer ios without losing any info on the phone?

    What is the best method to backup an Iphone 3G and then install newer ios without losing any data in the phone?

    How to BackUp  >  http://support.apple.com/kb/ht1766
    Key2Paradice wrote:
    What is the best method to backup an Iphone 3G ...
    Note:
    The iPhone 3G can only update as far as iOS 4.2.1
    Connect to iTunes on the computer you usually Sync with and “ Check for Updates “...
    If an Update Appears Install it... if not... you are up to date for your particular Device...
    See the Using iTunes Section Here...
    How to update your iPhone, iPad, or iPod touch

  • What is the best method to provide an option to select "All" for LOV ?

    Some posts sugest that you should "UNION" the origional select with something like (select "all" from dual ) this works as a seperate query but if you want to use and existintg query this is not very clean as viewlinks are not taken into account. We could also pass back an array list and include the all option in the list but that gets away from having the client use the iterator in the pagedef for other requirments of the page.
    Whats the best way to approach this with the new features in 11g?

    How to BackUp  >  http://support.apple.com/kb/ht1766
    Key2Paradice wrote:
    What is the best method to backup an Iphone 3G ...
    Note:
    The iPhone 3G can only update as far as iOS 4.2.1
    Connect to iTunes on the computer you usually Sync with and “ Check for Updates “...
    If an Update Appears Install it... if not... you are up to date for your particular Device...
    See the Using iTunes Section Here...
    How to update your iPhone, iPad, or iPod touch

  • What is the best method to revert back to 'golden' image of database

    Hello,
    I want to have a 'golden' image of my test database. What is the best method to keep reverting back to this 'golden' image after testers are done with testing. What I mean is I want to set up a test database for testers. Testers can insert,update, delete on objects as they like. But after the testers have completed their testing, I want to revert the database back to the 'golden' image. This 'golden' image is the state of the database before testers perform their tests. I need to revert back to the 'golden' image many times over as we have to perform many different tests.
    I thought about export and import (9i database) but takes 6 hours, too long. I tried using rman and was successful the first time, (set until time; restore database; recover database; open resetlogs;). The seconde time using rman, I got error saying the set until time was before the resetlogs time. I think I would have to restore the control file before the resetlog time frame before I can recover to the set until time, again.
    What is a straight forward method to have a 'golden' image so I can keep on restoring back to it? This database is a test 9i database and it is in archive log mode but it doesn't need to be. I just need a best practice method, whether it is rman, exp/imp, manual backup/restore? Something I can use time and time over again. Thank you.

    If it is a Test envionment, can you just take a COLD Backup (database files
    plus control files) ? How big is the database ? What platform is it on ?
    eg in a COLD Backup
    a. If using a script, run multiple "cp" (or cpio/tar) commands in parallel to
    copy different database files
    b. If using RMAN (in NOMOUNT), use multiple Chnanels.
    Note : Remember to include ControlFile Backups and Restores as well.

  • What is the Best Method to move the Applcations to a New Server Setup

    Hi All...
    Happy Christmas...
    Advanced Happy New YEAR 2009...
    We are using oracle Apex 3.1 on Database base oracle 10g Rel2 across Server 2000 platform,
    Made a New Installationof Oracle Apex 3.1 on HP-Unix PA-RISC and database is oracle 10g Rel2(New Server),
    Sucessfully...
    my Question is
    what is the Best Method to move the Applcations to a New Server ?
    1) Using Export/Import option .can I move the Applications/ Reports to New Server?
    2) Is it possible By Taking Application level Export and Import to the new Server?
    3)Do I need to create the Workspace as similar to old Server then Move the ApplicationS?
    or taking the Application EXPORT/IMPORT also imports the Workspace?
    (OR)
    Do I need to import the Database tables taking table level Dumps as well?
    THANKS ALOT in Advance
    MKZ
    Edited by: Z on Dec 31, 2008 12:10 PM
    Edited by: Z on Dec 31, 2008 12:57 PM

    Hello:
    You pretty much have it right. Here's what I do to move applications between APEX installations.
    1) Export/Import Workspaces
    2) Export/Import Applications for each workspace. (I retain the source application id in the target)
    3) Export/Import Workspace Images/Files etc
    4) Use Oracle exp/imp , Oracle DataPump or plain old sqlplus scripts to move database objects from source to target.
    Varad

  • What is the best Method to transport KMC from DEV to QA & PROD

    We are trying to figure out what is the best method to transport KMC from DEV to QA & PROD. Your help and feedback is greatly appreciated.
    David

    hi,
    Refer this thread.
    How to transport KM content and configration?
    Regards,
    Ganesh N

  • What is the best method for saving files off of the hard drive?

    I would like to save music files and photos somewhere other than my hard drive (eg. CDs, DVDs, zip disks). What is the best method for doing this?

    It rather depends on how paranoid you are
    External hard drives protect you from hard disk trouble on your machine.
    Optical media (CD's, DVD's) protect you from trouble with magnetic disks - such as external hard drives and the HD in your machine. Optical disks are thought to be more reliable that magnetic disks for long term storage.
    Off site back-ups will protect you from fire or theft at your home or office.
    How paranoid are you? Personally everything is backed up across three diferent external HD's. And maybe twice a year I burn a copy of my photos onto DVDs and they go to a relative's house across town.
    Regards
    TD

  • What is the best method to use for revealing the text on a jpg (as though the text is drawing itself?) Thanks.

    What is the best method to use for revealing the text on a jpg (as though the text is drawing itself?) Thanks.

    tacbob wrote:
    Are there any tutorials? I cannot find anything close.
    http://itunes.apple.com/de/podcast/write-on-effects-in-motion/id287113664?i=4883 4057
    The MacBreak Podcasts are an excellent source of info!
    Have a look on the others ..

  • What is the best method of using an iPad as an extra screen for a macbook pro?

    I just received a macbook pro what is the best method for using an ipad as an extra screen for an ipad? Hopeflly, one that is no cost to me.

    Sorry, but are you incapable of looking things up for yourself? Everything that you have asked is easily searchable on the internet.
    I used it over wi-fi.
    http://avatron.com/apps/air-display

  • Purchasing new iMac (27 i5), what is best method to transfer programs/files/documents from 24" iMAC?  What is the best method to remove personal data from OS?

    Purchasing a new iMac (27 i5), what is the best method to transfer programs/files,documents from a 24" iMac?
    What is the best method to remove personal data from the 24" iMac?

    Use setup assistant which is offered when you setup your new Mac.  It will transfer information from a Time Machine backup, Clone or another Mac.
    It's best to do this during setup to avoid issues with duplicate IDs.
    Regards

  • What is the best method for transferring iTunes library from PC to iMac?

    I have a new iMac.  I have authorized it with my iTunes account.  My current iTunes library is on a Windows Vista PC, not on the same network.  What is the best method for me to use to transfer the iTunes library from the PC to the iMac?
    iMac, Mac OS X (10.7.4)

    Did I just answer this in another post for you?
    iTunes: How to move [or copy] your music to a new computer [or another drive] - http://support.apple.com/kb/HT4527
    Quick answer if you let iTunes manage your music:  Copy the entire iTunes folder (and in doing so all its subfolders and files) intact to the other drive.  Start iTunes with the option (shift on Windows) key held down and guide it to the new location of the library.
    Macworld - How to transfer iTunes libraries between PC and Mac - http://www.macworld.com/article/46248/2005/08/shiftitunes.html
    Move an iTunes library from a Windows PC to a Mac - http://www.macworld.com/article/1146958/move_itunes_windows_mac.html
    iTunes for Windows: Moving your iTunes Media folder - http://support.apple.com/kb/HT1364

  • What is the best method for finding duplicates in iPhoto?

    What is the best method for finding duplicates in iPhoto?  I would like them identified and then prompted to delete or not.

    iPhoto Library Manager - http://www.fatcatsoftware.com/iplm/ - , duplicate annahalitor, Decloner
    LN

Maybe you are looking for

  • How can I chose and manage the addresses from which my emails are sent?

    My ISP lets me have an infinite choice of addresses by putting whatever I like in front of the @ in my email address. I want to use this to create and manage separate accounts for myself, my wife, and two voluntary associations for whom I act as secr

  • Problem with Logon on Handheld

    Hi, as you know i need to logon if i want to start a webdynpro application (directly via browser and url). When I do so on my desktop-computer there are no problems. But when I try to start the same applicaton on my handheld I cant logon. Nothing hap

  • How to deploy a pure jave development component to server?

    i have created a pure java development component. but i cannot find a way to deploy it to server is there any way?

  • XI R3.1 publication success / fail notifications not sent

    I have a set of 3 publications created and working fine in R3.1 (EDGE), each of which distributes a report to a UNC fileshare location. Upon success or failure, each is configured to send an email notification to an admin. The publications work and d

  • Error opening Address Book

    When trying to open Address Book I get this message: "You cannot use this version of the application Addressbook with this version of Mac OS X". Only thing is, the address book CAME with this Leopard version, didn't it?  I've been using Entourage mai