4 Txoj hauv Kev Rho Tawm Cov Ntaub Ntawv Dua Zaum Hauv Oracle

Cov txheej txheem:

4 Txoj hauv Kev Rho Tawm Cov Ntaub Ntawv Dua Zaum Hauv Oracle
4 Txoj hauv Kev Rho Tawm Cov Ntaub Ntawv Dua Zaum Hauv Oracle

Video: 4 Txoj hauv Kev Rho Tawm Cov Ntaub Ntawv Dua Zaum Hauv Oracle

Video: 4 Txoj hauv Kev Rho Tawm Cov Ntaub Ntawv Dua Zaum Hauv Oracle
Video: Mam tos hauv nruab dab. (1 tsug 13 hnub .PART#1.)_Phees lauj OFFICIAL MV 2022 2024, Kaum ib hlis
Anonim

Thaum ua haujlwm hauv Oracle, koj tuaj yeem pom cov ntawv theej ntawm qee cov ntaub ntawv. Koj tuaj yeem tshem tawm cov kab sib tshooj los ntawm kev txheeb xyuas lawv thiab siv RowID lub npe tsis sib xws nyob hauv kab. Ua ntej pib, tsim lub rooj thaub qab yog tias koj xav tau kev siv tom qab cov ntaub ntawv raug tshem tawm.

Kauj ruam

Txoj Kev 1 ntawm 4: Txheeb Xyuas Cov Luam

Rho tawm Cov Ntawv Teev Npe Hauv Oracle Kauj Ruam 1
Rho tawm Cov Ntawv Teev Npe Hauv Oracle Kauj Ruam 1

Kauj Ruam 1. Txheeb xyuas qhov sib thooj

Hauv qhov piv txwv no, peb txheeb xyuas qhov sib tshooj "Alan". Nco ntsoov tias cov ntaub ntawv yuav raug tshem tawm yog qhov tseeb los ntawm kev nkag mus rau SQL hauv qab no.

Rho tawm Cov Ntawv Teev Npe Hauv Oracle Kauj Ruam 2
Rho tawm Cov Ntawv Teev Npe Hauv Oracle Kauj Ruam 2

Kauj Ruam 2. Txheeb xyuas los ntawm kab ntawv hu ua "Lub Npe"

Yog tias kab ntawv muaj lub npe "Npe", koj yuav tsum hloov "column_name" nrog Lub Npe.

Rho tawm Cov Ntawv Teev Npe Hauv Oracle Kauj Ruam 3
Rho tawm Cov Ntawv Teev Npe Hauv Oracle Kauj Ruam 3

Kauj Ruam 3. Txheeb xyuas lwm kab ntawv

Yog tias koj tab tom sim txheeb xyuas cov ntawv sib txawv los ntawm kab sib txawv, piv txwv li Alan lub hnub nyoog tsis yog nws lub npe, nkag mus "Hnub Nyoog" hloov chaw ntawm "column_name" thiab ntxiv rau.

xaiv column_name, suav (column_name) los ntawm pawg pawg los ntawm column_name muaj suav (column_name)> 1;

Txoj Kev 2 ntawm 4: Tshem Tawm Ib Leeg

Rho tawm Cov Ntawv Teev Npe Hauv Oracle Kauj Ruam 4
Rho tawm Cov Ntawv Teev Npe Hauv Oracle Kauj Ruam 4

Kauj Ruam 1. Xaiv "npe los ntawm cov npe"

Tom qab "SQL" (luv rau Standard Query Language), sau "xaiv lub npe los ntawm cov npe".

Rho tawm Cov Ntawv Teev Npe Hauv Oracle Kauj Ruam 5
Rho tawm Cov Ntawv Teev Npe Hauv Oracle Kauj Ruam 5

Kauj Ruam 2. Rho tawm txhua kab nrog cov npe sib txawv

Tom qab "SQL", nkag mus "rho tawm ntawm cov npe nyob qhov twg lub npe = 'Alan';" Nws yuav tsum tau sau tseg tias kev nqis peev tseem ceeb ntawm no yog li cov kauj ruam no tuaj yeem tshem tawm txhua txoj kab npe "Alan". Tom qab "SQL", nkag mus "cog lus"

Rho tawm Cov Ntawv Teev Npe Hauv Oracle Kauj Ruam 6
Rho tawm Cov Ntawv Teev Npe Hauv Oracle Kauj Ruam 6

Kauj Ruam 3. Rov ua dua kab uas tsis muaj qhov sib thooj

Tam sim no koj tau tshem tag nrho cov kab thiab hloov lawv nrog "Alan", sau ib qho rov qab los ntawm kev nkag mus "ntxig rau hauv lub npe qhov tseem ceeb ('Alan');" Tom qab "SQL", nkag mus "cog lus" los tsim kab tshiab.

Rho tawm Cov Ntawv Teev Npe Hauv Oracle Kauj Ruam 7
Rho tawm Cov Ntawv Teev Npe Hauv Oracle Kauj Ruam 7

Kauj Ruam 4. Saib cov npe tshiab

Tom qab ua tiav cov theem saum toj no, koj tuaj yeem tshawb xyuas kom ntseeg tau tias tsis muaj cov ntaub ntawv theej tawm los ntawm kev nkag mus "xaiv * los ntawm cov npe".

SQL> xaiv lub npe los ntawm cov npe; Npe ------------------------------ Alan Citra Tomi Alan Baris xaiv. SQL> rho tawm ntawm cov npe nyob qhov twg lub npe = 'Alan'; Kab ntawv raug tshem tawm. SQL> cog lus; / Ua kom tiav. SQL> ntxig rau hauv cov npe qhov tseem ceeb ('Alan'); kab tsim. SQL> cog lus; Ua tiav. SQL> xaiv * los ntawm cov npe; Npe ------------------------------ Alan Citra Tomi kab xaiv.

Txoj Kev 3 ntawm 4: Tshem Tawm Ntau Yam Luam

Rho tawm Cov Ntawv Teev Npe Hauv Oracle Kauj Ruam 8
Rho tawm Cov Ntawv Teev Npe Hauv Oracle Kauj Ruam 8

Kauj Ruam 1. Xaiv RowID koj xav rho tawm

Tom qab "SQL", sau "xaiv rowid, npe los ntawm cov npe;."

Rho tawm Cov Ntawv Teev Npe Hauv Oracle Kauj Ruam 9
Rho tawm Cov Ntawv Teev Npe Hauv Oracle Kauj Ruam 9

Kauj Ruam 2. Tshem cov ntawv theej tawm

Tom qab "SQL", sau "rho tawm ntawm cov npe nyob qhov twg rowid> (xaiv min (rowid) los ntawm cov npe b qhov twg b.name = a.name);" kom tshem tawm cov theej tawm.

Rho tawm Cov Ntawv Teev Npe Hauv Oracle Kauj Ruam 10
Rho tawm Cov Ntawv Teev Npe Hauv Oracle Kauj Ruam 10

Kauj Ruam 3. Txheeb xyuas qhov sib thooj

Tom qab ua tiav cov theem saum toj no, txheeb xyuas qhov sib tshooj los ntawm kev nkag mus "xaiv kab, npe los ntawm cov npe;" ces "cog lus".

SQL> xaiv rowid, npe los ntawm cov npe; ROWID NPE ------------------------------- AABJnsAAGAAAdfOAAA Alan AABJnsAAGAAAdfOAAB Alan AABJnsAAGAAAdfOAAC Carrie AABJnsAAGAAAdfOAAD Tom AABJnsAAGAAAdfOAAF Alan kab xaiv. SQL> rho tawm ntawm cov npe nyob qhov twg rowid> (xaiv min (rowid) los ntawm cov npe b qhov twg b.name = a.name); kab deleted. SQL> xaiv rowid, npe los ntawm cov npe; ROWID NPE ------------------------------- AABJnsAAGAAAdfOAAA Alan AABJnsAAGAAAdfOAAC Carrie AABJnsAAGAAAdfOAAD Tom kab xaiv. SQL> cog lus; Ua tiav.

Txoj Kev 4 ntawm 4: Tshem Tawm Kab ntawm Kab

Rho tawm Cov Ntawv Teev Npe Hauv Oracle Kauj Ruam 11
Rho tawm Cov Ntawv Teev Npe Hauv Oracle Kauj Ruam 11

Kauj Ruam 1. Xaiv kab

Tom qab "SQL", sau "xaiv * los ntawm cov npe;" kom tuaj yeem pom kab.

Rho tawm Cov Ntawv Teev Npe Hauv Oracle Kauj Ruam 12
Rho tawm Cov Ntawv Teev Npe Hauv Oracle Kauj Ruam 12

Kauj Ruam 2. Tshem cov kab sib tshooj los ntawm kev txheeb xyuas lawv cov kab

Tom qab "SQL" sau "rho tawm ntawm cov npe nyob qhov twg rowid> (xaiv min (rowid) los ntawm cov npe b qhov twg b.name = a.name thiab b.age = a.age);" kom tshem tawm cov ntaub ntawv theej tawm.

Rho tawm Cov Ntawv Teev Npe Hauv Oracle Kauj Ruam 13
Rho tawm Cov Ntawv Teev Npe Hauv Oracle Kauj Ruam 13

Kauj Ruam 3. Txheeb xyuas qhov sib thooj

Thaum koj tau ua tiav cov theem saum toj no, nkag mus "xaiv * los ntawm cov npe;" tom qab ntawd "cog lus" txhawm rau saib yog tias cov theej tawm tau raug tshem tawm tiag.

SQL> xaiv * los ntawm cov npe; Lub Npe Hnub Nyoog ------------------------------ ---------------------- Alan 50 Citra 51 Tomi 52 Alan 50 kab xaiv. SQL> rho tawm ntawm cov npe nyob qhov twg rowid> (xaiv min (rowid) los ntawm cov npe b qhov twg b.name = a.name thiab b.age = a.age); kab deleted. SQL> xaiv * los ntawm cov npe; NPE AGE ------------------------------------------ Alan 50 Citra 51 Tomi 52 kab ntawv xaiv. SQL> cog lus; Ua tiav.

Ceeb toom

  • Tsim cov lus sib dhos hauv koj tus ID nkag mus kom nws tuaj yeem siv ua cov ntsiab lus siv thaum tsis muaj cov ntaub ntawv raug tshem tawm (yog tias koj muaj lus nug).

    SQL> tsim cov lus alan.names_backup raws li xaiv * los ntawm cov npe; Rooj tsim.

Pom zoo: