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
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.
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.
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
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".
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"
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.
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
Kauj Ruam 1. Xaiv RowID koj xav rho tawm
Tom qab "SQL", sau "xaiv rowid, npe los ntawm cov npe;."
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.
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
Kauj Ruam 1. Xaiv kab
Tom qab "SQL", sau "xaiv * los ntawm cov npe;" kom tuaj yeem pom kab.
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.
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.