Having problem in comparing dates

This is the select statement I run in toad
SELECT CASE WHEN l1 = l2 THEN 'same date' ELSE ' diff date' END AS mydatediff
FROM (SELECT TO_DATE ('2010/03', 'RRRR/MM') l1,
TO_DATE ('201003', 'RRRRMM') l2
FROM DUAL);
Works fine and get results as expected.
For this I have created a function
CREATE OR REPLACE FUNCTION get_same_diff_dat_fun (p_date1 in Varchar2
,p_Date2 in Varchar2)RETURN VARCHAR IS
tmpVar VARCHAR2(25);
Cursor C1 is SELECT CASE WHEN p_date1 = p_date2 THEN 'same date' ELSE ' diff date' END as tmpVar
FROM (SELECT TO_DATE (p_date1, 'RRRR/MM') ,
TO_DATE (p_Date2, 'RRRRMM')
FROM DUAL);
Begin
tmpVar := null;
Open C1;
Fetch C1 into tmpVar;
Close C1;
RETURN tmpVar;
EXCEPTION
WHEN NO_DATA_FOUND THEN
NULL;
WHEN OTHERS THEN
-- Consider logging the error and then re-raise
RAISE;
END get_same_diff_dat_fun;
Function works fine when I run in toad
select get_same_diff_dat_fun(to_date('2010/03','RRRR/MM'),to_date('201003','RRRRMM')) from dual
In the form I need to use this to compare the fields
Form filed is exp_date with date datatype
I have exp_date in the table called supplies_receiving. In the database it is defined as date.
In the form I have the field as date in format RRRRMM
I and not getting results. I have error message and its not even going to the error. When I type in date as 201003
the cursor comes back to the filed and stops. What is th reason. I need to solve this. Any help is appreciated.

First of all, you are doing a TO_DATE() on a date passed in. You should ONLY use TO_DATE on a text field, never on a date.
Second, why are you using a Select from Dual? You can simply do a PL/SQL date comparison, without the overhead of asking the Oracle database to do it.
And what is the RETURN VARCHAR?   Change it to RETURN VARCHAR2
And this is all you need. Note the Trunc(...'MM') functions. It removes any time element and day-of-month element from the input date parameters, so you effectively are only comparing month and year in the two dates. I am assuming that is what you want to do, since you are using the YYYYMM format everywhere.
<pre><font face = "Lucida Console, Courier New, Courier, Fixed" size = "1" color = "navy">CREATE OR REPLACE FUNCTION get_same_diff_dat_fun
(p_date1 in Varchar2,
p_Date2 in Varchar2)
RETURN VARCHAR2 is
Begin
If trunc(p_date1,'MM')
= trunc(p_date2,'MM') then
Return 'same date';
Else
Return 'diff date';
End if;
End;</font></pre>
/

