How to truncate sysdate

hello friends
I created a table called log as follows
create table log(logid number,login_date date);
insert into log values(101,sysdate);
after 10 mins i created a cursor as follows..
declare
uname varchar2(30);
logdate date;
cursor name_c is
select logid,login_date from log where logid=101 and login_date=sysdate;
begin
open name_c;
fetch name_c into uname,logdate;
if(name_c%FOUND) then
dbms_output.put_line( 'FOUND');
end if;
close name_c;
end;
set serveroutput on;
PL/SQL procedure successfully completed.
But i got no result..I found the reason that when i insert into table sysdate stores all fields
including hour,min,sec etc.. But i fetch cursor sysdate[After 10 min] So the time fields change.So only the cursor fetch no rows...Please help me to fetch the row from log table..
How to truncate sysdate field to fetch only date like('18-feb-2011')..

hi there
use trunc(sysdate) in ur cursor
and one more thing
use
exit when name_c%notfound;refer this
DECLARE
   uname     VARCHAR2 (30);
   logdate   DATE;
   CURSOR name_c
   IS
      SELECT   logid, login_date
        FROM   LOG
       WHERE   logid = 101 AND trunc(login_date) = trunc(SYSDATE);
BEGIN
   OPEN name_c;
   FETCH name_c INTO   uname, logdate;
    exit when name_c%notfound;
   IF (name_c%FOUND)
   THEN
      DBMS_OUTPUT.put_line ('FOUND');
   END IF;
   CLOSE name_c;
END;
/regards
Hitesh

