Trying to get sysdate- 2yrs and sysdate+2yrs value into variable

Hi,
iam Trying to get sysdate- 2yrs and sysdate+2yrs value into variable.But facing the following issue. Please help me out .
Error :
p_start_date := select add_months(max(sysdate), -24) from dual;
ERROR at line 6:
ORA-06550: line 6, column 25:
PLS-00103: Encountered the symbol "SELECT" when expecting one of the following:
( - + case mod new not null <an identifier>
<a double-quoted delimited-identifier> <a bind variable>
continue avg count current exists max min prior sql stddev
sum variance execute forall merge time timestamp interval
date <a string literal with character set specification>
<a number> <a single-quoted SQL string> pipe
<an alternatively-quoted string literal with character set specification>
<an alternat
ORA-06550: line 7, column 3:
PLS-00103: Encountered the symbol "P_END_DATE"
Code
declare
p_start_date date;
p_end_date date;
begin
select add_months(max(sysdate),-24) into p_start_date from dual;
dbms_output.put_line('p_start_date' |p_start_date);
dbms_output.put_line('p_end_date' | p_end_date);
end;

Hi, try:
SQL> declare
  2 
  3  p_start_date date;
  4  p_end_date date;
  5 
  6  begin
  7 
  8  select add_months(sysdate,-24) into p_start_date from dual;
  9  select add_months(sysdate, 24) into p_end_date from dual;
10 
11  dbms_output.put_line('p_start_date: ' ||to_char(p_start_date, 'dd-mm-yyyy hh24:mi:ss'));
12  dbms_output.put_line('p_end_date: '   ||to_char(p_end_date, 'dd-mm-yyyy hh24:mi:ss'));
13  end;
14  /
p_start_date: 14-04-2007 17:41:34
p_end_date: 14-04-2011 17:41:34
PL/SQL procedure successfully completed.

Similar Messages

  • Date between sysdate-50 and sysdate  problem

    hi,
    i have a big big problem and i need some help
    I have oracle 8i and 10g databases installed at work. i have a problem with an select statement that brings data from 3 tables.
    The select looks like this:
    select mms_id, img_id, mms_usr_id as usr_id, mms_pvd_id, mms_data as data
    from vsc_mms vm, vsc_image vi, vsc_user vu
         where img_mms_id = mms_id
         and mms_usr_id = usr_id and usr_client_id = cli
         and img_mms_id <> 0
              and mms_status =0
              and mms_data between data_ini and data_end .......is not very important; the joins are made all right. What is important is that:
    vsc_mms has aprox. 3.000.000 recordings
    vsc_image has, also, aprox. 3.000.000 recordings.
    select count(distinct img_date) from vsc_image =657.021
    select count(distinct mms_data) from vsc_mms >=600.000
    On both tables there are, among other, index on mms_data, img_date.
    Now, my data_ini and data_end come from java (user send data_ini and data_end through http:// ) OR i can put this select in a procedure like:
    declare
    datai date:=to_date('20.01.2006','dd.mm.yyyy');
    datae date:=to_date('30.01.2006','dd.mm.yyyy');
    ......my select ..... and mms_data between data_ini and data_end
    the select takes on 8i more than 30 seconds. the same select takes on 10G quite same long time. i also run the select using
    and mms_data between sysdate-50 and sysdate and i got the same long time.
    Also important: this select brings almost 30 recordings; when the restrictions are too severe and the count(*) =0 the result is brought in 0.01 seconds; outherwise, when count(*) >1, is ruinous.
    But, if i put and mms_data between to_date('20.01.2006','dd.mm.yyyy') and to_date('30.01.2006','dd.mm.yyyy'), the response come in 1 seconds or less.
    1. Can someone help me and tell me why i got this long time for response when i use sysdate or when receiving data_ini, data_end like parameters from java
    2. is it true that for a better usage of a index, the procent of repeatedly recordings has to be small? I mean when i have 600.000 distinct recordings from 3.000.000 is it good or not to use index on that column?
    thanks in advance

    There can be some difference in how Oracle builds execution plan when
    you are using binding variables and explicit values:
    SQL> create index idxtbl1 on tbl1(date#);
    Index created.
    SQL> insert into tbl1 select sysdate-rownum from (select 1 from dual connect by lev
    200000 rows created.
    SQL> create index idxtbl1 on tbl1(date#);
    Index created.
    SQL> analyze table tbl1 compute statistics for all indexes;
    Table analyzed.
    SQL>set autotrace traceonly
    SQL> var a1 varchar2(20)
    SQL> var a2 varchar2(20)
    SQL> select * from tbl1 where date# between to_date('01/01/1900','dd/mm/yyyy')
      2  and to_date('01/01/1901','dd/mm/yyyy');
    365 rows selected.
    Execution Plan
       0      SELECT STATEMENT Optimizer=ALL_ROWS (Cost=3 Card=365 Bytes=3
              285)
       1    0   INDEX (RANGE SCAN) OF 'IDXTBL1' (INDEX) (Cost=3 Card=365 B
              ytes=3285)
    Statistics
              0  recursive calls
              0  db block gets
             28  consistent gets
              0  physical reads
              0  redo size
           6809  bytes sent via SQL*Net to client
            772  bytes received via SQL*Net from client
             26  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
            365  rows processed
    SQL> exec :a1 := '01/01/1900'
    PL/SQL procedure successfully completed.
    SQL> exec :a2 := '01/01/1901'
    PL/SQL procedure successfully completed.
    SQL> select * from tbl1 where date# between to_date(:a1,'dd/mm/yyyy')
      2  and to_date(:a2,'dd/mm/yyyy');
    365 rows selected.
    Execution Plan
       0      SELECT STATEMENT Optimizer=ALL_ROWS (Cost=4 Card=495 Bytes=4
              455)
       1    0   FILTER
       2    1     INDEX (RANGE SCAN) OF 'IDXTBL1' (INDEX) (Cost=4 Card=495
               Bytes=4455)
    Statistics
              0  recursive calls
              0  db block gets
             28  consistent gets
              0  physical reads
              0  redo size
           6809  bytes sent via SQL*Net to client
            772  bytes received via SQL*Net from client
             26  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
            365  rows processedRgds.

  • Trying to get the Opening and Closing Balance, 0TOTALSTCK and 0VALSTCKVAL

    Hi Experts, Good Day.
    I am developing a query for Stock Balances, Using Custom cube created with copy from 0ic_c03.
    I am trying to get the Opening and Closing Balance, based on Non-Cumulative KF - 0TOTALSTCK and 0VALSTCKVAL.
    Both The KF's Behaviour for Exception Aggregat. = Last Value
    I am using VARIABLE OFFSET as -1 to get Opening Balance, and just restriction for Closing Balance based on 0CALMONTH
    Unfortunately i am getting data for the periods which does not have data in my Cube. It is taking the total value as closing balance for the periods which we don't have transaction in the cube.
    For Ex. I have data for 09.2010 & 10.2010 a particular material, when i enter 08.2010 as input i am getting the total value of the material.
    I hope you understand the problem and solution soon.
    I will give you more explanation if needed.
    Thanks in Advance....
    Have a great Day Ahead.....
    GopalN

    Hi GopaIN,
    can you explain us process you have done about initialization of data (2LIS_03_BX, cube compression)? it seams like there was data before 09.2010 and you load it with 2LIS_03_BX data source. That data is not in cube, but just used for update markers.
    Edited by: Sasa Todorovic on Mar 25, 2011 9:48 AM

  • I got a new ipad mini and chose to set up as a copy of my iPad.  Didn't sync the music on however as it is a smaller model, not enough room.  Now trying to get some pictures and music on.  Chose some pictures that were not in iPhoto, got a message that I

    I got a new ipad mini and chose to set up as a copy of my iPad.  Didn't sync the music on however as it is a smaller model, not enough room.  Now trying to get some pictures and music on.  Chose some pictures that were not in iPhoto, got a message that I could only sync with one library, chose cancel, and apply and it downloaded my pictures anyway.  Now trying to sync some music but just get "The iPad “Linda’s iPad” is synced with another iTunes library. Do you want to erase this iPad and sync with this iTunes library?"  So I hit cancel.  Have tried several times, same thing. What can I try?

    You should be able to accept this message, it will cause existing music, photos (not camera roll) and videos (also excluding those in camera roll) to be removed and replaced with those from this computer. All other user data on the iPad will be unaffected.

  • Just wanted to make sure I had the most up to date version of ITunes on my desktop first.  Tried to get on site, and got an error message saying; The folder ITunes is on a locked disk or you do not have write permissions for this folder.  Help!

    Wanted to sync up my new IPhone4, and thought that I should make sure I had the most up to date version of ITunes on my desktop first.  Tried to get on site, and got an error message saying; "The folder ITunes is on a locked disk or you do not have write permissions for this folder."   Cannot get on ITunes at all now.  Help!  Thx.

    In my case its a new computer the old one was stolen and the time machine disk did not work for a restore but did for copying the info to the new mac

  • I'm trying to get itunes up and running on new computer. I have lots of music I've purchased from Itunes...and they show in my account.  But only some of them have the cloud next to them.  The rest say "downloaded" and it won't let me download them again.

    I'm trying to get itunes up and running on new computer. I have lots of music I've purchased from Itunes...and they show in my account.  But only some of them have the cloud next to them.  The rest say "downloaded" and it won't let me download them again.

    I believe that all audiobooks are supplied to Apple by audible.com, so I assume that it's them requiring the one-time only download. This is the link for contacting iTunes Support : http://www.apple.com/support/itunes/contact/ - click on Contact iTunes Store Support on the right-hand side of the page, then Purchases, Billing & Redemption

  • I tried creating a new folder and quickly moving Newsstand into it, but Newsstand is grayed out, and could not be moved. Any other ideas how to get rid of it?

    I tried creating a new folder and quickly move Newsstand into it, but it is grayed out and cannot be moved. Any other ideas how to get rid of it?

    You cannot

  • HT5373 How do I enable a calendar subscription in my iCloud calendar? I'm using a Windows laptop (Home Office 7) and am trying to get the rugby and footfall fixtures to appear on my iCloud calendar.  Thanks for your help.

    How do I enable a calendar subscription in my iCloud calendar? I'm using a Windows laptop (Home Office 7) and am trying to get the rugby and footfall fixtures to appear on my iCloud calendar.  Thanks for your help.

    I suspect you had the same issue I did and downloaded the 64-bit version of the OpenSC libraries, but your firefox is 32-bit. You can see the opensc-pkcs11.dll in the System32 folder via windows explorer, but when you browse that directory via firefox to add the module, you are acutally being redirected to the SysWOW64 directory. Try intstalling the 32-bit OpenSC libraries, and adding the appropriate library from the C:\Windows\SysWOW64 directory.

  • I bought a new iPhone 6 and switched carriers and am trying to get my voicemail and instant messages ported over to the new phone

    I bought a new iPhone 6 and switched carriers and am trying to get my voicemail and instant messages ported over to the new phone

    Restore from your backup.  For voicemail contact your cell phone provider.

  • Trying to get new software and ipad reads iOS 5.1.1 your software is up to date  can't get 6 iPad, iOS 5.1.1

    PLease help me.    
    trying to get new software and ipad reads iOS 5.1.1 your software is up to date  can't get 6
    iPad, iOS 5.1.1
    trying to get new software and ipad reads iOS 5.1.1 your software is up to date  can't get 6

    The original iPad can't be updated past 5.1.1.
    (86600)

  • I'm trying to get onto facetime and I keep getting a message saying the server encountered an error processing registration, can anyone tell me why?

    I'm trying to get onto facetime and I keep getting a message saying the server encountered an error processing registration please try again later. Can anybody tell me what is going on?

    I have read over and actioned ALL recommendations many times over, and still get the Facetime error..! I have reset Host file, looked for iphone certificates, set time/date to auto, checked for suspect DNS entries, cleared caches etc etc. It's become a very fustrating problem. Worked fine for a long time but then suddenly stopped.
    I wish I could find the solution...

  • HT3606 I have Mac OS X version 10.5.8 and so im wondering what is the next step i need to get. i have tried to get snow leopard and other things and not having any lukck . can any one help me out pls.

    I have Mac OS X version 10.5.8 and so im wondering what is the next step i need to get. i have tried to get snow leopard and other things and not having any lukck . can any one help me out pls.

    If your Mac meets these requirements:
    http://support.apple.com/kb/SP575
    then you can order a Snow Leopard disk and install it.
    http://store.apple.com/us/product/MC573Z/A/mac-os-x-106-snow-leopard
    Ciao.

  • I keep trying to get onto appstore and its says my apple ID is disabled. Why is this happening and how can i fix it?

    keep trying to get onto appstore and its says my apple ID is disabled. Why is this happening and how can i fix it?

    This forum is for questions from those managing sites on iTunes U, Apple's service for colleges and universities to post educational material in the iTunes Store. You'll be most likely to get help with this issue if you ask in the general iTunes forums.
    Regards.

  • Possible to get JComboBox before and after chaged value?

    Hi,
    I have a JComboBox... whenever the JComboBox value change is it possible to get the before and after changed value? For example:
    Let says the JComboBox is showing "One" and the user change it to "Three" after the user chged... I want to System.out.println before chged value ("One") and aft chged value ("Three")
    I tried:
    put in some code in the itemStateChanged() method... but no success...
    Can someone pls provide some pointer or sample code...
    Thank you for your time...

    Ok, I lost half a day on this (novice problem), but I arranjed a solution that resolve the problem totally. There is the code:
    YourComboBox.addFocusListener(new java.awt.event.FocusAdapter()
            int aux_selected;
            // if YourComboBox gains Focus
           public void focusGained(java.awt.event.FocusEvent fe)
                // get index value of selected element
               aux_selected= YourComboBox.getSelectedIndex();
               // create a variable for storing de ItemListener
              ComboBListener = new java.awt.event.ItemListener() {
                   public void itemStateChanged(java.awt.event.ItemEvent e)
                       if(e.getStateChange()==java.awt.event.ItemEvent.SELECTED)
                           // compares the selected value with the old one
                           if (aux_selected!=YourComboBox.getSelectedIndex())
                           System.out.println("ComboBox Changed !");
               // add the variable Listener to your Combo
               YourComboBox.addItemListener(ComboBListener);
           // if focus is lost
           public void focusLost(java.awt.event.FocusEvent fe)
              // remove the itemListener from the combobox
             YourComboBox.removeItemListener(ComboBListener);
    //Put the Listener variable outside
    private java.awt.event.ItemListener ComboBListener; //----------------------------------------------------------------------------------------------------
    You only have to change YourComboBox by the name of the combobox.
    To all people that help this forum (specially from PORTUGAL) and all java people: YOU ARE DOING A GREAT JOB

  • HT4623 I AM TRYING TO UPDATE MY IPHONE4 AND WHEN I GO INTO THE SOFTWARE UPDATE IT WONT LOAD ANYTHING.

    I AM TRYING TO UPDATE MY IPHONE4 AND WHEN I GO INTO THE SOFTWARE UPDATE IT WONT LOAD ANYTHING. IT JUST SAYS CHECKING FOR UPDATE

    The update servers are still under pretty heavy load, so it's possible it's nothing on your end. Are you trying to do it over the air or through iTunes?
    = L.I.

Maybe you are looking for

  • Where can I buy replacement headphones for my Zen Mi

    Anybody know where I can get a replacement pair of headphones..or an alternati've that are just as good.....mine have gone in one ear.....and itz not the headphone jack..i checked. The creative shop is pretty useless, unless I really missed something

  • What are the ROLES & Responcibilites of a SAP Tester

    Hi, I would like to know the roles and responcibilites of a SAP tester what kind of things will do by Manual Testing as well as Automation Testing by using ECATT Thankyou

  • Trigger output before release PO

    Hey all the experts, Is there a way to trigger an output before release a PO? Regards, Santthi.

  • J1IEX Part 2 Posting !!

    HI We capture excise during MIGO and without posting part2 we try to do MIRO then the system should give error/warning "part2 posting not done yet" Where do we activate this ? Thank You

  • Can't install Centrale for Windows 7

    I've tried several times to install Centrale to connect my Zen 8BG?to my pc running Windows 7 64-bit. However, I keep getting the same error message: "Source file not found: C:\PROGRA~3{C8754~\OFFLINE\F778FA6\905FE969ChnTag. exe. Vertify that the fil