【问题标题】:How to fetch the merchant id by giving the customer id by using function?如何通过使用函数提供客户ID来获取商家ID?
【发布时间】:2022-06-22 18:24:39
【问题描述】:

我有一个名为“CUSTOMER BASIC INFO”的表格。 它们具有客户 ID 和商家 ID。 现在我想通过将客户 ID 作为输入参数来编写一个获取商家 ID 的函数。 所以请详细回答我;

【问题讨论】:

    标签: sql plsql customer


    【解决方案1】:
    CREATE PROCEDURE GetMerchantId @cid dataTypeOfCustomerId(length)
    AS
    SELECT merchant_id FROM CUSTOMER_BASIC_INFO WHERE customer_id = @cid
    GO;
    

    称之为

    EXEC GetMerchantId @cid = '5';
    

    【讨论】:

      【解决方案2】:

      代码有点简单:

      create or replace function f_test (par_customer_id in customer_basic_info.customer_id%type)
        return customer_basic_info.merchant_id%type
      is
        retval customer_basic_info.merchant_id%type;
      begin
        select merchant_id
        into retval
        from customer_basic_info
        where customer_id = par_customer_id;
      
        return retval;
      end;
      /
      

      但是,这将返回 TOO_MANY_ROWS 错误客户拥有多个商家(这很有可能),所以 - 在这种情况下您想返回什么?有商家吗?没有商家?让函数引发错误?举起它,但你会以某种方式处理它?

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-11-30
        • 2020-03-28
        • 1970-01-01
        • 2012-04-22
        • 1970-01-01
        相关资源
        最近更新 更多