Similar Messages

  • How to truncate data in a subpartition

    Hi All,
    I am using oracle 11gr2 database.
    I have a table as given below
    CREATE TABLE SCMSA_ESP.PP_DROP
    ESP_MESSAGE_ID VARCHAR2(50 BYTE) NOT NULL ,
    CREATE_DT DATE DEFAULT SYSDATE,
    JOB_LOG_ID NUMBER NOT NULL ,
    MON NUMBER GENERATED ALWAYS AS (TO_CHAR("CREATE_DT",'MM'))
    TABLESPACE SCMSA_ESP_DATA
    PARTITION BY RANGE (JOB_LOG_ID)
    SUBPARTITION BY LIST (MON)
    PARTITION PMINVALUE VALUES LESS THAN (1)
    ( SUBPARTITION PMINVALUE_M1 VALUES ('01') TABLESPACE SCMSA_ESP_DATA,
    SUBPARTITION PMINVALUE_M2 VALUES ('02') TABLESPACE SCMSA_ESP_DATA,
    SUBPARTITION PMINVALUE_M3 VALUES ('03') TABLESPACE SCMSA_ESP_DATA,
    SUBPARTITION PMINVALUE_M4 VALUES ('04') TABLESPACE SCMSA_ESP_DATA,
    SUBPARTITION PMINVALUE_M5 VALUES ('05') TABLESPACE SCMSA_ESP_DATA,
    SUBPARTITION PMINVALUE_M6 VALUES ('06') TABLESPACE SCMSA_ESP_DATA,
    SUBPARTITION PMINVALUE_M7 VALUES ('07') TABLESPACE SCMSA_ESP_DATA,
    SUBPARTITION PMINVALUE_M8 VALUES ('08') TABLESPACE SCMSA_ESP_DATA,
    SUBPARTITION PMINVALUE_M9 VALUES ('09') TABLESPACE SCMSA_ESP_DATA,
    SUBPARTITION PMINVALUE_M10 VALUES ('10') TABLESPACE SCMSA_ESP_DATA,
    SUBPARTITION PMINVALUE_M11 VALUES ('11') TABLESPACE SCMSA_ESP_DATA,
    SUBPARTITION PMINVALUE_M12 VALUES ('12') TABLESPACE SCMSA_ESP_DATA
    PARTITION PMAXVALUE VALUES LESS THAN (MAXVALUE)
    ( SUBPARTITION PMAXVALUE_M1 VALUES ('01') TABLESPACE SCMSA_ESP_DATA,
    SUBPARTITION PMAXVALUE_M2 VALUES ('02') TABLESPACE SCMSA_ESP_DATA,
    SUBPARTITION PMAXVALUE_M3 VALUES ('03') TABLESPACE SCMSA_ESP_DATA,
    SUBPARTITION PMAXVALUE_M4 VALUES ('04') TABLESPACE SCMSA_ESP_DATA,
    SUBPARTITION PMAXVALUE_M5 VALUES ('05') TABLESPACE SCMSA_ESP_DATA,
    SUBPARTITION PMAXVALUE_M6 VALUES ('06') TABLESPACE SCMSA_ESP_DATA,
    SUBPARTITION PMAXVALUE_M7 VALUES ('07') TABLESPACE SCMSA_ESP_DATA,
    SUBPARTITION PMAXVALUE_M8 VALUES ('08') TABLESPACE SCMSA_ESP_DATA,
    SUBPARTITION PMAXVALUE_M9 VALUES ('09') TABLESPACE SCMSA_ESP_DATA,
    SUBPARTITION PMAXVALUE_M10 VALUES ('10') TABLESPACE SCMSA_ESP_DATA,
    SUBPARTITION PMAXVALUE_M11 VALUES ('11') TABLESPACE SCMSA_ESP_DATA,
    SUBPARTITION PMAXVALUE_M12 VALUES ('12') TABLESPACE SCMSA_ESP_DATA
    ENABLE ROW MOVEMENT;
    I have populate two sets of data.
    One with Positive job_log_id and another with Negative job logid as given below.
    Step 1:
    Data going to PMAXVALUE Partition
    INSERT INTO PP_DROP ( ESP_MESSAGE_ID, CREATE_DT,JOB_LOG_ID)
    SELECT LEVEL, SYSDATE+TRUNC(DBMS_RANDOM.VALUE(1,300)), 1 FROM DUAL CONNECT BY LEVEL <=300;
    Step 2:
    Data going to PMINVALUE partition
    INSERT INTO PP_DROP ( ESP_MESSAGE_ID, CREATE_DT,JOB_LOG_ID)
    SELECT LEVEL, SYSDATE+TRUNC(DBMS_RANDOM.VALUE(1,300)), -1 FROM DUAL CONNECT BY LEVEL <=300;
    Now the question is how to truncate the data that is present only in the Positive partitions subpartition
    Like in the PMAXVALUE partition I have 10 subpartitions and I need to truncate the data in the JAN MONTH Partition only of the PMAXVALUE partition.
    Appreciate your valuable response.
    Thanks,
    MK.

    For future reference:
    http://www.morganslibrary.org/reference/truncate.html
    The library index is located at
    http://www.morganslibrary.org/library.html

  • How to default Sysdate in Advance table region on clicking Add Another Row

    Hi,
    Can any one please help me how to default Sysdate (MessageTextInput column) in Advance table region on clicking Add Another Row.
    Thanks,
    Mohan

    Got it... thanks mukesh..here it works.Reference to others!!!
    if (ADD_ROWS_EVENT.equals(pageContext.getParameter(EVENT_PARAM)))
    OAViewObject vo3 = (OAViewObject)am.findViewObject("XxStageLineVO1");
    OARow row1 = (OARow)vo3.getCurrentRow();
    java.util.Date sysdate = pageContext.getCurrentUserDate();
    String convSysDate = pageContext.getOANLSServices().dateToString(sysdate);
    row1.setAttribute("StrtDt", convSysDate);
    }

  • How to convert sysdate to the format dd-mon-yyyy

    how to convert sysdate to the format dd-mon-yyyy

    <how to convert sysdate to the format dd-mon-yyyy>
    This question is better answered by thinking about about how Oracle dates work. SYSDATE is a pseudocolumn (function without any arguments) that returns a date value: it already is a date. Oracle date values are stored not as we see them, say 'DD-MON-YY', but as a series of bytes with the different date components from the millennium down to the second. We NEVER see dates as they are stored but use the formats for automatic conversion.
    To display a date the way you want use TO_CHAR() with an edit mask or as others suggested change your NLS_DATE_FORMAT (thought I advise against this as most systems use DD-MON-YY and porting queries from other systems or even OTN can easily break). To change a converted string back to a date use TO_DATE() with an edit mask.

  • How to truncate the floats?

    I like to know how to truncate the floats to 2 decimal points because when I got 500.00 - 0.10, I get 499.9000000000...
    So how do I say 499.90?

    Try using NumberFormat class:
    NumberFormat currency = NumberFormat.getNumberInstance();
    currency.setMinimumFractionDigits(2);
    currency.setMaximumFractionDigits(2);
    String s = currency.format(anyFloatValue);
    ..

  • How to truncate a micro feed?

    How to truncate a micro feed? or set a filter to display the last 5 posts etc?

    Hi,
    If you only want to show the last 5 posts in the site feed web part, then you use the code below to limit the numbers of posts:
    <script src="http://code.jquery.com/jquery-1.10.2.min.js" type="text/javascript"></script>
    <script type="text/javascript">
    $(document).ready(function () {
    var limit=5;
    $("#ms-feedthreadsdiv .ms-microfeed-thread").each(function(i){
    if(i>=limit){
    $(this).addClass("ms-hide");
    </script>
    However, you need to override the click event of the “SHOW MORE POSTS” button after using the code above.
    And it is better to create your own site feed web part with default limit number of posts as 5.
    https://social.msdn.microsoft.com/Forums/sharepoint/en-US/dac4a734-4d62-4ac7-b8a6-5d27b78c55de/how-to-set-the-item-limit-on-the-activity-feed-webpart-sp2013?forum=sharepointdevelopment
    Best regards.
    Thanks
    Victoria Xia
    TechNet Community Support

  • How to truncate the values from the table

    Hi All,
    I am working on an issue..where we are first deleting all the records from the table and then based on few conditions we are putting the records back in that table...when we tried to run this program along with few others those who are doing almost the same stuff we are having issues...we tried to schedule few jobs related to these programs only...but after a ceratin amount of time couple of jobs got canceled...I was talking to my basis guy and he said the problem is ratehr then truncating the records from the table we are deleting the records and it's taking lots and lots of space to execute...so we need to truncate the records from the table insted of deleting it...we are using the following the statement right now:
        DELETE FROM ZTUS_PG.
        COMMIT WORK.
    So can you please tell me how can we truncate the values from this table instead of just deleting them and what would be effect of this.
    Thanks,
    Rajeev Gupta

    I don't think basis is saying you should delete all the records from the table. They are saying remove the table and it's contents (a much faster thing to do). I'm not sure this the right thing to do, but you can have a look at:
    http://publib.boulder.ibm.com/infocenter/db2luw/v9/index.jsp?topic=/com.ibm.db2.udb.apdv.sample.doc/doc/admin_scripts/s-truncate-db2.htm
    Something like:
    EXEC SQL.
      TRUNCATE TABLE ZTUS_PG REUSE STORAGE
    ENDEXEC.
    COMMIT WORK.                      "Empty table is committed here
    Rob
    Edited by: Rob Burbank on Dec 1, 2008 4:06 PM

  • How to truncate a field in a Select Query

    Hello Gurus,
    I am new in SAP, i have a question i am making an appointment letter in SMARTFORMS , in global declaration (initialization) i am using a select query
    SELECT SINGLE BET01 FROM PA0008 INTO G_BET01 WHERE PERNR = WA_PERNR.
    where BET01 is the Amount field which is getting printed in the smart form but its takes 5 to 6 character blank spaces in the printing time, i want to truncate this space (remove this space ) in the print time , please tell me how to remove this space , the field size is 13 , how can i reduce the field size in my smartform query. please help . G_BET01 is a variable

    Maybe you can use this.
    DATA: d_char(15).
    WRITE G_BET01 TO d_char CURRENCY 'XXX'.
    'Then you can remove the spaces using :
    CONDENSE d_char no-gaps.

  • How to insert sysdate in a flat file

    Hi All,
    i have a interafce i extract data from oracle database and generate a flat file.
    In one of the columns i have to insert sysdate in the file.
    could someone help me how to add the sysdate in flat file.
    Thanks in advance
    Naveen

    Hi Naveen,
    Trying to contribute a little,
    Yes you can use sunopsis CURRENT_DATE function to get the sysdate.
    @ your interface
    1. In the definition, make sure your staging area different from target is checked and SUNOPSIS MEMEORY ENGINE is selected.
    2. In the diagram, for the column which you want date to be inserted just say CURRENT_DATE and make it to execute on STAGING.
    3. In the Flow, you have to see 3 boxes, in the first box select LKM SQL to SQL, in the second box make it as UNDEFINED, in the third box select IKM SQL To FIle Append and select the options accordingly.
    Makes sens?
    Thanks,
    G

  • How to truncate oracle.jbo.domain.date

    Hi,
    I have problem to convert oracle.jbo.domain.date. Now I got current date from pagecontext, but it is yyyy-mm-dd hh:mi:ss format. I want to only yyyy-mm-dd, so I want to truncate the time from oracle.jbo.domain.date. And I want to got Date object not string. I found there is Date.truncate(), but I don't know how to use it.
    Could some one to help to give me a example?
    Best Regards,
    Eileen

    After spandig a lot of time with this I have found that the method is not implemented!!!
    Use this:
        public static oracle.jbo.domain.Date trunc(oracle.jbo.domain.Date dt,String fmt) {
            java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(fmt);
            String s= sdf.format(dt.getValue());
            java.sql.Timestamp ts;
            try {
                ts = new java.sql.Timestamp(sdf.parse(s).getTime());
                dt=new oracle.jbo.domain.Date(ts);
            } catch (ParseException e) {
            return dt;
        }To trunc to hours use format e.g. "dd.MM.yyyy HH"
    Karel
    Edited by: Karel.Redl on 26.11.2009 6:48

  • How to get SYSDATE in the header section dynamically when we run the report

    I have one more issue may i know how can i get the sysdate in the header section when i run the report.
    as we have the requirement like this
    In the header section
    Run Date : ("sysdate").
    How to get the sysdate dynamically in the RTF template, when i go across the google i found that header and footer section did not allow form fiields .
    So is there any way to do it.
    Thanks in Advance.
    Have a Nice Day.

    You cannot insert form fields in the Header section, but you can just insert the code to achieve this. For example: insert this in the header section to view the sysdate: You could format the date as you would like..
    <?xdoxslt: sysdate(‘YYYY-MM-DD’)?>
    Since you are new to BI publisher, search the forum, review the Report Designer's guide for BI publisher. You will find that most of your basic questions are answered there and there are examples as well.
    Thanks!

  • JSP - How to Truncate or replace non-english inputs ?

    Hi,
    I have a JSP form in which users needs to input certain values and those values get stored in our database. Now my concern is that many a times users from different part of geographies also input non-english values which comes as weired characters and gets stored in my database.
    I do not want non english stuffs to be stored in my database.
    What I want is that if user enters any NON-ENGLISH character then either it should get truncated or it should get replaced with its nearest matching english character.
    How can I achieve this ?
    Awaiting Help !
    Thanks

    Hey guyz..Iam awaiting ur response......is it something that not achievable....if thats so then please suggest me some way out

  • How to assign sysdate  in application engine peoplecode action

    Hi ,
    How to assign the below query result to local variable in Applicationengine peoplecode action.
    select to_char(sysdate,'MM/DD/YYYY') from dual;
    My objective is:Need to assign sysdate(date only) to local variable in app engine peoplecode action.
    Thanks
    Vinoth

    Use peoplecode function %Date instead of a roundtrip to the database.

  • How to TRUNCATE a table dynamically in a Stored Procedure?

    Hi everyone, How can I create a Procedure with dynamic sql to truncate a table name I pass by every time in Oracle? I am running the following query and nothing happens. It neither creates the procedure nor errors out.
    CREATE OR REPLACE PROCEDURE TruncateTable(TableName IN VARCHAR2(50))
    IS
    BEGIN
    SQLCmd VARCHAR(200);
    BEGIN
    SQLCmd := 'TRUNCATE TABLE ' || TableName;
    EXECUTE IMMEDIATE SQLCmd;
    END;
    Could someone please help me?
    Thanks

    Thanks Brendan for the reply. But, it neither does anything after I add a "/" on line9. Just wondering if the syntax of the proc is correct?

  • How To Format Sysdate

    How do you format sysdate? I want the results to be in date format, but I only want the date itself without the time added as
    6/14/2010
    The To_Date function doesn't seem to work as it converts a string to a date and sysdate isn't a string?
    Thanks for any help..

    user12296489 wrote:
    Turns out that I can specify to change the format from text to date when I import the data into access. So, after using To_Char to save the data in mm/dd/yy text format, I can import that, changing it to date format upon the import..That sounds like the correct thing to do.
    You have to remember, when you talk about "format", you are talking about how something is displayed or output and that means you are talking about strings. Only character based datatypes are strings (VARCHAR2, CLOB) and the other datatypes are internal representations that have to be formatted to strings to be displayed.
    For examples, if I look at the string 'FRED'...
    SQL> select 'FRED', dump('FRED') as dmp from dual;
    'FRE DMP
    FRED Typ=96 Len=4: 70,82,69,68You can see that it's stored internally as 4 bytes each of which are the ascii values of the 4 characters in the string. There's no formatting needed as it's already a direct representation of the ASCII characters needed to display it.
    However, if I look at sysdate...
    SQL> select sysdate, dump(sysdate) as dmp from dual;
    SYSDATE             DMP
    15/06/2010 08:28:04 Typ=13 Len=8: 218,7,6,15,8,28,4,0Whilst it displayes in DD/MM/YYYY HH24:MI:SS format, the internal storage of it is something completely different. It's made up of 8 bytes of data that sort of (but not fully) represent the number parts of the date, but contain non of the formatting that would display it as it appeared to me.
    The format for the date comes from my local session settings, which tell it how to format it as a string. I can change this...
    SQL> alter session set nls_date_format='DD-MON-YYYY';
    Session altered.
    SQL> select sysdate, dump(sysdate) as dmp from dual;
    SYSDATE     DMP
    15-JUN-2010 Typ=13 Len=8: 218,7,6,15,8,32,44,0Now the date is displayed differently, but internally it's still represented by 8 bytes, that hasn't changed.
    So, if you want to format dates, or numbers, you need to use the TO_CHAR function and specify the format it should be displayed in. You can use the NLS settings, but they are session specific and you would need to be careful using them. It's always better to be explicit about the format you want using TO_CHAR instead.

Maybe you are looking for

  • 3 iOs 5 bugs no one seems to be talking about

    I've noticed 3 bugs in iOs 5 that no one seems to be talking about. 1.  Sometimes the setup personal hotspot toggle in settings will keep thinking even if you don't tap on it.  I believe this contributes to the poor battery life.  I've found the only

  • Acrobat 9 ad in not working in excel.

    The ad in is there, when I hover mouse over option to create PDF I get additional options, but when I go to choose the option I want, it fades away.  I can create PDF's within Acrobat 9 program, but really need to have the ad in work in excel.

  • Notification sent to all users in a role when some of them responded in first reminde

    Hi, We have a workflow using (voteforresult, standard voting method) sending notifications to users via role. Sends first notification times out sends second one. If some users responded to notification in first email it still sends email to all user

  • Adding Actionlistener to a cell in a JTable?

    is this possible? how would i go among doing this?

  • Help help please help

    i have a msi 7970 and soon as i start it it overheats i'm running a waterblock on it but soon as i hit start it overheats and crashes can someone help me or point me in the right direction thank you