//The stored procedure is used to operate the database, the function is used to return data, the stored procedure can be called in the stored procedure, the function
create or replace (PROCEDURE/FUNCTION) ***(parameter type)//For stored procedures, the parameters are in out. If the default in is not written, the functions are all in (no need to write)
as /return varchar2 IS//The stored procedure uses as, and the function uses return varchar2 IS
///PRAGMA AUTONOMOUS_TRANSACTION; the sub-thing has an exception and the main thing is not affected. His price increase can drive the submission of the main thing
Variable name Variable type //// When assigning value, variable name:=; Do not type when referencing:
V_STR VARCHAR2(10240) DEFAULT '';
begin
if .. and ... then
else
end if;
Variable:=case variable when 'null' then '' when 'NULL' then '' else variable end;
when ... then
when others then
//return variable; function return
commit;////If exception handling is used, then the operation in the entire stored procedure should be set to rollback, and then write ROLLBACK when handling exceptions; functions and views do not perform data operations, but only operations, and stored procedures can only say things
end;
//////view
create or replace view **
as
query statement only
Several common syntaxes are used together:
// query assignment
SELECT CHK_STATUS
INTO V_CHK_STATUS
FROM TB_CD_DEP
WHERE CD_KEY=V_CD_KEY;
//Insert query, omit the value keyword
INSERT INTO TB_CD_LOG_NEW(
LOG_KEY,CD_KEY,LOG_TYPE
,OPE_MAN_KEY,OPE_MAN
,LOG_TIME,LOG_CONTENT
,REMARK
)
SELECT
V_LOG_KEY,CD_KEY,'F'
,NULL,V_STORAGE_CHK_MAN
,SYSDATE,'Warehouse receipt review operation: review rejected'
,NULL
FROM TB_CD_DEP
WHERE CD_KEY=V_CD_KEY;
Exception handling:
Parameter definition place:
USERDEF_EXCPT EXCEPTION;
An exception needs to be thrown:
RAISE USERDEF_EXCPT;
Catch exception handling:
EXCEPTION
WHEN USERDEF_EXCPT THEN
ROLLBACK;
OUTPARA := 'ARTNFLAG=1'||CHR(13)||CHR(10)||'MSG='||TRIM(V_ERRMSG);
PD_BAS_GETPRO_LOG('PD_CD_CHK','Warehouse receipt review',INPARA,OUTPARA,'N');
WHEN OTHERS THEN
ROLLBACK;
OUTPARA := 'ARTNFLAG=1'||CHR(13)||CHR(10)||'MSG='||SQLERRM;
PD_BAS_GETPRO_LOG('PD_CD_CHK','Warehouse receipt review',INPARA,OUTPARA,'N')