-
oracle PL/SQL_서브프로그램_함수DataBase/oracle 2020. 4. 20. 02:32
< 함수와 프로시저의 차이점 >
프로시저 : in, out, in out모드를 사용여 값을 반환 하기도 하고, 반환하지 않고 종료 할 수 있다.
함수 : 작업을 수행한 후에 결과를 반환한다
***함수의 구문 형식
create [or replace ] function 함수명
파라미터1 데이터타입,
파라미터2 데이터타입,
...
return datatype
is [as]
PL/SQL 블럭;
기본함수
123456789101112131415create or replace function dept_max_sal( dept_id employees.department_id%type)return numberismax_sal employees.salary%type;beginselect max(salary) into max_salfrom employeeswhere department_id = dept_id;return max_sal;end;/select dept_max_sal(50) from dual;함수_2
123456789101112create or replace function cnt_member(cnt number)return numberistotal_cnt number;beginselect count(*) into total_cntfrom employeeswhere department_id = cnt;return total_cnt;end;/http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter1select cnt_member(50) from employees;==> 107개가 출력된다
1select count(*) from employees where department_id = 50;==> 이거랑 같은 값이 나와야하는거 아닌가??
'DataBase > oracle' 카테고리의 다른 글
oracle PL/SQL_트리거 (0) 2020.04.26 oracle PL/SQL_패키지 (0) 2020.04.20 oracle PL/SQL_서브프로그램_프로시저(procedure) (0) 2020.04.19 oracle PL/SQL_예외처리(Exception) (0) 2020.04.19 oracle PL/SQL_ 커서(cursor) (0) 2020.03.29