Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Oracle Date Time Conversion

Posted on 2011-03-22
16
Medium Priority
?
538 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 59

Expert Comment

by:HainKurt
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 59

Expert Comment

by:HainKurt
ID: 35193576
try adding some size

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

Accepted Solution

by:
slightwv (䄆 Netminder) earned 2000 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 59

Expert Comment

by:HainKurt
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 59

Expert Comment

by:HainKurt
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

Industry Leaders: 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

Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
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…
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 shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…

722 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