473,403 Members | 2,284 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

null data from bind variable on table insert

I have a PL/SQL script where I load data from a stored procedure into bind variables. Then, I insert that data from the bind variables into an Oracle table with a simple insert statement.

The execution of the stored procedure and the insert are in a FOR-LOOP.

Expand|Select|Wrap|Line Numbers
  1. insert into ccd_t
  2. (acct_id,
  3. acct_seq_no,
  4. acct_btn)
  5. values
  6. (to_number(v_acct_id),
  7.  to_number(v_acct_seq_no),
  8.  substr(v_acct_btn,1,10)
  9. )
  10.  
After exiting the for-loop, I do a commit. Everything works great unless there is an exception. When an exception occurs (unless it is ORACLE not available) the rows get inserted, but the v_acct_btn is NULL.

There is a WHEN OTHERS for exception processing that prints out the error.

I am thinking the acct_id and acct_seq_no are inserting valid values because of the conversion function, to_number. Since substr is a character function, the v_acct_btn is not dynamic?

Does that make sense? Can anyone verify my conclusion?

The stored procedure always returns an acct_btn, not NULLs so it is not from the stored procedure. Acct_id and acct_seq_no always return numbers.

Or is there some other reason for this odd behavior?

field: acct_id number(10)
field acct_seq_no number(3)
field: acct_btn varchar2(10)
field: v_acct_id varchar2(10);
field: v_acct_seq_no varchar2(3);
field: v_acct_btn varchar2(20);

Thanks.
Jan 3 '08 #1
6 6253
amitpatel66
2,367 Expert 2GB
I have a PL/SQL script where I load data from a stored procedure into bind variables. Then, I insert that data from the bind variables into an Oracle table with a simple insert statement.

The execution of the stored procedure and the insert are in a FOR-LOOP.

Expand|Select|Wrap|Line Numbers
  1. insert into ccd_t
  2. (acct_id,
  3. acct_seq_no,
  4. acct_btn)
  5. values
  6. (to_number(v_acct_id),
  7.  to_number(v_acct_seq_no),
  8.  substr(v_acct_btn,1,10)
  9. )
  10.  
After exiting the for-loop, I do a commit. Everything works great unless there is an exception. When an exception occurs (unless it is ORACLE not available) the rows get inserted, but the v_acct_btn is NULL.

There is a WHEN OTHERS for exception processing that prints out the error.

I am thinking the acct_id and acct_seq_no are inserting valid values because of the conversion function, to_number. Since substr is a character function, the v_acct_btn is not dynamic?

Does that make sense? Can anyone verify my conclusion?

The stored procedure always returns an acct_btn, not NULLs so it is not from the stored procedure. Acct_id and acct_seq_no always return numbers.

Or is there some other reason for this odd behavior?

field: acct_id number(10)
field acct_seq_no number(3)
field: acct_btn varchar2(10)
field: v_acct_id varchar2(10);
field: v_acct_seq_no varchar2(3);
field: v_acct_btn varchar2(20);

Thanks.
Could you please post the error that thrown?
I am not able to make it from your explanation to what exactly is your problem. And also post the full procedure for my reference!!
Jan 4 '08 #2
Could you please post the error that thrown?
I am not able to make it from your explanation to what exactly is your problem. And also post the full procedure for my reference!!
I will do so.
The exact problem is that rows get inserted with a valid acct_id, but an acct_btn with NULL values when an Exception occurs.

Here is one error that was thrown. I am not worried about the exact error. I know what is causing it. I am questioning why rows still get inserted, but with an acct_btn that is nulls and the acct_id is not nulls. acct_btn is not nulls coming from the stored procedure (btn_sp).

[ERROR]
Unknown Failure - SQLERRM: ORA-02068: following severe error from
tstdb
ORA-03113: end-of-file on communication channel
DECLARE
*
ERROR at line 1
[/ERROR]

