Txhim Txheej Txheem vs Ua Haujlwm
Cov txheej txheem khaws cia thiab kev ua haujlwm yog ob hom programming blocks. Ob leeg yuav tsum muaj npe. Cov npe hu yog siv los hu rau lawv hauv lwm qhov programming block zoo li cov txheej txheem ua haujlwm thiab pob khoom lossis SQL queries. Ob qho tib si ntawm cov khoom no lees txais cov kev txwv thiab ua haujlwm tom qab cov khoom ntawd. Nov yog cov syntax (hauv ORACLE) los tsim cov txheej txheem khaws cia, tsim lossis hloov cov txheej txheem npe (tsis suav)
as
pib
nqe lus;
exception
exception_handling
end;
Thiab ntawm no yog cov syntax los tsim ua haujlwm (hauv ORACLE), tsim lossis hloov cov haujlwm ua haujlwm_name (tsis muaj)
return return_datatype
as
pib
nqe lus;
return_value/variable;
exception;
exception_handling;
end;
Cov txheej txheem khaws cia
Raws li tau hais los saum toj no cov txheej txheem khaws cia yog lub npe hu ua programming blocks. Lawv lees txais cov kev txwv raws li cov neeg siv tswv yim thiab cov txheej txheem raws li cov logic tom qab cov txheej txheem thiab muab cov txiaj ntsig (lossis ua ib qho kev txiav txim tshwj xeeb). Cov kev ntsuas no tuaj yeem yog IN, OUT thiab INOUT hom. Cov lus tshaj tawm sib txawv, kev ua haujlwm sib txawv, tswj cov lus, voj, SQL queries thiab lwm yam haujlwm / txheej txheem / pob hu tuaj yeem nyob hauv lub cev ntawm cov txheej txheem.
Functions
Functions kuj muaj npe hu ua programming blocks, uas yuav tsum xa rov qab tus nqi siv RETURN nqe lus, thiab ua ntej nws rov qab tus nqi, nws lub cev ua qee yam ua dhau los (raws li qhov muab logic). Functions kuj lees txais cov kev khiav haujlwm. Cov haujlwm tuaj yeem hu rau hauv cov lus nug. Thaum muaj nuj nqi hu ua SELECT query, nws siv rau txhua kab ntawm cov txiaj ntsig ntawm SELECT query. Muaj ob peb pawg ntawm ORACLE cov haujlwm. Lawv yog,
Ib kab ua haujlwm (rov qab ib qho txiaj ntsig rau txhua thiab txhua kab ntawm cov lus nug)
Muaj qee pawg ntawm ib kab ua haujlwm.
- Numeric function (Ex: ABS, SIN, COS)
- Character muaj nuj nqi (Ex: CONCAT, INITCAP)
- Hnub tim muaj nuj nqi (Ex: LAST_DAY, NEXT_DAY)
- Conversion functions (Ex: TO_CHAR, TO_DATE)
- Collection function (Ex: CARDINALITY, SET)
- Aggregate functions (Rau ib kab ib kab, raws li ib pawg kab. Ex: AVG, SUM, MAX)
- Analytic functions
- Object reference functions
- qauv ua haujlwm
- Tus neeg siv lub luag haujlwm
Qhov txawv ntawm kev ua haujlwm thiab Cov Txheej Txheem Khaws Cia yog dab tsi?
• Txhua txoj haujlwm yuav tsum xa rov qab tus nqi siv RETURN nqe lus. Cov txheej txheem khaws cia tsis rov qab qhov txiaj ntsig siv RETURN nqe lus. Rov qab nqe lus nyob rau hauv ib tug txheej txheem yuav rov qab nws cov kev tswj mus rau qhov kev pab cuam hu. OUT parameters tuaj yeem siv los xa cov txiaj ntsig los ntawm cov txheej txheem khaws cia.
• Cov haujlwm tuaj yeem hu rau hauv cov lus nug, tab sis cov txheej txheem khaws cia tsis tuaj yeem siv hauv cov lus nug.
• Cov ntaub ntawv xa rov qab yuav tsum suav nrog los tsim kev ua haujlwm, tab sis hauv cov txheej txheem khaws cia DDL, nws tsis yog.