Solved

Oracle Date Time Conversion

Posted on 2011-03-22
16
536 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 53

Expert Comment

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

   ORDER BY start_date_time;
0
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 

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 53

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 53

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 53

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

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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Oracle cursor lifecycle inside procedure. 2 40
Oracle Nested table uses ? 2 60
pl/sql parameter is null sometimes 2 39
how to tune the query 17 87
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…
Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

752 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