Expand|Select|Wrap|Line Numbers
  1. WHENEVER SQLERROR EXIT SQL.SQLCODE;
  2. SET SERVEROUTPUT ON SIZE 200000;
  3. SET ECHO OFF
  4. SET TIME ON
  5. SET TIMI ON
  6. SET FEEDBACK ON
  7. ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD:HH24:MI:SS';
  8. DECLARE
  9.   l_acct_not_found  NUMBER;
  10.   v_lookup_cnt          NUMBER;
  11.   v_acct_id             VARCHAR2(20); 
  12.   v_acct_seq_no         VARCHAR2(20);
  13.   v_btn          VARCHAR2(20);
  14.  
  15.  
  16.   CURSOR dss_cur IS 
  17.    SELECT SUBSTR(etn,1,20) AS etn
  18.         , SUBSTR(btn,1,20) as btn 
  19.      FROM ccd_hst
  20.   GROUP BY SUBSTR(etn,1,20), SUBSTR(btn,1,20);
  21.  
  22.   dss_rec   dss_cur%rowtype;
  23. BEGIN
  24.  
  25.   FOR dss_rec IN dss_cur LOOP
  26.      btn_sp(dss_rec.etn
  27.                  , dss_rec.btn
  28.                  , v_acct_id
  29.                  , v_acct_seq_no
  30.                  , v_btn
  31.                  );
  32.  
  33.    IF v_acct_id = '9999999999' THEN
  34.      l_acct_not_found := l_acct_not_found + 1;
  35.    ELSE    
  36.        INSERT INTO cct_t
  37.             ( acct_dim_id
  38.             , c_id
  39.            , acct_id
  40.             , acct_seq_no
  41.             , acct_btn
  42.             , insdate )
  43.        VALUES    
  44.             ( cct_t.NEXTVAL
  45.             , NULL
  46.             , TO_NUMBER(v_acct_id)
  47.             , TO_NUMBER(v_acct_seq_no)
  48.             , SUBSTR(v_btn,1,10)
  49.             , SYSDATE );
  50.  
  51.    END IF;
  52.  
  53.  END LOOP;
  54.  COMMIT;
  55.  
  56. EXCEPTION
  57.   WHEN OTHERS THEN
  58.     DBMS_OUTPUT.PUT_LINE('Unknown Failure - SQLERRM: '||SQLERRM);
  59.     RAISE;
  60. END;
  61.  
  62.  
Jan 4 '08 #3
Expand|Select|Wrap|Line Numbers
  1.  
  2. INSERT INTO ccd_t
  3. (acct_id,
  4. acct_seq_no,
  5. acct_btn)
  6. VALUES
  7. (TO_NUMBER(v_acct_id),
  8.  TO_NUMBER(v_acct_seq_no),
  9.  SUBSTR(v_acct_btn,1,10)
  10. )
  11.  
  12.  
Jan 5 '08 #4
amitpatel66
2,367 Expert 2GB
Are you sure the value of the acct_btn retunred by the procedure btn_sp is NOT NUL??
Jan 7 '08 #5
Are you sure the value of the acct_btn retunred by the procedure btn_sp is NOT NUL??
I am absolutely sure that the acct_btn is never returned NULL. I have tested this procedure for over 1.5 million executions consecutively without ever returning a NULL. Moreover, there are no acct_btn with the value of NULL on the originating table.
Jan 15 '08 #6
Expand|Select|Wrap|Line Numbers
  1.  
  2. INSERT INTO ccd_t
  3. (acct_id,
  4. acct_seq_no,
  5. acct_btn)
  6. VALUES
  7. (TO_NUMBER(v_acct_id),
  8.  TO_NUMBER(v_acct_seq_no),
  9.  SUBSTR(v_acct_btn,1,10)
  10. )
  11.  
  12.  
I am unsure what your post meant. Are you verifying that the problem is because the v_acct_id has a conversion function, and v_acct_btn has a character function? Can you direct me to some documentation, or provide an explanation?

Thanks.
Jan 15 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Chris | last post by:
I have tableA, defined as: field1 varchar2(10), field2 varchar2(10), field3 varchar2(10) I have host variables defined as: v1 pic x(10) varying v2 pic x(10) varying
2
by: FizzBin | last post by:
We are writing a C application that is using ODBC to insert records into a database. We have a NOT NULL column that can legitimately have an empty value, i.e. we know the value and it is empty...
5
by: Robert Stearns | last post by:
Either I missed something, or ALTER TABLE does not have this capability. Is there any way of doing it except DROPping all constraints which mention this table, EXPORTing the data, DROPping the...
2
by: Robert Smith jr. | last post by:
Hello, Please pardon my newbie question ... I am building an ASP.NET page that displays a recordset with a Delete statement enabled (this all works fine). I want to Insert the current row...
6
by: Dean Slindee | last post by:
I am looking for the "right" way to handle inserting and presenting null date values. Public Const c_NullDate As Date = #12:00:00 AM# If I set the value of a date variable in an SQL Server insert...
5
by: Neil | last post by:
I'd like to know what the best method is for handling NULL (or 0) values within a DropDownList. If a database lookup value is optional I would normally consider leaving it NULL but this leads to...
2
by: clickon | last post by:
I am using ASP.net 2.0 and trying to take advantage of the updated data editing facilities provided through the SQLDataSource control and the DetailsView control. The data is a record from a...
6
by: rcoco | last post by:
Hi, I have a datagrid that is ment to insert data. But when I run the form only the header appears. I would like some advise from you all and solve this problem I'm using visual studio 2003. My...
4
by: justice750 | last post by:
Hi All, I am using a FormView control. The allows me to update records in the database. However, when a database field is null I can not update the field on the form. It works fine when the field...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.