0
Question is : I have to Create Function with below Details 
Function Name : Credit_Limit 
Input         : Entity_Id (Shipment_entity) 
Returns       : VARCHAR2 (Limit_Status)

Design rules:

  1. If the credit_limit of the given entity id is greater then 50000,then display the limit_status as 'Credit limit is greater than 50000'
  2. If the credit_limit of the given entity id is less then 50000,then display the limit_status as 'Credit limit is less than 50000'

Note: DO NOT CHANGE the given status message in your solution.

    CREATE OR REPLACE FUNCTION credit_limit (entity_id IN INTEGER)
         RETURN VARCHAR2
       IS
         c_credit_limit   NUMBER (5, 2);
         limit_status     VARCHAR (255);
        BEGIN
          SELECT credit_limit
             INTO c_credit_limit
           FROM shipment_entity
          WHERE id = entity_id;

    IF c_credit_limit > 50000
    THEN
        limit_status := 'Credit limit is greater than 50000';
    ELSE
        IF c_credit_limit < 50000
        THEN
            limit_status := 'Credit limit is less than 50000';
        END IF;
    END IF;

    RETURN (c_credit_limit);
    END;
    /

I executed the above mentioned code the function is created but it shows wrong answer after submit the code. help on this.

3
  • number(5, 2) will allow numbers up to 999.99... Commented May 9, 2018 at 7:38
  • Better use c_credit_limit shipment_entity.credit_limit%TYPE; instead of c_credit_limit NUMBER (5, 2); Commented May 9, 2018 at 8:06
  • Thank you..Function is created/executed successfully Commented May 9, 2018 at 12:35

2 Answers 2

2

You want:

RETURN limit_status;

not

RETURN (c_credit_limit);
Sign up to request clarification or add additional context in comments.

Comments

0

Below Function is working fine

CREATE OR REPLACE FUNCTION credit_limit (entity_id IN INTEGER) RETURN VARCHAR2 IS c_credit_limit shipment_entity.credit_limit%TYPE; limit_status VARCHAR (255); BEGIN SELECT credit_limit INTO c_credit_limit FROM shipment_entity WHERE id = entity_id;

IF c_credit_limit > 50000
THEN
    limit_status := 'Credit limit is greater than 50000';
ELSE
    IF c_credit_limit < 50000
    THEN
        limit_status := 'Credit limit is less than 50000';
    END IF;
END IF;

RETURN limit_status;
END;
/

Comments

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.