Oracle Update TOP N Issue, ask the expert to answer

Source: Internet
Author: User

Hello everyone

Last week wrote an anonymous method, a lot of readers, very happy, I believe we have from the people's reply, the. NET has a more profound understanding.

OK, now the topic, all kinds of databases have a corresponding update of the table top N scheme. Now I'm one by one, for example.

First look at the table structure as follows:

database and table creation commands Initializing Database statements

1 CREATE TABLE Student (2varchar)    not NULL , 3 varchar (+)   NULL , 4 int NULL)

1 Insert  intoStudentValues('001','WFG', -);2 Insert  intoStudentValues('002','LXX', +);3 Insert  intoStudentValues('003','wly',3);4 Insert  intoStudentValues('004','JCJ', -);5 Insert  intoStudentValues('005','WSS', -);6 Insert  intoStudentValues('006','Xsm', -);7 Insert  intoStudentValues('007','LCF', -);8 Insert  intoStudentValues('008','Wjy', *);9 Insert  intoStudentValues('009','HYF', *);Ten Insert  intoStudentValues('010','LWL', A);

The table structure is as follows:

Id Name Age
001 Wfg 20
002 Lxx 21st
003 Wly 3
004 Jcj 60
005 Wss 60
006 Xsm 60
007 Lcf 60
008 Wjy 35
009 Hyf 35
010 Hwl 12

The requirements are as follows: In order of name, update the first 5 age of 100 years, how to do.

First of all, MSSQL.

1 --Scenario 1 failed2 Update Top(5) StudentSetAge=  -  Order  byname;3 --Scenario 2ok4 UpdateStudentSetAge=  - whereIdinch(Select Top 5Id fromStudentOrder  byname);5 Select Top(5)*  fromStudentOrder  byName

Very successful, good job!

Next we look at MySQL, wait and see ...

1 Update Set =  -  Order  by 5 ; 2 Select *  from Order  by 5;

Good news, MySQL did a good job,

And then we'll look at Oracle?

1 --Mode 1 failed2 UpdateStudentSetAge=  - whereRowNum<5 Order  byname;3 Commit;4 --Mode 2 failed5 UpdateStudentSetAge=  - whereIdinch(SelectId fromStudentwhereRowNum<5 Order  byname);6 Commit;7 Select *  fromStudentwhereRowNum<5 Order  byName

At present, there is no way to find a solution in Oracle, please database expert guidance, thank send by!

Oracle Update TOP N Issue, ask the expert to answer

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.