Date Format in SQL*Plus

How can I change SQL*Plus to run the statement:
select * from t_1 where t_1.date_ini = '22-05-2001'
Thank You

I had this problem the other day and with a lot of toll and trouble I figured it out.
select * from dual where to_date(t_1.date_ini,'DD-MM-YYYY') = '22-05-2001'
<BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by Miguel Miqambres ([email protected]):
How can I change SQL*Plus to run the statement:
select * from t_1 where t_1.date_ini = '22-05-2001'
Thank You<HR></BLOCKQUOTE>
null

Similar Messages

  • Date format in SQL statements

    Hi there !
    Please, can anyone help me find out what is going on with date format in my SQL Statements ?
    While in development, the date format in SQL statements were:
    SELECT DATA_FIELD FROM TABLE WHERE DATE_COL = '10-DEC-2004'
    And works fine.
    After deploy to production server, we get ORACLE error: not a valid month
    So we change the format to
    SELECT DATA_FIELD FROM TABLE WHERE DATE_COL = '10/12/2004'
    And it gets to works again.
    Yesterday, the net administrator updated the JAVAC / JSDK run-time with Java update tool, and AGAIN we get ORACLE error: not a valid month
    So we change the format AGAIN to
    SELECT DATA_FIELD FROM TABLE WHERE DATE_COL = '10-DEZ-2004'
    And it gets to works again.
    What is going on ?
    JAVAC running on Windows2003.
    The application access the ORACLE DB directly through JDBC.
    There is no APPLICATION SERVER, like TOMCAT.
    The regedit (windows registry) ALWAYS was and are now :
    NLS_DATE_FORMAT = DD-MON-YYYY
    NLS_LANG = AMERICAN_AMERICA.WE8ISO8859P1
    Versions:
    DB Oracle 9.2.0.5.0
    JavaC 1.4.2.05
    Thanks.
    Juliano

    Somewhere, I'm willing to wager your NLS_DATE_FORMAT was/ is being changed. This is a client-side setting. Are you sure that the setting is the same on every client machine.
    This is one of the reasons that it is considered bad form to rely on implicit conversion. If you wrap your string literal in a TO_DATE, use the JDBC escape sequence {d }, or use a Date bind variable, you don't have this problem. The bind variable approach will also play much more nicely with your database's shared pool.
    Justin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

  • Date formats for SQL statements used by recordset object

    Hi,
    Date formatting appears to be quite problematic for Business One.  I did a forum search for date issues and I don't think I saw any of them with an "answered" status.  I have an issue with formatting a date for the creation of an SQL statement that the DI sends to SQL Server 2005.  I need to format a date so that the localization parameters don't matter for either the client machine or SQL Server's machine.  We don't have a problem as long as our machines are localized as USA.
    I have PL 22 and I have a form - ours - where I use the Today() function to fill a date field.  So this is a date that is not entered by the user.  The result of this function is consistent with the localization parameters on my machine.  We have two other date fields on the form where the user must type in the date. 
    As a test, I changed my machine to the UK parameters.  I then set up the language parameters of Business One for English(United Kingdom).  I changed the date format specifications in Business One so that its format is dd/mm/yy.  I then brought up the form and the field that is formatted by the above function arrived in the form's field as dd/mm/yy.  I then typed in the two other dates in the same format and added the record to the database.  The form's table is user-defined. 
    I dismissed the form then brought it back up loaded with the new record.  The date that was entered by the function appeared in USA format (mm/dd/yy).  The dates that were typed in appeared in the Business One format (dd/mm/yy).  This of course is not consistent.
    When I looked at what got into the database, the formats were the opposite.  Weird!  To make matters really confusing, I run an SQL statement within SQL Server Mgt Studio, and use the WHERE clause to filter on the date that was based on the function.  It didn’t matter what format I used for the WHERE clause, the record came up.  Does anyone have any idea about how I can ensure that I always use the correct date format for SQL statements passed by Business One to SQL Server regardless of where in the world the application is being run?
    Thanks,
    Mike

    Ian,
    Here's what I'm concerned about:  I’m using the date in a “WHERE” clause.
    Assume the date is Aug 3, 2007.
    "SELECT * FROM Table WHERE StartDate > ‘8/3/2007’"
    OR
    "SELECT * FROM Table WHERE StartDate > ‘3/8/2007’"
    If the client machine is set up as USA, the today function will provide the date as formatted in the first query.  If the database server is setup as let’s say the UK, I believe that SQL Server query parser will interpret the date as Mar 8, 2007.
    If the client machine is set up as UK, the today function will provide the date as formatted in the second query.  If the database server is setup as let’s say USA, I believe that SQL Server query parser will also interpret the date as Mar 8, 2007.
    In both cases it would be wrong.
    I know I could use the DATEPART function to get the three parts and this will make the code indifferent to the localization specs of the client machine.  I need to then be able to concatenate those date parts for the “WHERE” clause so that the localization specifications of the database server don’t matter.
    Thanks,
    Mike

  • Update date format in SQL developer

    I need to convert date format in SQL developer , it's varchar2 format now
    The current format is yyyy/mm/dd-hh:mm:ss:sss and I need to convert it to yyyy-mm-dd hh:mm:ss CST
    I don't really know SQL but did some research and found that I can use instr to find the string and replace it, however, no matter what I try,there is always something off :(
    Could anyone here help me with it? thanks in advance.

    create table xo_custom_date_format (mydateAsChar varchar2(100));
    table XO_CUSTOM_DATE_FORMAT created.
    insert into xo_custom_date_format
    values ('2012/03/23-09:52:24:123')
    +1 rows inserted.+
    select mydateasChar from xo_custom_date_format
    mydateaschar
    +2012/03/23-09:52:24:123+
    select to_timestamp(mydateaschar, 'YYYY/MM/DD-HH24:MI:SS:FF3') mydateAsTimestamp from xo_custom_date_format
    -- We must convert to timestamp data type, rather than date data type as you have fractions of seconds
    mydateAsTimestamp
    +23-MAR-12 09:52:24.123000000 --<-- This will probably appear differently, depending on your database NLS_ settings (i.e. what country you are in)+
    select to_char( to_timestamp(mydateaschar, 'YYYY/MM/DD-HH24:MI:SS:FF3') , 'YYYY-MM-DD HH24:MM:SS')||' CST' as myDateReformatted
    from xo_custom_date_format
    mydateReformatted
    +2012-03-23 09:03:24 CST+

  • Xml output format in sql*plus problem

    Hi all,
    In stead of seeing xml output in multiple line format, my sql*plus always returns xml output in ONE line, is there a way to change the format, it's really hard to read.
    Thanks
    1 select xmlelement("row", xmlelement("user", xmlattributes(username as "name", default_tablespa
    2 from dba_users
    3* where rownum=1
    SQL>/
    XMLELEMENT("ROW",XMLELEMENT("USER",XMLATTRIBUTES(USERNAMEAS"NAME",DEFAULT_TABLES
    <row><user name="SYS" tbs="SYSTEM"></user></row>
    however I want to see something well formatted like
    <row>
    <user name="SYS" tbs="SYSTEM"></user>
    </row>

    Not sure if there are any settings with the SQL*PLUS but if you use packages other than the SQLX operators like DBMS_XMLQUERY, DBMS_XMLGEN, SYS_XMLGEN to generate xml then the output is as desired.
    select dbms_xmlgen.getxml('select username, default_tablespace from dba_users
    where rownum=1') from dual
    DBMS_XMLGEN.GETXML('SELECTUSERNAME,DEFAULT_TABLESPACEFROMDBA_USERSWHEREROWNUM=1'
    <?xml version="1.0"?>
    <ROWSET>
    <ROW>
    <USERNAME>REVIEW</USERNAME>
    <DEFAULT_TABLESPACE>METRICS</DEFAULT_TABLESPACE>
    </ROW>
    </ROWSET>
    But these packages does not offer the flexibility you have with SQLX operators.
    so if you requirement is simple generation you can use the above method.

  • How to execute procedure returning data rows from sql plus

    Hi,
    I want to execute a stored procedure that returns data rows from sql plus. please let me know the syntax for the same.
    Thanks,
    YG

    user13065317 wrote:
    Even if i get the result set into the cursor, do i have to do normal fetch into all the coumn variables within a loop
    But suppose no of columns in my result set varies depending on a parameter to the stored procedure.
    Is there any straightforward way to retrieve all the data irrespective of no of columns in the result set.There is no such thing as a "+result set+". Oracle does not create a temporary data set in memory that contains the results of your query. What would happen if this result set is a million rows and is too large to fit into memory? Or there are a 100 clients each with a 100,000 row result set?
    This is not scalable. You will be severely limited in the number and sizes of these "+result sets+" that can be created in server memory.
    A cursor is in fact a "program" that is created by compiling the SQL source code that you provide. This source code is parsed and compiled into what Oracle calls an execution plan. This is nothing but a series of instructions that the cursor will execute in order to return the rows required.
    Thus the result set is actually the output from a cursor (a program). Likewise, bind variables are the input parameters to this program.
    All SQLs are parsed and compiled as cursors and stored in the SQL Shared Pool. Oracle gives you handle in return to use to address this cursor - bind values to it, execute it, describe the output structure returned by the cursor, and fetch the output from the cursor.
    On the client side, this handle is used in different ways. In PL/SQL alone, this cursor handle can be used as an implicit cursor (you do not even see or use the cursor handle in your PL/SQL code). Or you can use a PL/SQL cursor variable. Or a DBMS_SQL cursor variable. Or a reference cursor variable.
    Why so many different client structures for the very same SQL cursor handle returned by Oracle? Because to allow you, the programmer, all kinds of different features and flexibility.
    The ref cursor feature is the ability to pass this cursor handle around, not only between PL/SQL code, but also from PL/SQL to the actual client process (Java. VB, SQL*Plus, TOAD, etc).
    The primary thing to remember - irrespective of what the client calls this (e.g. ref cursor, SQL statement handle, etc), this all refers to the same SQL cursor in the Shared Pool. And that this SQL cursor is a program that outputs data, and not a result set in itself.

  • How to bind DATE variables in SQL*Plus

    I have a stored procedure in a package that has a DATE OUT parameter
    myPackage.myProcedure( outDate OUT DATE )
    I am trying to test this from SQL*Plus
    How do I specify a Bind variable for the outDate? The VARIABLE command does not allow DATE types?
    If this was a CHAR type I could have done
    VARIABLE myChar CHAR
    BEGIN
    myPackage.myProcedure( :myChar )
    END;
    PRINT myChar
    How do I do this with DATE data types instead? I am using Oracle 8.1.7.

    you should use VARCHR2 type with the minimum length that can store a value defined by your NLS_DATE_FORMAT
    string. The returned date will be converted to a VARCAHR2 type and the size and format will depend on
    your NLS_DATE_FORMAT setting.
    =============================================================================
    SQL> variable dt VARCHAR2(20)
    SQL> create or replace procedure ret_date(dt OUT DATE) is
    2 begin
    3 dt := SYSDATE ;
    4 end ;
    5 /
    Procedure created.
    SQL> exec ret_date(:dt) ;
    PL/SQL procedure successfully completed.
    SQL> print dt
    DT
    13-OCT-02
    SQL> select sysdate from dual ;
    SYSDATE
    13-OCT-02
    SQL> alter session set nls_date_format = 'DD-MON-YYYY HH24:MI:SS' ;
    Session altered.
    SQL> exec ret_date(:dt) ;
    PL/SQL procedure successfully completed.
    SQL> print dt
    DT
    13-OCT-2002 10:43:23
    SQL>
    ================================================================

  • Multiple date formats using sql developer

    Hello!
    i have 2 date fields in a table.. one is populated using trunc(<date1>) and the other is to_date(<date2>,'YYYYMMDD HH24MISS'). We want <date1> to display as MM/DD/YYYY and <date2> to display as MM/DD/YYYY HH:MI:SS AMPM. When we set the date format under Preference -> Database -> NLS parameter in SQL Developer with a time format it adds 12:00:00 to <date1>, if we take it out, it drops the time in <date2>. What can we do?
    thanks!

    I think what the original poster wanted was to display the two date columns using different formats in the table "Data" tab and AFAIK that is not possible. Setting a date format in the Preferences accomplishes the same thing as the statement
    ALTER SESSION SET NLS_DATE_FORMAT='<some format>';
    in command-line SQL*Plus. To do what the OP wants they'll need to create a view that has a SELECT something like this:
    SELECT TO_CHAR( date1, 'YYYY-MM-DD' ) date1
    , TO_CHAR( date2, 'YYYY-MM-DD HH24:MI:SS') date2
    FROM some_table;
    One thing the OP needs to keep in mind is that the DATE datatype stores both date and time together. If they insert a date alone, the time defaults to midnight. (This is stated in the Oracle SQL Reference.)
    Ed. H.

  • EA1 - Cannot Change Date Format in SQL Results

    In version 1.2, I used to go to Tools > Preferences > Database > NLS Paramters and change the date format there. The change would then be reflected in the SQL results for date columns.
    When I try to do the same thing in 1.5 EA1, the date format is always the same, DD-MON-RR, no matter what I put in the date format setting under NLS Paramters.
    Am I missing something?
    Thanks.

    Just a quick post to make sure that the bug you logged takes into account all NLS parameters :), as this does not concern only dates but also timestamp formats, decimal and group separators as well, and probably all of the NLS parameters I assume.

  • How to convert from ifs date format to sql based dates

    I want to write a sql query using dates, to search an ifs
    database. Ifs stores dates as numbers created using the
    java.util.Date class. These dates are accurate to seconds.
    PLSQL uses a different format.
    What I need is a PLSQL function that converts PLSQL date format
    to and from the java.util.date format.
    This is an example of what I would like to do.
    String classname = "DOCUMENT";
    String whereclause = "CREATEDATE > theNeededFuction(to_date('01-
    Jan-2001', 'DD-Mon-YYYY'),'j')";
    Selector mySelector = new Selector(login.getSession());
    mySelector.setSearchClassname(classname);
    mySelector.setSearchSelection(whereclause);
    I do realize that I could simply convert the date in java, but
    in the long run, I want to use the oracle tools that support
    busness day calulations.
    -Mitch

    Hi Mitch - our ViewSpecification functionality automatically
    includes an Oracle Date column, which is derived from the java
    date values we store. These views are the supported way of
    performing read-only operations against an iFS instance.
    For yor reference, the Oracle date column is derived using the
    following SQL operation (e.g. for createdate):
    to_date('01-JAN-1970', 'DD-MON-YYYY') + (createdate/86400000)
    regards,
    dave

  • Wrong Date format in SQL Server

    Hello All,
    I have an asp page with a hidden field that holds
    <%=Date()%>. Because the
    Session.LCID is set to UK this value today would be
    12/03/2007 (UK format).
    When this hidden field is fed into an INSERT Stored Procedure
    in SQL Server
    in my testing environment, the date format that is inserted
    into the
    database is the same as the value in the hidden field eg
    12/03/2007, which
    is what I want.
    Now though, the site has moved to a production web server
    with SQL Server.
    When I perform this exact insert using the same webpages and
    (from what I
    can see) the same SQL Server configuration, the date inserts
    as 03/12/2007,
    US format. This is causing me big problems as the website is
    complete but
    the wrong dateformat is producing some undesirable results.
    The whole site
    is set up to expect the original format and I cannot see why
    this is
    happening.
    Does anyone have any suggestions and more importantly how I
    can change this
    please.

    There is a real issue here and it has nothing to do with the
    way that data
    is formatted on the way out.
    msSQL does seem to always assume that numbers entered in the
    format of
    00/00/00 follow the pattern of MM/DD/YY which is American
    format. So the 8th
    of March entered in UK format of 08/03/2007 ends up being
    intrepreted by SQL
    as 3rd August. However it only does this up to the 12th of
    each month. If
    you enter the 13th of March as 13/03/2007 SQL stores it
    correctly.
    The workaround does seem to enter the number in the
    YYYY-MM-DD format as
    Julian has suggested.
    Paul Whitham
    Certified Dreamweaver MX2004 Professional
    Adobe Community Expert - Dreamweaver
    Valleybiz Internet Design
    www.valleybiz.net
    "Lionstone" <[email protected]> wrote in
    message
    news:[email protected]...
    > SQL Server does not store dates in any format. They are
    simply numbers,
    > with the integer part representing date and the
    fractional part
    > representing time. If you do not format dates on the way
    out, then you're
    > leaving things up to your web server (and depending on
    when the dates
    > become strings, it might be the ADO provider and not ASP
    that does the
    > formatting).
    >
    > The only way to reliably format dates the way you want
    is to do so
    > explicitly. You may use CONVERT for SQL Server and
    specify a format
    > option (
    http://msdn2.microsoft.com/en-us/library/aa226054(SQL.80).aspx),
    > or you may use the FormatDateTime function in your ASP
    page.
    > FormatDateTime is locale-aware when it formats dates.
    All you have to do
    > is make sure the locale is set properly (which you seem
    to have done).
    >
    >
    >
    > "TTal" <[email protected]> wrote in message
    > news:[email protected]...
    >> Hello All,
    >>
    >> I have an asp page with a hidden field that holds
    <%=Date()%>. Because
    >> the Session.LCID is set to UK this value today would
    be 12/03/2007 (UK
    >> format).
    >>
    >> When this hidden field is fed into an INSERT Stored
    Procedure in SQL
    >> Server in my testing environment, the date format
    that is inserted into
    >> the database is the same as the value in the hidden
    field eg 12/03/2007,
    >> which is what I want.
    >>
    >> Now though, the site has moved to a production web
    server with SQL
    >> Server. When I perform this exact insert using the
    same webpages and
    >> (from what I can see) the same SQL Server
    configuration, the date inserts
    >> as 03/12/2007, US format. This is causing me big
    problems as the website
    >> is complete but the wrong dateformat is producing
    some undesirable
    >> results. The whole site is set up to expect the
    original format and I
    >> cannot see why this is happening.
    >>
    >> Does anyone have any suggestions and more
    importantly how I can change
    >> this please.
    >>
    >
    >

  • Date Format in SQL Loader

    Dear All,
    I have a table CMS_HO where I have defined different columns. One column is of date type STATUS_DATE. I want to upload one ASCII file where one field is in the format like below:
    5/26/2008 12:41
    5/26/2008 8:51
    5/28/2008 9:01
    5/28/2008 13:54
    5/13/2008 10:45
    4/6/2008 9:21
    I want to upload file into Oracle database. Currently I am using following control file:
    LOAD DATA
    INTO TABLE CMS_HO TRUNCATE
    FIELDS TERMINATED BY "\t"
    TRAILING NULLCOLS
    ( ID,EXPIRYDATE, VER, SN, STATUS_DATE)
    There seems error in the STATUS_DATE field in control file. Can any one help how to modify this Control file so that data against this field can be uploaded into date format please?
    Thanks

    Here's an example i pulled from the web on specifying the date format in a control file.
    http://infolab.stanford.edu/~ullman/fcdb/oracle/or-load.html#loading%20date%20data
    Based on the sample data you provided, i think this is the format you're after.
    ME_XE?select
      2     to_date('5/13/2008 10:45', 'mm/dd/yyyy hh24:mi') as date_value_24_hours
      3  from dual;
    DATE_VALUE_24_HOURS
    13-MAY-2008 10 45:00
    1 row selected.
    Elapsed: 00:00:00.89

  • How to convert milliseconds to date format in sql query

    Hi All,
    The following code is in java.     
    String yourmilliseconds = "1316673707162";**
    Date resultdate = new Date(Long.parseLong(yourmilliseconds));
    could you plese tell me how to convert milliseconds into date format in query and comparing with another date like(sysdate-3)

    Hello,
    http://stackoverflow.com/questions/3820179/convert-epoch-to-date-in-sqlplus-oracle
    Regards

  • Help with date format and sql

    Hi
    I am a complete oracle idiot.
    I have created a table with 2 columns po_id,po_date. Yhe id data type is number,date type is date. To add values to the table i enter something like
    "insert into purchase_orders(po_id,po_date) values(1,01/01/2004)"
    It does not accept the date and will not add the record, i have also tried the date format 01-Jan-2004.
    What is the proper way to add the date.
    Thanks
    Garry

    You probably want to use an explicit to_date cast. That lets you specify the format of the date string, i.e.
    INSERT INTO purchase_orders( po_id, po_date )
      VALUES( 1, to_date( '01/01/2004', 'DD/MM/YYYY' );Justin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

  • DATE FORMAT IN SQL

    Hi
    I need to compare between 2 dates and display the greatest among them.
    Ex:
    Date1 : 05/09/08 13:50 MDT
    Date2 : 06/09/08 13:50 CDT
    The greatest among these two is 06/09/08 13:50 CDT . But here I need to display
    Date with Time stamp . like the output format should be "06/09/08 13:50 CDT"
    Any body have any Idea about how to write Sql for this?

    Please, take a look in the doc :
    http://download.oracle.com/docs/cd/B10501_01/server.920/a96540/functions134a.htm#1032202
    Nicolas.

Maybe you are looking for

  • Not using the most recent checked in version of the web app DLL in Release build

    Hi folks Got some peculiar behaviour - I have three build configurations set up within VS2K13 for Debug, Release and DebugOnLive. There are some basic XML transformations to update emails, db-settings etc - all very simple and working. Needed to do a

  • What is the use of Tcode: SM35

    Hi Experts, What is the use of Tcode: SM35 If some one can brief me in detail it would be great help. Appreciate your early response. Regards Rajesh

  • App Store MAC Updates download and install, yet show as needing Update

    I have, 4 times now, selected UPDATE on two apps that show as having free updates. they do so and tell me they are installing, and the buttons change to installed. Then I quit App Store, to find the red button with 2 in it re-appears and I start the

  • Real Application Clusters

    Dear All, I need to test the load balancing on the RAC, so i need to know how can i know the number of sessions on each instance ? Exp: Suppose i have 15 sessions 8 sessions on instance number 1 7 sessions on instance number 2, what is the query for

  • Displaying no Records found in webdynpro side?

    Hi All , How to display the error message coming from R/3 side. If iam giving input from dynproside, if no Records found in R/3 side how can I display "No records Found"in Dynpro side. Please help me for this. Thanks Nageswara.