저장 프로 세 스 와 저장 함수 와 트리거 예제
SQL> create or replace procedure raiseSalary(empid in number)
as
pSal emp.sal%type;
begin
select sal into pSal from emp where empno=empid;
update emp set sal = sal*1.1 where empno=empid;
dbms_output.put_line(' :' || empid || '
' || psal || ' ' || psal*1.1);
end;
/
Procedure created
SQL> set serveroutput on
SQL> exec raisesalary(7369);
직원 번호: 7369 임금 인상 전
800 임금 인상 후 880
PL/SQL procedure successfully completed
2. 저장 함수 예시: 모 직원 의 연수 입 을 조회 합 니 다.
SQL> /** 모 직공 의 총수입 을 조회 하 다 */
create or replace function queryEmpSalary(empid in number)
return number
as
pSal number; --
pComm number; --
begin
select sal,comm into psal,pcomm from emp where empno = empid;
return psal*12+nvl(pcomm,0);
end;
/
Function created
SQL> declare
v_sal number;
begin
v_sal:=queryEmpSalary(7934);
dbms_output.put_line('salary is:'|| v_sal);
end;
/
salary is:15600
PL/SQL procedure successfully completed
SQL> begin
dbms_output.put_line('salary is:'|| queryEmpSalary(7934));
end;
/
salary is:15600
PL/SQL procedure successfully completed
3. 트리거 예제 생 성 1: 비 작업 시간 을 제한 하여 데이터베이스 에 데 이 터 를 삽입 합 니 다.
SQL> create or replace
trigger securityEmp
before insert on emp
declare
begin
if to_char(sysdate,'day')in(' ',' ',' ')
or to_number(to_char(sysdate,'hh24'))not between 8 and 18 then
raise_application_error(-20001,' 。');
end if;
end;
/
Trigger created
4. 트리거 예제 2: 데 이 터 를 확인 합 니 다 (emp 표 에서 sal 의 수정 값 이 원래 값 보다 낮 지 않 음 을 검사 합 니 다)
SQL> create or replace trigger checkSal
before update of sal on emp
for each row
declare
begin
if :new.sal<:old.sal then
raise_application_error(-20001,' ');
end if;
end;
/
Trigger created
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.