473,582 Members | 3,083 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

null data from bind variable on table insert

4 New Member
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 6266
amitpatel66
2,367 Recognized Expert Top Contributor
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
pretzla
4 New Member
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
t3chn0n3rd
19 New Member
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 Recognized Expert Top Contributor
Are you sure the value of the acct_btn retunred by the procedure btn_sp is NOT NUL??
Jan 7 '08 #5
pretzla
4 New Member
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
pretzla
4 New Member
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
5981
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
8773
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 (i.e. a zero length string). We are using SQLBindParameter() to bind a variable to the parameterized insert statement <<in the form: INSERT INTO...
5
50633
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 table, reCREATEing the table without the 'NOT NULL property, reCREATEing the INDEXes, reloading the data, redefining all of DROPped constraints...
2
6537
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 *that is going to be deleted* into another table, before the original data is deleted. I am trying to use the RowDeleting method to call an Update...
6
12985
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 statement to c_NullDate, the insert statement works. When I re-read the row and display the inserted date value in a text box, the string...
5
6399
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 problems with DropDownLists because there is no value to bind to and an eror is raised. I considered a method whereby the DropDownList has a an...
2
8608
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 customer complaints table and one of the fields on the DetailsView control is called ComplaintType. The field is a template field and in insert mode and...
6
3699
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 code looks like this: private void Fill() { DataTable table = new DataTable(); SqlDataAdapter adapter = new SqlDataAdapter("SELECT * from
4
2889
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 is not a null value. I am not using any code behind (C#) to bind the data or manipulate the data. I have read that when there is a null value in...
0
7886
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7809
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8159
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8312
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
8183
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5685
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3835
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2312
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1147
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.