Merge functions in Oracle (batch update/delete)

Source: Internet
Author: User
DEFINETABLE: SCORE: Keys: thebaseinformationofstudentsDEFINECOLUMNS: STUNO: thestudentsIDintheUniversitySTUNAME: studentsnameCOURSENAME: coursenameCOURSESCORE: t

Define table: SCORE: using for save the students score informations STUDENTS: the base information of students define columns: STUNO: the students 'Id in theUniversity STUNAME: students 'name COURSENAME: course name COURSESCORE: t

Define table:

SCORE: using for save the students 'score informations

STUDENTS: the base information of students

Define columns:

STUNO: the students 'Id in the University

STUNAME: students 'name

COURSENAME: course name

COURSESCORE: the study-results of the reference course

CLASSNAME: where the students study in

STUGRADE: the students grade

TERMNAME: the term which the reference course studied

Now beagin to write down the statement here blow this line!

MERGE INTO SCORE S

USING

(

Select a. *, B .*,? Myscore from score a, STUDENT B

WHERE

A. CLASSNO =? And a. GRADE =?

And a. TERMNAME =? And a. COURSENAME =?

A. STUNO = B. STUNO (+)

) X

ON

(S. STUNO = X. STUNO)

WHEN

MATHED

THEN

Update set coursescore = X. MYSCORE

WHEN

NOT MATHED

THEN

INSERT

(

STUNO, STUNAME, COURSENAME, COURSESCORE,

CLASSNAME, STUGRADE, TERMNAME

)

VALUES

(

X. STUNO, X. STUNAME, X. COURSENAME, X. MYSCORE,

X. CLASSNAME, X. STUGRADE, X. TERMNAME

);

NotesMERGEStatement at the end of ";" (semicolon), which only takesMERGEFor a completeSQLStatement.

[1] [2]

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.