Similar Messages

  • Having problem with storing data in array

    Hi,
    I'm having problem on storing data in array. My problem is that each time it loops, the array just keep overwrite instead save to the next index. Like at 0 the value is 123, and 1 is 234. But i having that all data capture all overwrite at 0 till the last data it still show at 0. How do i correct this problem?
    Solved!
    Go to Solution.

    How to use array to do comparison? Like Array 1 go thru array 2 to get data Loss out and build an array. Like Array 1 ,1000,1024,1048,etc before 1520 fall in between Array 2 range 1000-1500. So Freq 1000,1024,1048 etc will get Loss value as 1 and 1520 fall in between 1500-2000 will output Loss 2. and so on till the end of the list. How should do this? Need help on this.
    Array 1                                                Array 2
    Freq                                              ​     Freq   Loss
    1000                                              ​    1000      1
    1024                                              ​    1500      2
    1048                                              ​    2000      3
    1100                                              ​     :
    1200                                              ​     :
    :                                                 ​        18000
    1520
    18000

  • Is anyone else having problems with Apertures Date fields?

    After experiencing a sysems failure I began restoring my images from backups.  I have had no end of problems with Image dates.  I have come to the determination that Aperture is NOT using either the "Create Date" or "DateTimeOriginal" as the image "Date" or "Date Created" data if other fields have other dates.
    Here is a clip from my image metadata using exiftool:
    File Modification Date/Time     : 2012:09:23 19:53:15-04:00
    File Access Date/Time           : 2013:01:16 11:34:38-05:00
    File Inode Change Date/Time     : 2013:01:16 11:31:32-05:00
    Create Date                          : 2006:02:20 11:51:12.10
    Date/Time Original              : 2006:02:20 16:51:12.10
    Modify Date                          : 2006:02:20 11:51:12.10
    And here is what Aperture utilized on import
    Date:                               9/23/12 7:53:15 PM EDT
    Date Created                         9/23/2012 7:53:15 PM
    So Aperture utlized the File Modification Date/Time as the Create Date despite that the fact that the Create Date field is present and is properly formatted in the original image.
    According to the Aperture mapping table, this shouldn't be happening.
    Now, before someone recommends that I use Aperture's Date Adjust utility - I'm talking about  slightly over 30,000 images.  Editing images one at a time, or in blocks when you don't know what field Aperture is using as the Create Date would require individual inspection of each image followed by manual adjustment of each image.  That approach isn't acceptable.

    Hmm ok, let me restate the issue then, I thought I was clear.  I could have pointed out in my original post however, that only the EXIF and IPTC date fields were displayed from the metadata dump.
    The data set presented in my first post is the EXIF dataset from the file which clearly shows the image was captured by digital camera at
    Create Date                          : 2006:02:20 11:51:12.10
    Date/Time Original              : 2006:02:20 16:51:12.10
    (The delta of 5 hours is the result of Zulu versus local time offset)
    But, when I ingested it into Aperture, the import routine utilized the IPTC field
    File Modification Date/Time     : 2012:09:23 19:53:15-04:00
    which is updated by the OS whenever you move the file around outside of Aperture. (a number of image data fields are updated by the OS - filename for example is another.).  This resulted in the image date fields being stamped in Aperture as:
    Date:                               9/23/12 7:53:15 PM EDT
    Date Created                         9/23/2012 7:53:15 PM
    Which obviously came form the File Modification Date/Time field and not (either) the Create Date or Date/Time Original fields.

  • Problem with Comparing Dates in MS Access

    Hai Friends
    I am using MS ACCESS 2000 Database
    I am using the following sqlString in AWT Frame class to fetch the date from MS ACcess Database
    I heard that while comparing with >= or <= we need to include # symbol between the date.
    I was tried by using #. But i am not able to get the results.
    please see the sql query and give me the solution.
    Thanksinadvance
    Yours
    Rajesh
    if(Enddate.getText().trim().equals(""))
    sqlString = "select * from data_comm_err where log_date >= '" + Startdate.getText() + "'";
    if(Startdate.getText().trim().equals(""))
    sqlString = "select * from data_comm_err where log_date <= '" + Enddate.getText() + "'";
    }

    non-proprietary query(portable):
    PreparedStatement ps = con.prepareStatement("select * from data_comm_err where log_date <= ? ");
    ps.setDate(1,new java.sql.Date(Startdate.getTime()));
    ResultSet r  = ps.executeQuery();
    ....note: for clarity and good programming style, don't capitalize the first letter of a variable(Startdate)
    Jamie

  • SQL: Having problems passing a date value to dynamic SQL

    SQL Version 2008 (not R2)
    Problem:  1)  I'm getting the following error message when trying to run the sql code below.
    SQL "Messages" Returned when running code:
    Msg 206, Level 16,
    State 2, Procedure uspxc_WAWP_10_Get_VPData, Line 0
    Operand type clash: int is incompatible with date
    Loaded VP DATA for Month: 20121201
    Problem Code Line: 
    SET @dynamicSQL = 'EXEC ' + @StoredProcedureName + ' ' + @DEVModeYN + ', ' + CAST(@WIPMonth as varchar);
    Any help would be greatly appreciated.  I've spent several hours trying to get around this error.
    Full Code:
    ALTER PROCEDURE [dbo].[uspxi_XIUD_98_DataConversionGET_VP_WIPJobHistory] (@DEVModeYN nchar(1) = 'D', @WIPMonth Date)
    AS
    BEGIN 
     SET NOCOUNT ON;
     DECLARE @returnCode AS INT ,
       @dynamicSQL AS VARCHAR(8000),
       @msg as varchar(60),
       @DEVModeYN nchar(1) = 'D',
       @WIPMonth date = '20121201',
       @StoredProcedureName AS VARCHAR(60)
     SET @returnCode = 0
     SET @StoredProcedureName = 'uspxc_WAWP_10_Get_VPData'
    -- Check to see if @StoredProcedureName exists in the database.
    IF EXISTS(SELECT name FROM sys.procedures WHERE name = @StoredProcedureName)
     BEGIN 
      -- RUN SP to Import VP Data for each WIPMonth parameter value
      SET @dynamicSQL = 'EXEC ' + @StoredProcedureName + ' ' + @DEVModeYN + ', ' + CAST(@WIPMonth as varchar);
      SELECT @dynamicSQL;
      -- RUN stored procedure for WIP Month
      EXEC (@dynamicSQL);
      SET @returnCode = 0;
      SELECT @returnCode;
      SET @msg = 'Loaded VP DATA for Month: ' + @WIPMonth;
      PRINT @msg;
      GoTo SPEND
     END 
     ELSE
      SET @returnCode = 1;
      SET @msg = 'NO DATA IMPORTED for Month: ' + CAST(@WIPMonth as varchar(10))
      PRINT @msg
    SPEND:
    END
    Bob Sutor

    When you work with dynamic SQL, you should never build a full SQL string by concatenating values, because this is more difficult to get right and also has problems with SQL injection and efficient use of the SQL Server cache.
    So the correct way to do this in dynamic SQL would be:
    SET @dynamicSQL = 'EXEC ' + quotename(@StoredProcedureName)  '@DEVModeYN, @WIPMonth';
    EXEC sp_executesql @SQL, N'DEVModeYN nchar(1), @WIPMonth date',
                       @DEVModeYN, @WIPMonth
    A lot easier and cleaner! (Note that the variable @SQL must be declared as nvarchar.)
    ...however, in this particular case, this is still an overkill, and there is no need for dynamic SQL at all. EXEC accepts a variable for the procedure name, so:
    EXEC @StoredProcedureName @DEVModeYN, @WIPMonth
    ...but it does not stop there. You can make all these changes, but you will get the same error. To wit, you get the error on Line 0, which means that it is the call to the procedure that fails. Apparently, you are passing an integer value, when you were
    supposed to pass a date. Maybe you forgot to put the dates in quotes?
    Erland Sommarskog, SQL Server MVP, [email protected]

  • I'm having problems manipulating array data within a for loop, and extracting the required sub-arrays generated.

    Hi,
    I'm using labVIEW V5.1
    I'm trying to generate 10 1D arrays, the first array is initialized to all zeroes, then I have set up a for loop which shifts the first element by 1, then a random number is placed into the first element position. I am using a shift register to feed back in the newly generated array into the start of the loop.
    By the end of the each loop I want to be able to use the array generated in an algorithm outside the loop. However I only want the Nx1 array that has just been generated.
    Unfortunately, I cannot figure out how to resize, reshape or index the output array to do this.
    I would like the loop to
    give me out a 1D array after each iteration.
    Any help would be greatly appreciated.

    I hope I've understood your problem.
    First your vi was lacking of the sub-vi working as shift register, I've replaced it with the rotate function.
    The indexing of your arrays create a 2D array whose rows are your 1D array.To pick only one of them you have to use the index array function and select which one you want.
    To use your temporary data in another part of your application you should use a local variable of array2.
    I did it in a separated while loop That I syncronized with the for loop using occurrence, in this way the while loop runs each time a new value is inserted in array2 (each loop of the for loop structure).
    If you don't need this syncronization just get rid of occurrence functions.
    I place a delay in the for loop to show what happens when running.
    Hope it was helpful.
    Alberto Locatelli
    Attachments:
    array_test_v3.vi ‏35 KB

  • Having problem with accessing data in CRM machine

    Hi,
    I have a search functionality which searches for the records existing depending on the Id number passed... But every time i am trying to execute the BAPI it is giving me an
    "Internal Server Error"  if there are records existing for the given ID number...
    But for any other ID number which does not have any records, the BAPI is executed.. Can anyone help me out with this...

    hi,
    Quite literally an "Internal Server Error" is an error on the server that you're trying to access. That server is misconfigured in some way that is preventing it from responding properly to what you're asking for.
    sometime it may arise due to cache, but i am not sure about your case.
    try accessing bapi from r/3 for both the condition, if it gets executed well then it is some server error or cache error
    hope it helps
    regards

  • Problem with Java Dates and UPDATE for SQL2000

    I am having problems with the date formats for Java. I am trying to put the current date time into a SQL table, here it the code I am using:
    var Today = new Date()
    var conn = Server.CreateObject( "ADODB.Connection" )
    conn.Open( "Provider=SQLOLEDB;Server=(local);Database=BillTracking;UID=sa;PWD=;")
    var sql = "UPDATE BillAssignments SET DatePosted = " + Today + " WHERE AssignmentID = '" + Request.QueryString("AssignmentID") + "'"
    var rs = conn.execute(sql)
    I keep getting different errors and I have been unable to find a solution yet. I know that I need to change the date format from the Java standard to the one that SQL likes.
    Help....
    Norm...

    Please tell us where the Java part of this comes in. I see that you are using JavaScript to load up data via an ADO connection (presumably on an IIS platform) - but I do not see where you are using Java
    Lee

  • XML..: Problem getting the data in the XML-file..

    I'm developing a flash-file for my customer to use when
    displaying list of products he's selling.
    His list of products is inside a XML-file and he want me to
    display an overview of the products inside a datagrid, so when you
    click on the product you're interested in the productinfo will be
    displayed.
    But.. I'm having problems grabbing the data I want as it
    seems to me that I have to use the unik ID's for each products to
    get the data I want. I've tried adding the unik ID-code to my
    action script but it still won't work.
    Here's a part of the XML-code:
    <Tooldata>
    <Store name="N/A" zipcode="0033450" city="N/A" url="N/A"
    phone="N/A" fax="N/A" email="N/A">
    <Tool unikID="5_0022" control="14" cmnd="update">
    <Toolgroupe>Hammer</Toolgroupe>
    <Brand>Knipps</Brand>
    <Model>K55_Knipps</Model>
    <Price>35€</Price>
    <Weight>N/A</Weight>
    <Soldout>0</Soldout>
    <Color>Red/Black</Color>
    <Images>
    <Images image="5_0022.jpg" prioritet="1" gen_id="16"
    desc="MainImage"/>
    <Images image="5_0022_1.jpg" prioritet="2" gen_id="16"
    desc="Image 1"/>
    <Images image="5_0022_2.jpg" prioritet="3" gen_id="16"
    desc="Image 2"/>
    <Images image="5_0022_3.jpg" prioritet="4" gen_id="16"
    desc="Image 3"/>
    </Images>
    Now, the code above is only one item/product. But there are
    several proucts listed in the XML-file and I find it hard to get
    the product and the product info that I want to be displayed.
    Here's my action script:
    var xmlLoader:URLLoader = new URLLoader();
    var xmlData:XML = new XML();
    xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
    xmlLoader.load(new URLRequest("ToolData.xml"));
    function LoadXML(e:Event):void {
    xmlData = new XML(e.target.data);
    ParseBildata(xmlData);
    function ParseTooldata(TooldataInput:XML):void {
    trace("XML Output");
    trace("------------------------");
    trace(TooldataInput.Store);
    If I want to trace the images I just write
    "trace(TooldataInput.Store.Images);
    But if I want to trace one unik tool it's impossible. Well,
    maybe not impossible.. I just don't know how to do just that.
    When you trace (TooldataInput.Store); you get all the tools
    at that store. But how do I trace only one tool using the unikID??
    Thanks a lot in advance!

    Ace,
    When using E4X if you have multiple nodes at the same level
    you should be able to access them as an XMLList. Looking at your
    XML you should be able to access each <Tool> node as:
    TooldataInput.Store.Tool[0];
    TooldataInput.Store.Tool[1];
    or as an entire list
    TooldataInput.Store.children()
    WL

  • Problem in uploading data to psa.

    Hi experts,
    im having problems in uploading data to psa using info package in HR info area.
    while monitoring the info package the following error comes with red traffic signal..
    Request still running
    Diagnosis
    No errors found. The current process has probably not finished yet.
    System Response
    The ALE inbox of BI is identical to the ALE outbox of the source system
    or
    the maximum wait time for this request has not yet been exceeded
    or
    the background job has not yet finished in the source system.
    Current status
    No Idocs arrived from the source system.
    So , please help me in this regard...
    waiting for your reply...

    Hi,
    You may need to check for pending TRFCs/IDOCs in source system in Tcode SM58 and BD87 and process them manually.
    ProcessI DOCS Manually 
    http://help.sap.com/saphelp_nw04s/helpdata/en/0b/2a6620507d11d18ee90000e8366fc2/frameset.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/dc/6b815e43d711d1893e0000e8323c4f/content.htm
    &messageID=2311994
    Thanks,
    JituK

  • Problem in Loading data for clob column using sql ldr

    Hi,
    I am having problem in loading data for tables having clob column.
    Could anyone help me in correcting the below script for ctrl file inorder to load the data which is in mentioned format.
    Any help really appreciated.
    Table Script
    Create table samp
    no number,
    col1 clob,
    col2 clob
    Ctrl File
    options (skip =1)
    load data
    infile 'c:\1.csv'
    Replace into table samp
    fields terminated by ","
    trailing nullcols
    no,
    col1 Char(100000000) ,
    col2 Char(100000000) enclosed by '"' and '"'
    Data File(1.csv)
    1,asdf,"assasadsdsdsd""sfasdfadf""sdsdsa,ssfsf"
    2,sfjass,"dksadk,kd,ss""dfdfjkdjfdk""sasfjaslaljs"
    Error Encountered
    ORA-01461: can bind a LONG value only for insert into a LONG column
    Table sampThanks in advance

    I can't reproduce it on my 10.2.0.4.0. CTL file:
    load data
    INFILE *
    Replace into table samp
    fields terminated by ","
    trailing nullcols
    no,
    col1 Char(100000000) ,
    col2 Char(100000000) enclosed by '"' and '"'
    BEGINDATA
    1,asdf,"assasadsdsdsd""sfasdfadf""sdsdsa,ssfsf"
    2,sfjass,"dksadk,kd,ss""dfdfjkdjfdk""sasfjaslaljs"Loading:
    SQL> Create table samp
      2  (
      3  no number,
      4  col1 clob,
      5  col2 clob
      6  );
    Table created.
    SQL> host sqlldr scott/tiger control=c:\temp\samp.ctl log=c:\temp\samp.log
    SQL> select * from samp
      2  /
            NO
    COL1
    COL2
             1
    asdf
    assasadsdsdsd"sfasdfadf"sdsdsa,ssfsf
             2
    sfjass
    dksadk,kd,ss"dfdfjkdjfdk"sasfjaslaljs
            NO
    COL1
    COL2
    SQL> SY.

  • Problems to create data control in JDeveloper 11g

    Hi everybody , I´m having problems to use Data Control in Jdev 11 , I create an jpa , and with my entities I create the data control component , but when I try to create a JSF page I can´t use data control, where is data control component palette ?

    Please post JDev 11 questions on the JDev 11 forum
    JDeveloper and OC4J 11g Technology Preview
    Follow this tutorial to see the data control palette for EJB/JPA
    http://www.oracle.com/technology/obe/obe11jdev/11/ejb/ejb.html
    Here is how it will look like:
    http://www.oracle.com/technology/obe/obe11jdev/11/ejb/images/t50105.gif

  • Problems adding Bridge Data to prepaid (Allset) iPhone5

    Anyone having problems trying to add bridge data to a prepaid (Allset) phone. I've tried to add 3GB to my iPhone 5 all day today and I've had no success. I've tried doing through (1) the new My Verizon Mobile App, (2) dialing *611 and following the prompts and (3) on my PC while logged into my "My Verizon" account. All three methods result in a "system error" and I can't add any bridge data. The only thing that worked, was it allowed me to put $25 on account by charging my credit card. So now I've been taken for $25 and can't do anything with the money on now have in my account. A call to customer service was a complete waste of time. The CSR told me to do the *228 Activation code on my 4G LTE iPhone 5. I'm not a CSR and I know you don't use *228 on an a 4G iPhone! After wasting 30 minutes and being told my SIM card "had to age" (very creative), I got tired of the snow job and hung up. Is anyone else having problems adding bridge data? Please advise if you have succeeded in adding bridge data today.

    Why have a Prepaid forum that is not monitored by CSR's who can actually do something about the issues posted by Prepaid customers? I'm not looking for a "sorry to hear about your problem" reply, I'm looking for answers/solutions. 
    What a ridiculous arrangement. This Prepaid sub-forum should be deleted so customers don't waste their time posting problems here.
    Sent from my iPad

  • Problem extracting LIS data

    Hi,
    We are having problem extracting LIS data.
    I have cheked the delta queue (RSA7), and 2LIS_13_VDITM has total 0.
    I have also checked transaction LBWQ, and can see that the MCEX13 has got 150028 entries and MCEX11 has got 12811 entries in the queue. It has destination NONE and status NOSEND.
    What can I do to transfer all these entries to the delta queue so that they can be loaded to BW?
    BR,
    Linda

    Hi Linda,
    search form RMBWV in the ABAP input box (job name = *, user = *)
    goto SMQ1 in the source system; you'll see LUWs for the MCEX* queue.
    in this tran you also see your BW delta queue; do you see LUWs as well for your datasource?
    you can schedule the update job via LBWE / job control; once executed, the LUWs for  MCEX* should decrease and your BW LUWs should incerease...
    let us know
    hope this helps
    Olivier.
    Message was edited by:
            Olivier Cora

  • I have iPod touch 5 and having problems

    I have iPod touch 5 and having problems with charging(data cable is ok), when I have contacted support in my country, they would like to have recieve and warranty letter that I do not have. What should I do?

    Unfortunately I am not in US(.
    Ukrainian Apple Authorized Service Provider tells me to bring it, but iPod was purchased in US)

Maybe you are looking for