Robert Martinsson
Robert Martinsson

Reputation: 5

dbms_output.put_line write out each value from function

I've got a function that takes three number arguments and returns a value calculated from those three numbers. Now in another stored procedure I call try to write out each value like this:

CREATE OR REPLACE PROCEDURE P_POOL 
IS

BEGIN

DBMS_OUTPUT.PUT_LINE('test'||' '||POOL_PKG.F_REKTANGULÄR(6,4,2);

But I want to the output to be example:

test is 6 meter and 4 meter and 2 meter!

How can I add text after each value?

Upvotes: 0

Views: 72

Answers (1)

kevinskio
kevinskio

Reputation: 4551

Try this

Package POOL_PKG 
IS

FUNCTION F_REKTANGULÄR(meter_in NUMBER,height_in NUMBER,bottom_in NUMBER,Show_dims_in IN NUMBER := 0) RETURN NUMBER;

END POOL_PKG;

Package Body POOL_PKG is

FUNCTION F_REKTANGULÄR(meter_in NUMBER,height_in NUMBER,bottom_in NUMBER, Show_dims_in IN NUMBER := 0) RETURN NUMBER
v_result NUMBER(10);
v_unit VARCHAR2(10) := 'meter';
IS

--assert that all inputs are greater than 0
--and less than a reasonable amount

v_result := meter_in * height_in * bottom_in;
IF show_dims_in = 1 
THEN
DBMS_OUTPUT(meter_in ||' '||v_unit||', '||height_in||' '||v_unit||', '||bottom_in);
END IF;
RETURN v_result;
END F_REKTANGULÄR;

END POOL_PKG;

and could be used this way DECLARE v_result NUMBER(9); BEGIN v_result := POOL_PKG.F_REKTANGULÄR(6 ,4 ,2,1); END;

Or, given your comments this would work to:

Declare
a NUMBER(9);
b NUMBER(9);
c NUMBER(9);
v_unit VARCHAR2(10) := 'meter';
v_result NUMBER(9);
BEGIN
a := 6;
b := 4;
c := 2;

    DBMS_OUTPUT(a||' '||v_unit||', '||b||' '||v_unit||', '||c||' '||v_unit);
    v_result := POOL_PKG.F_REKTANGULÄR(a ,b ,c);
END;

Upvotes: 1

Related Questions