0

我在 oracle 存储过程中有一个游标,它随机截断返回的列之一中的值。

我看不到任何模式,有时它会起作用,有时它只是将值截断为 1 个字符长。

这是光标:

CURSOR cur_clients IS
    SELECT DISTINCT p.PROPOSAL_ID, rop.client_id, c.FORENAME, c.INITIAL1, c.SURNAME, concat(c.FORENAME,c.SURNAME),
      c.DATE_OF_BIRTH, c.SEX, a.ADDRESS_LINE1, a.ADDRESS_LINE2, a.ADDRESS_LINE3, a.ADDRESS_LINE4, '', a.POSTCODE, c.PPSN_NO, swr.scv_code
      FROM proposal p, roleonproposal rop, client c, address a, scv_wn_roles swr
      WHERE p.proposal_id = p_proposal_id
      AND p.proposal_id = rop.proposal_id
      AND rop.ROLE_ID <> v_Role
      AND rop.CLIENT_ID = c.CLIENT_ID
      AND c.CLIENT_ID = a.CLIENT_ID
      AND p.PROPOSAL_ID = a.PROPOSAL_ID
      AND rop.role_id = swr.id
      AND p.company_id = swr.company_id;

被截断的列是表 scv_wn_roles 中的 swr.scv_code。可能的值为 ('WL1','WL2','WG','WB','WD','WP','WT','WE') 但有时插入的只是 W。

然后我按如下方式遍历光标:

FOR c_client IN cur_clients LOOP

将角色插入为 W 的表在这里:

INSERT INTO scv_policy_client_lookup spc
   (spc.policy_number, spc.system_client_id, spc.qsclient_id, spc.role_id)
VALUES
   (c_client.proposal_id, c_client.client_id, v_QS_id, c_client.scv_code);

两个表的结构如下:

create table SCV_WN_ROLES
(
  ID              NUMBER(10) not null,
  REF_DESCRIPTION VARCHAR2(50),
  COMPANY_ID      NUMBER not null,
  SCV_CODE        CHAR(3)
);

和,

create table SCV_POLICY_CLIENT_LOOKUP
(
  POLICY_NUMBER    VARCHAR2(42) not null,
  SYSTEM_CLIENT_ID VARCHAR2(51) not null,
  QSCLIENT_ID      NUMBER(38,10) not null,
  ROLE_ID          VARCHAR2(4) not null,
  COUNTRY_IND      VARCHAR2(1) default 'R'
)

列 swr.scv_code 被插入到存储过程中的其他表中,它在它们中工作正常,只是这个查找表。

我尝试将光标值 c_client.scv_code 移动到 VARCHAR2(3) 的局部变量中,然后将其写入查找表,但这也并不总是有效。

如果这很重要,我们将使用 Oracle 11g。

有人发现任何可疑之处吗?

谢谢你的帮助,麦奎姆

4

1 回答 1

0

I figured it out and thankfully it wasn't related to the above code, thought I was going mad..

We have a nightly batch job that runs on IBM Datastage & Qualitystage and it assigns unique QS Client id's. The bad design of this batch job meant that it was reading the entire contents of this table into a temporary dataset and then writing it all back out again with new QS ID's.

The issue is the the temporary dataset only allows 1 character for the role ID and thus truncating the above roles.

The inserting above is actually fine but its the overnight Datastage job that causes the issues.

Thanks again for anyone who looked.

于 2013-04-30T21:00:27.697 回答