Pregunta

I have a cursor in an oracle stored procedure that randomly truncates the value in one of the returned columns.

I cannot see any pattern to this, sometimes it works other times it just truncates the value to 1 char long.

This is the cursor:

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;

The column that is being truncated is swr.scv_code from the table scv_wn_roles. It's possible values are ('WL1','WL2','WG','WB','WD','WP','WT','WE') but what gets inserted sometimes is just the W.

I then loop through the cursor as follows:

FOR c_client IN cur_clients LOOP

And the table where the role is being inserted as W is here:

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

The structure of the two tables are as follows:

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

And,

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'
)

The column swr.scv_code is inserted into other tables within the stored procedure and it works fine in them, just this lookup table.

I tried moving the cursor value c_client.scv_code into a local variable of VARCHAR2(3) and then writing this to the lookup table but this does not always work either.

We are on Oracle 11g if that matters.

Anyone spot anything suspect?

Thanks for the help, mcquaim

¿Fue útil?

Solución

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top