Solved

Oracle Date Time Conversion

Posted on 2011-03-22
16
530 Views
Last Modified: 2012-05-11
Im sending a string onto my oracle stored procedure, however when I attempt to convert it to a Date and perform some operation on it I get 'numeric or value error: character string buffer too small'.  I have verified that the format im sending in is correct.
 (3/28/2011 3:33:15 PM), but when I try to convert using
to_date(pFinishDateTime,'mm/dd/yyyy hh:mi:ss am') I get the error.  
create or replace
PROCEDURE GET_CONFLICT_VOLUME 
(pJunction IN VARCHAR2,
pPipeline IN VARCHAR2,
pBatchCode IN VARCHAR2,
pStartDateTime  IN VARCHAR2,
pFinishDateTime IN VARCHAR2,
pConflictVolume OUT VARCHAR2) AS
BEGIN
  
  SELECT round(sum(rate * ((to_date(pFinishDateTime,'mm/dd/yyyy hh:mi:ss am') - to_date(pStartDateTime,'mm/dd/yyyy hh:mi:ss am'))* 24))) into pConflictVolume 
     FROM schedule_events
     WHERE rate > 0  AND
     shipper || '-' || product || '-' || cycle || phase = pBatchCode
     AND junction = 'xxx'
     AND pipeline = 'xxx'
     AND STATION = '000'
    ORDER BY start_date_time;

END GET_CONFLICT_VOLUME;

Open in new window

0
Comment
Question by:jmpatton
  • 6
  • 5
  • 4
  • +1
16 Comments
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
Comment Utility
What are you calling the procedure with?  make sure the receiving variable is large enough to hold the results from the procedure.
0
 

Author Comment

by:jmpatton
Comment Utility
calling with C#.  
0
 
LVL 51

Expert Comment

by:HainKurt
Comment Utility
I guess you dont need this line

   ORDER BY start_date_time;
0
 

Author Comment

by:jmpatton
Comment Utility
If I run a test in PL/SQL Developer it will work if I dont have the 'AM or PM' at the end of the date string
0
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
Comment Utility
What does your C# parameter declaration look like?  Does it have room for possible 4000 characters?

Can you call the procedure from sqlplus?

I'm trying to make sure it is the actual procedure itself 'causing' the problem and not just 'reporting' the problem.
0
 
LVL 51

Expert Comment

by:HainKurt
Comment Utility
try adding some size

   pStartDateTime    IN     VARCHAR2(22),
   pFinishDateTime   IN     VARCHAR2(22),
0
 
LVL 76

Accepted Solution

by:
slightwv (䄆 Netminder) earned 500 total points
Comment Utility
>>If I run a test in PL/SQL Developer it will work

Then it's a C# output parameter size issue.
0
 

Author Comment

by:jmpatton
Comment Utility
Here is my c# parameter

OracleCommand command = new OracleCommand("GET_CONFLICT_VOLUME", connection);
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.Add("pJunction", OracleDbType.Varchar2).Value = stationPipingjunction;
                command.Parameters.Add("pPipeline", OracleDbType.Varchar2).Value = stationPipingPipeline;
                command.Parameters.Add("pBatchCode", OracleDbType.Varchar2).Value = batchcode;
                command.Parameters.Add("pStartDateTime", OracleDbType.Varchar2).Value = startDateTime;
                command.Parameters.Add("pFinishDateTime", OracleDbType.Varchar2).Value = finishDateTime;
                command.Parameters.Add("pConflictVolume", OracleDbType.Varchar2).Direction = ParameterDirection.Output;
                command.ExecuteNonQuery();

                conflictVolume = command.Parameters["pConflictVolume"].Value.ToString();
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
Comment Utility
>>command.Parameters.Add("pConflictVolume", OracleDbType.Varchar2).Direction = ParameterDirection.Output;


What is the 'default' size for a Varchar2 using MSOfts data provider?

You need to specify a size.  I'm not sure how to do that with that data provider.

I strongly encourage you to migrate over to Oracle's ODP.Net.  It will save you a lot of headaches.
0
 

Author Comment

by:jmpatton
Comment Utility
Well it will work in SQL Developer if I dont have AM/PM at the end of the string.  but Oracle shold be able to accomodate for that shouldnt it?
0
 
LVL 51

Expert Comment

by:HainKurt
Comment Utility
and try cast the rounded value to varchar
CREATE OR REPLACE PROCEDURE GET_CONFLICT_VOLUME (
   pJunction         IN     VARCHAR2,
   pPipeline         IN     VARCHAR2,
   pBatchCode        IN     VARCHAR2,
   pStartDateTime    IN     VARCHAR2 (22),
   pFinishDateTime   IN     VARCHAR2 (22),
   pConflictVolume      OUT VARCHAR2)
AS
BEGIN
   SELECT CAST (
             ROUND (
                SUM (
                   rate
                   * ( (TO_DATE (pFinishDateTime, 'mm/dd/yyyy hh:mi:ss am')
                        - TO_DATE (pStartDateTime, 'mm/dd/yyyy hh:mi:ss am'))
                      * 24))) AS VARCHAR2)
     INTO v_result
     FROM schedule_events
    WHERE     rate > 0
          AND shipper || '-' || product || '-' || cycle || phase = pBatchCode
          AND junction = 'xxx'
          AND pipeline = 'xxx'
          AND STATION = '000';
END GET_CONFLICT_VOLUME;

Open in new window

0
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
Comment Utility
>>but Oracle shold be able to accomodate for that shouldnt it?

Can't speak to that.

This is a guess but try:

command.Parameters.Add("pConflictVolume", OracleDbType.Varchar2,4000).Direction = ParameterDirection.Output;

0
 
LVL 73

Expert Comment

by:sdstuber
Comment Utility
>>>  pStartDateTime    IN     VARCHAR2 (22)  

this is illegal syntax for parameter declaration


>>> INTO v_result

this won't work because v_result isn't declared in your procedure
0
 

Author Comment

by:jmpatton
Comment Utility
Ok, I fixed the date/time error.  but now it is erroring out saying "numeric or value error: character string buffer too small".  So this goes back to the default size of the parameter being returned.  The parameter being returned though would be no longer than 6 characters
0
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
Comment Utility
>>Ok, I fixed the date/time error

There was a date/time error?  Also, 'what' fixed it?

>>but now it is erroring out saying "numeric or value error: character string buffer too small".

Isn't that the original error message from the initial question?
0
 
LVL 51

Expert Comment

by:HainKurt
Comment Utility
did you try this
CREATE OR REPLACE PROCEDURE GET_CONFLICT_VOLUME (
   pJunction         IN     VARCHAR2,
   pPipeline         IN     VARCHAR2,
   pBatchCode        IN     VARCHAR2,
   pStartDateTime    IN     VARCHAR2,
   pFinishDateTime   IN     VARCHAR2,
   pConflictVolume      OUT VARCHAR2
)
AS
BEGIN
   SELECT   CAST (
               ROUND(SUM(rate
                         * ( (TO_DATE (pFinishDateTime,
                                       'mm/dd/yyyy hh:mi:ss am')
                              - TO_DATE (pStartDateTime,
                                         'mm/dd/yyyy hh:mi:ss am'))
                            * 24))) AS VARCHAR2(100)
            )
     INTO   pConflictVolume
     FROM   schedule_events
    WHERE   rate > 0
            AND shipper || '-' || product || '-' || cycle || phase =
                  pBatchCode
            AND junction = 'xxx'
            AND pipeline = 'xxx'
            AND STATION = '000';
END;

Open in new window

0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now