Oracle数据库中的函数创建

时间:2018-05-09 07:30:41

标签: oracle

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

设计规则

  1. 如果给定实体ID的credit_limit大于50000,则将limit_status显示为'信用额度大于50000'
  2. 如果给定实体ID的credit_limit小于50000,则显示limit_status为'信用额度小于50000'
  3. 注意:请勿更改解决方案中的给定状态消息。

        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;
        /
    

    我执行上面提到的代码函数已创建,但在提交代码后显示错误的答案。帮助。

2 个答案:

答案 0 :(得分:2)

你想:

RETURN limit_status;

RETURN (c_credit_limit);

答案 1 :(得分:0)

下面的功能正常

创建或替换功能credit_limit(entity_id IN INTEGER)          RETURN VARCHAR2        IS          c_credit_limit shipment_entity.credit_limit%TYPE;          limit_status VARCHAR(255);         开始           选择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;
/