본문 바로가기
개발/sql

oracle sql function, dual,upper

by 카앙구운 2015. 10. 6.
728x90
반응형

ed fn_sum2


create or replace function fn_sum2

(v_sum1 in number,

v_sum2 in number)

return number

is 

v_sum number;

begin

v_sum :=v_sum1 + v_sum2;

return v_sum;

end;

/

@fn_sum2

variable sum number;

execute :sum :=fn_sum2(10,20)

print sum;


select fn_sum2(10,20) from dual;


--------------------------------------

ed sum_dept;


create or replace function sum_dept

(v_deptno in dept.deptno%type)

return number


is

v_sum number;

begin

select sum(sal) into v_sum from emp

where deptno=v_deptno;

return v_sum;

end;

/

@sum_dept;

select sum_dept(10) from dual;

------------------------------------------


ed emp_sal


create or replace function emp_sal

(v_empno in emp.empno%type)

return number


is

v_empsal number;

v_sal number;

begin

select sal into v_empsal from emp

where empno=v_empno;

v_sal:=v_empsal*1.5;

return v_sal;

end;

/

@emp_sal;

select emp_sal(7900) from dual;

------------------------------------------

ed ssss;


create or replace function ssss

(v_ename in emp.ename%type)

return varchar2


is

v_dname dept.dname%type;

begin

select d.dname into v_dname from (select deptno from emp where ename=UPPER(v_ename)) e,dept d 

where d.deptno=e.deptno;

return v_dname;

end;

/

@ssss

select ssss('SMITH') from dual;



728x90
반응형

댓글