0

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?

1 Answer 1

1

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;
Sign up to request clarification or add additional context in comments.

5 Comments

Sorry was in a bit hurry :-) ok i Will try . i want the output to be like this : 6 meter, 4 meter and 2 meter.
Cant you change in dbms_output? CREATE OR REPLACE PROCEDURE P_POOL IS BEGIN DBMS_OUTPUT.PUT_LINE(POOL_PKG.F_REKTANGULÄR(6,4,1.5)); is it impossible to pick out value 6 first and print out after, then 4, to get this: spec: Lenght 6 meter, bottom 2 meter, height 1,5 meters.. ? Bec i have a stored procedure who call this function output..
Not without using more complicated methods to break down the results from the function.
Ok well when i write it out now i got this: speci: Längd 6 meter, bredd 4 meter, höjd 1,5 meter 36 Volym: 36 meter cost: 45 i got 36 below, can i remove it?
IT WORKS! thank you :P i added the comment v_result NUMBER(9); BEGIN v_result := POOL_PKG.F_REKTANGULÄR(6 ,4 ,2,1); in my procedure now it works good.. doesnt print out the 36 either perfect! ty :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.