对create_person的Oracle过程失败,出现PLS-00306错误

时间:2014-09-19 06:59:13

标签: oracle plsql

我有一个包规范:

G_PKG_NAME   CONSTANT VARCHAR2(30) := 'XX_CUST_PKG';
PROCEDURE customer_load
( errbuff OUT NOCOPY VARCHAR2
, retcode OUT NOCOPY VARCHAR2);

以及调用HZ_PARTY_V2PUB API的过程的主体。它使用游标从表中获取数据,然后将其发送到API:

PROCEDURE create_customer
( errbuff OUT NOCOPY VARCHAR2
, retcode OUT NOCOPY VARCHAR2)
IS

ERR_SOURCE   CONSTANT VARCHAR2(100) := G_PKG_NAME ||'.create_customer'; 

CURSOR c_load 
IS 
  SELECT    rowid               row_id
  ,         person_first_name  
  ,         person_last_name   
  ,         title              
  ,         known_as           
  ,         person_identifier  
  ,         gender             

  FROM      xx_customer_info
  WHERE     NVL(status_flag, 'X') <> 'S';

r_load c_load%ROWTYPE;      
--p_init_msg_list VARCHAR2(1) := FND_API.G_TRUE;    
v_gender        VARCHAR2(30); --hz_parties.sex%TYPE;
v_title         VARCHAR2(60); --hz_parties.title%TYPE;

--API record type 
person_rec      HZ_PARTY_V2PUB.PERSON_REC_TYPE;

-- API output variables
x_return_status VARCHAR2(1);
x_msg_count     NUMBER;
x_msg_data      VARCHAR2(2000);
x_party_id      NUMBER;
x_party_number  VARCHAR2(30);
x_profile_id    NUMBER;

EXC_VALDN_ERR EXCEPTION;

BEGIN

  errbuff := ' ';
  retcode := RTN_SUCCESS;

  msg_log ('Inside '||ERR_SOURCE);

  FOR r_load in c_load LOOP

    BEGIN 
      x_msg_data      := NULL;
      x_return_status := fnd_api.G_RET_STS_SUCCESS;

      fnd_msg_pub.initialize;

      -- example validation: 
      IF r_load.person_first_name IS NULL THEN 
        x_msg_data := ' "First name" cannot be null';
        RAISE EXC_VALDN_ERR;
      END IF;

      -- Same validation for person_last_name here

      -- Record Type:

      person_rec.person_first_name  := r_load.person_first_name;
      person_rec.person_last_name   := r_load.person_last_name;
      person_rec.person_title       := v_title;
      person_rec.known_as           := null;
      person_rec.gender             := v_gender;  
      person_rec.created_by_module  := 'TCA_V2_API';



      HZ_PARTY_V2PUB.create_person ( p_init_msg_list => FND_API.G_TRUE
                                   , p_person_rec    => person_rec
                                   , x_party_id      => x_party_id
                                   , x_party_number  => x_party_number 
                                   , x_profile_id    => x_profile_id
                                   , x_return_status => x_return_status
                                   , x_msg_count     => x_msg_count
                                   , x_msg_data      => x_msg_data);

      msg_log('==========================');
      msg_log('first name / last_name : '||r_load.person_first_name||' | '||r_load.person_last_name);
      msg_log('x_return_status: '||x_return_status);
      msg_log('x_msg_count: '||x_msg_count);
      msg_log('x_msg_data: '||x_msg_data);

      IF NVL(x_return_status, FND_API.G_RET_STS_ERROR) <> FND_API.G_RET_STS_SUCCESS THEN 
        IF NVL(x_msg_count, 0) > 1 THEN
          FOR i IN 1..x_msg_count LOOP
            x_msg_data := x_msg_data||i||'. '||substr(fnd_msg_pub.get(p_encoded => fnd_api.g_false ), 1, 255)||' , ';
            msg_log(x_msg_data);
          END LOOP;
        END IF;     
      END IF;

      msg_log('==========================');

    EXCEPTION
      WHEN OTHERS THEN
        x_msg_data      := 'EXC: '||NVL(x_msg_data, SQLERRM);
        x_return_status := FND_API.G_RET_STS_ERROR;
    END;


    UPDATE xx_customer_info
    SET    status_flag = x_return_status
    ,      error_message = x_msg_data
    WHERE  rowid = r_load.row_id;

  END LOOP;

  COMMIT;

  msg_log ('Exit '||ERR_SOURCE);      

EXCEPTION
  WHEN OTHERS THEN   
    ROLLBACK;
    msg_log('ERROR : '||ERR_SOURCE||' : '||NVL(SQLERRM, x_msg_data));
    errbuff := 'ERROR : '||ERR_SOURCE||' : '||NVL(SQLERRM, x_msg_data);
    retcode := RTN_ERROR;   

END create_customer;

它应该返回错误或成功。

当我在匿名块中测试并运行它时:

begin
 XX_CUST_PKG.create_customer;
end;

我收到错误消息PLS-00306:调用'CREATE_CUSTOMER'时参数的数量或类型错误。我无法清楚地看到此错误所指的位置。我只有2个OUT参数,它应该只给 errbuff (这是x_msg_data)和 retcode ,它是RTN_SUCCESS,RTN_WARNING或RTN_ERROR(我把它声明为常量'0' ,'1','2')输出。

这是从初始包重写到上面的示例代码,因此它处理异常,很少有东西需要修改,但现在我在测试它时感到困惑。

我遗漏了什么? 有什么帮助吗?

1 个答案:

答案 0 :(得分:0)

您收到的错误是PL/SQL编译错误,因为您可以看到错误代码以PLS-XXXX开头..因此,它不会从您的过程返回。您错过了发送变量来保存过程中的值(out arguments)

   Declare
      errbuf varchar2(4000);
      retcode varchar2(10); 
   begin
     XX_CUST_PKG.create_customer(errbuf,retcode);
     --printing the values
     DBMS_OUTPUT.PUT_LINE(retcode||' '||errbuf);
    end;
    /