CREATE OR REPLACE FUNCTION iva(numero1 NUMBER)
RETURN NUMBER
IS
suma NUMBER;
BEGIN
suma :=numero1 * 0.19;
RETURN suma;
END;
SELECT iva(196330000)
FROM dual;
DIVISION
CREATE OR REPLACE FUNCTION DIVISION(NUMERO1 NUMBER,NUMERO2 NUMBER)
RETURN NUMBER
IS
DIVISION NUMBER;
BEGIN
DIVISION :=NUMERO1 / NUMERO2;
RETURN DIVISION;
END;
SELECT DIVISION(7,2)
FROM dual;
RESTA
CREATE OR REPLACE FUNCTION RESTA(NUMERO1 NUMBER,NUMERO2 NUMBER)
RETURN NUMBER
IS
RESTA NUMBER;
BEGIN
RESTA :=NUMERO1 - NUMERO2;
RETURN RESTA;
END;
SELECT RESTA(7,2)
FROM dual;
DIVIDIR CONDICION
CREATE OR REPLACE FUNCTION DIVID(NUM1 NUMBER, NUM2 NUMBER)
RETURN NUMBER
IS
DIVID NUMBER;
BEGIN
IF NUM2 <> 0 THEN
RETURN NUM1/NUM2;
ELSE
RETURN 0;
END IF;
END;
SELECT DIVID (7,0)
FROM DUAL;
SELECT DIVID (7,0)
FROM DUAL;
create or replace FUNCTION F_DIVISION(N1 NUMBER,N2 NUMBER)
RETURN NUMBER AS DIVIN NUMBER;
BEGIN
DIVIN :=N1/N2;
EXCEPTION
WHEN zero_divide THEN
dbms_output.put_line('el valor no puede ser negativo');
RETURN DIVIN;
END F_DIVISION;
SELECT F_DIVISION(120,0) Division from dual;
RESTA
CREATE OR REPLACE FUNCTION RESTA(NUMERO1 NUMBER,NUMERO2 NUMBER)
RETURN NUMBER
IS
RESTA NUMBER;
BEGIN
RESTA :=NUMERO1 - NUMERO2;
RETURN RESTA;
END;
SELECT RESTA(7,2)
FROM dual;
DIVIDIR CONDICION
CREATE OR REPLACE FUNCTION DIVID(NUM1 NUMBER, NUM2 NUMBER)
RETURN NUMBER
IS
DIVID NUMBER;
BEGIN
IF NUM2 <> 0 THEN
RETURN NUM1/NUM2;
ELSE
RETURN 0;
END IF;
END;
SELECT DIVID (7,0)
FROM DUAL;
SELECT DIVID (7,0)
FROM DUAL;
create or replace FUNCTION F_DIVISION(N1 NUMBER,N2 NUMBER)
RETURN NUMBER AS DIVIN NUMBER;
BEGIN
DIVIN :=N1/N2;
EXCEPTION
WHEN zero_divide THEN
dbms_output.put_line('el valor no puede ser negativo');
RETURN DIVIN;
END F_DIVISION;
SELECT F_DIVISION(120,0) Division from dual;