Solved

Oracle Date Time Conversion

Posted on 2011-03-22
16
535 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 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 35193534
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
ID: 35193541
calling with C#.  
0
 
LVL 51

Expert Comment

by:Huseyin KAHRAMAN
ID: 35193558
I guess you dont need this line

   ORDER BY start_date_time;
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:jmpatton
ID: 35193568
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 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 35193569
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:Huseyin KAHRAMAN
ID: 35193576
try adding some size

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

Accepted Solution

by:
slightwv (䄆 Netminder) earned 500 total points
ID: 35193580
>>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
ID: 35193596
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
 
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 35193614
>>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
ID: 35193617
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:Huseyin KAHRAMAN
ID: 35193626
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 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 35193640
>>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 74

Expert Comment

by:sdstuber
ID: 35194040
>>>  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
ID: 35199498
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 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 35199538
>>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:Huseyin KAHRAMAN
ID: 35200209
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to free up undo space? 3 61
clob to char in oracle 3 89
Using SQL*PLUS issue with where statement with trunc function 3 34
pl/sql parameter is null sometimes 2 23
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…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

685 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