CREATE OR REPLACE TYPE xx_data_struc_obj AS OBJECT(
num_col NUMBER
, num_col2 NUMBER);
/
CREATE OR REPLACE TYPE xx_data_construct_obj AS OBJECT(
--Define member Functions
xx_data_struc xx_data_struc_obj
-- this function performs addition
, MEMBER FUNCTION addition
RETURN NUMBER
-- this function performs substraction
, MEMBER FUNCTION substraction
RETURN NUMBER
-- this function performs multiplication
, MEMBER FUNCTION multiplication
RETURN NUMBER
-- this function performs dividation
, MEMBER FUNCTION dividation
RETURN NUMBER);
/
CREATE OR REPLACE TYPE BODY xx_data_construct_obj
AS
MEMBER FUNCTION addition
RETURN NUMBER
AS
l_result NUMBER;
BEGIN
l_result := xx_data_struc.num_col + xx_data_struc.num_col2;
RETURN l_result;
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.put_line( 'ADDITION : UNEXP_ERROR : '
|| SUBSTR(SQLERRM
, 1
, 250));
END addition;
MEMBER FUNCTION substraction
RETURN NUMBER
AS
l_result NUMBER;
BEGIN
l_result := xx_data_struc.num_col2 - xx_data_struc.num_col;
RETURN l_result;
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.put_line( 'SUBSTRACTION : UNEXP_ERROR : '
|| SUBSTR(SQLERRM
, 1
, 250));
END substraction;
MEMBER FUNCTION multiplication
RETURN NUMBER
AS
l_result NUMBER;
BEGIN
l_result := xx_data_struc.num_col * xx_data_struc.num_col2;
RETURN l_result;
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.put_line( 'MULTIPLICATION : UNEXP_ERROR : '
|| SUBSTR(SQLERRM
, 1
, 250));
END multiplication;
MEMBER FUNCTION dividation
RETURN NUMBER
AS
l_result NUMBER;
BEGIN
l_result:= ROUND(xx_data_struc.num_col/xx_data_struc.num_col2);
RETURN l_result;
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.put_line( 'DIVIDATION : UNEXP_ERROR : '
|| SUBSTR(SQLERRM
, 1
, 250));
END dividation;
END;
/
--------------Execution -------------------------
DECLARE
data_struc xx_data_struc_obj := xx_data_struc_obj(25, 60);
data_construct xx_data_construct_obj
:= xx_data_construct_obj( data_struc);
BEGIN
DBMS_OUTPUT.put_line( 'Addition Output: '||data_construct.addition);
DBMS_OUTPUT.put_line( 'Substraction Output: '||data_construct.substraction);
DBMS_OUTPUT.put_line( 'Multiplication Output: '||data_construct.multiplication);
DBMS_OUTPUT.put_line( 'Dividation Output: '||data_construct.dividation);
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.put_line( 'BLOCK : UNEXP_ERROR : '
|| SUBSTR(SQLERRM
, 1
, 250));
END;
num_col NUMBER
, num_col2 NUMBER);
/
CREATE OR REPLACE TYPE xx_data_construct_obj AS OBJECT(
--Define member Functions
xx_data_struc xx_data_struc_obj
-- this function performs addition
, MEMBER FUNCTION addition
RETURN NUMBER
-- this function performs substraction
, MEMBER FUNCTION substraction
RETURN NUMBER
-- this function performs multiplication
, MEMBER FUNCTION multiplication
RETURN NUMBER
-- this function performs dividation
, MEMBER FUNCTION dividation
RETURN NUMBER);
/
CREATE OR REPLACE TYPE BODY xx_data_construct_obj
AS
MEMBER FUNCTION addition
RETURN NUMBER
AS
l_result NUMBER;
BEGIN
l_result := xx_data_struc.num_col + xx_data_struc.num_col2;
RETURN l_result;
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.put_line( 'ADDITION : UNEXP_ERROR : '
|| SUBSTR(SQLERRM
, 1
, 250));
END addition;
MEMBER FUNCTION substraction
RETURN NUMBER
AS
l_result NUMBER;
BEGIN
l_result := xx_data_struc.num_col2 - xx_data_struc.num_col;
RETURN l_result;
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.put_line( 'SUBSTRACTION : UNEXP_ERROR : '
|| SUBSTR(SQLERRM
, 1
, 250));
END substraction;
MEMBER FUNCTION multiplication
RETURN NUMBER
AS
l_result NUMBER;
BEGIN
l_result := xx_data_struc.num_col * xx_data_struc.num_col2;
RETURN l_result;
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.put_line( 'MULTIPLICATION : UNEXP_ERROR : '
|| SUBSTR(SQLERRM
, 1
, 250));
END multiplication;
MEMBER FUNCTION dividation
RETURN NUMBER
AS
l_result NUMBER;
BEGIN
l_result:= ROUND(xx_data_struc.num_col/xx_data_struc.num_col2);
RETURN l_result;
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.put_line( 'DIVIDATION : UNEXP_ERROR : '
|| SUBSTR(SQLERRM
, 1
, 250));
END dividation;
END;
/
--------------Execution -------------------------
DECLARE
data_struc xx_data_struc_obj := xx_data_struc_obj(25, 60);
data_construct xx_data_construct_obj
:= xx_data_construct_obj( data_struc);
BEGIN
DBMS_OUTPUT.put_line( 'Addition Output: '||data_construct.addition);
DBMS_OUTPUT.put_line( 'Substraction Output: '||data_construct.substraction);
DBMS_OUTPUT.put_line( 'Multiplication Output: '||data_construct.multiplication);
DBMS_OUTPUT.put_line( 'Dividation Output: '||data_construct.dividation);
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.put_line( 'BLOCK : UNEXP_ERROR : '
|| SUBSTR(SQLERRM
, 1
, 250));
END;
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.