必须声明如何解决“标识符” ACCOUNT_REQUEST_TBL“

时间:2019-09-12 07:11:24

标签: oracle plsql oracleforms

一个错误

  

FRM-40735::未按一下按钮时触发扳机    ORA-06502

在我尝试如下插入字段时出现提示。可能是什么原因 ?

DECLARE

    v_reqid NUMBER(10) := :txtreqid;
    v_branch VARCHAR2(15) := :txtbranch;
    v_acctype VARCHAR2(15) := :txtacctype;
    v_title VARCHAR2(4) := :txttitle;
    v_firstname VARCHAR2(15) := :register.txtfirstname;
    v_lastname VARCHAR2(15) := :register.TXLASTNAME;
    v_DOB DATE := :txtdob;
    v_workp NUMBER(10) := :txtworkp;
    v_hphone NUMBER(10) := :txthphone;
    v_address VARCHAR2(30) := :txtadd;
    v_state_info VARCHAR2(15) := :txtstate;
    v_hphone NUMBER(10) := :txtzip;
    v_email VARCHAR2(30) := :txtemail;
    v_status VARCHAR2(10) := :txtstatus;
    v_user_name VARCHAR2(30) := :txtun;
    v_password VARCHAR2(30) := :txtpw;
BEGIN
    INSERT INTO account_request_tbl
    VALUES(v_reqid,v_branch,v_acctype,v_title,v_firstname,  v_lastname,v_DOB,v_workp, 
           v_hphone,v_address,v_state_info,v_hphone,v_email,v_status,v_user_name,v_password);

    COMMIT;
    message('You have succesfully created a new account!');
END;

1 个答案:

答案 0 :(得分:1)

假设变量名称是从表account_request_tbl列的名称派生的,请改用account_request_tbl.<column_name>%type来定义变量的数据类型。由于您的问题与数据类型的不匹配和/或局部变量与列的数据类型之间的精度有关:

DECLARE
    v_reqid      account_request_tbl.reqid%type := :txtreqid;
    v_branch     account_request_tbl.branch%type := :txtbranch;
    v_acctype    account_request_tbl.acctype%type := :txtacctype;
    v_title      account_request_tbl.title%type := :txttitle;
    v_firstname  account_request_tbl.firstname%type := :register.txtfirstname;
    v_lastname   account_request_tbl.lastname%type := :register.TXLASTNAME;
    v_DOB        account_request_tbl.dob%type := :txtdob;
    v_workp      account_request_tbl.workp%type := :txtworkp;
    v_hphone     account_request_tbl.hphone%type := :txthphone;
    v_address    account_request_tbl.address%type := :txtadd;
    v_state_info account_request_tbl.state_info%type := :txtstate;
    v_email      account_request_tbl.email%type := :txtemail;
    v_status     account_request_tbl.status%type := :txtstatus;
    v_user_name  account_request_tbl.user_name%type := :txtun;
    v_password   account_request_tbl.password%type := :txtpw;
BEGIN
   INSERT INTO account_request_tbl(reqid,branch,acctype,title,firstname,lastname,dob,workp,
               hphone, address, state_info, email, status, user_name, password )
   VALUES(v_reqid,v_branch,v_acctype,v_title,v_firstname,  v_lastname,v_DOB,v_workp,              
          v_hphone,v_address,v_state_info,v_email,v_status,v_user_name,
          v_password);

   IF SQL%ROWCOUNT > 0 THEN 
     COMMIT;
     message('You have succesfully created a new account!');
   ELSE
     ROLLBACK;
     message('Unfortunately, you couldn''t create a new account !!!');
   END IF; 
END;

错误的原因可能有所不同,例如字段:txtadd的长度不适合VARCHAR2(30),或者:txtreqid字段中的值是字符串类型..等 实际上,无需显式声明变量,INSERT语句内的直接替换就足够了(感谢@AndyDan )为

INSERT INTO account_request_tbl(reqid,branch,acctype,title,firstname,lastname,dob,workp,
            hphone, address, state_info, email, status, user_name, password )
VALUES(:txtreqid,:txtbranch,:txtacctype,:txttitle,:register.txtfirstname,  
       :register.txlastname, :txtdob, :txtworkp,:txthphone, :txtadd, :txtstate,:txtemail,
       :txtstatus, :txtun, :txtpw);