Displaying diff dates using PL/SQL expression for 'display only' item ?

Hi ,
I am having a display only item -- :P2_FROM_Date . If its Thu,Fri,Sat or Sun I want to set the date as the last Monday's date . If its Mon,Tue or Wed then it should be the present Monday's date .
E.g: Today is Friday and the last Monday was on 18th .
So for yesterday , today,tomorrow and Sunday , the date should be displayed as 18-JUN-2012.
From the coming Monday to Wednesday , the date should of be the coming Monday i.e , 24-JUN-2012
I tried it doing under 'Source ' of item using PL/SQL expression and PL/SQL function body. Not working
Can someone help ?
Thanks & Regards
Umer

Nice1 wrote:
declare
lv_date number;
begin
select to_char(sysdate,'D') into lv_date from dual;
if lv_date=2 then
:P2_FROM_DATE := to_char(sysdate-1);
end if;
end;I tried this under " PL/SQL function body " in "Source " tab of the item P2_FROM_DATE
When I run this , nothing is displayed corresponding to the item P2_FROM_DATEExactly as expected. This code will only set a value for <tt>P2_FROM_DATE</tt> when run on Mondays in territories where the first day of the week is Sunday, and when run on Tuesdays where Monday is the first day of of the week:
SQL> var P2_FROM_DATE varchar2(30)
SQL> alter session set nls_date_format='Dy DD-MON-YYYY';
Session altered.
SQL> select sysdate from dual
SYSDATE
Mon 25-JUN-2012
SQL> alter session set nls_territory='AMERICA';
Session altered.
SQL> declare
  2  lv_date number;
  3  begin
  4  select to_char(sysdate,'D') into lv_date from dual;
  5  if lv_date=2 then
  6  :P2_FROM_DATE := to_char(sysdate-1);
  7  end if;
  8  end;
  9  /
PL/SQL procedure successfully completed.
SQL> print p2_from_date
P2_FROM_DATE
Sun 24-JUN-2012
SQL> alter session set nls_territory='UNITED KINGDOM';
Session altered.
SQL> exec :p2_from_date := null
SQL> declare
  2  lv_date number;
  3  begin
  4  select to_char(sysdate,'D') into lv_date from dual;
  5  if lv_date=2 then
  6  :P2_FROM_DATE := to_char(sysdate-1);
  7  end if;
  8  end;
  9  /
PL/SQL procedure successfully completed.
SQL> print p2_from_date
P2_FROM_DATE
SQL>Hence the questions about language above.
>
I am having a display only item -- :P2_FROM_Date . If its Thu,Fri,Sat or Sun I want to set the date as the last Monday's date . If its Mon,Tue or Wed then it should be the present Monday's date .
E.g: Today is Friday and the last Monday was on 18th .
So for yesterday , today,tomorrow and Sunday , the date should be displayed as 18-JUN-2012.
From the coming Monday to Wednesday , the date should of be the coming Monday i.e , 24-JUN-2012
>
The coming Monday is 25-JUN-2012.
Aren't these rules equivalent to "Monday this week, where Monday is the first day of the week"? In which case the PL/SQL Expression you require is:
trunc(sysdate, 'iw')For example:
SQL> with t as (
  2    select date '2012-06-21' + level d from dual connect by level <= 17)
  3  select
  4            d
  5          , trunc(d, 'iw')  monday
  6  from
  7            t;
D               MONDAY
Fri 22-JUN-2012 Mon 18-JUN-2012
Sat 23-JUN-2012 Mon 18-JUN-2012
Sun 24-JUN-2012 Mon 18-JUN-2012
Mon 25-JUN-2012 Mon 25-JUN-2012
Tue 26-JUN-2012 Mon 25-JUN-2012
Wed 27-JUN-2012 Mon 25-JUN-2012
Thu 28-JUN-2012 Mon 25-JUN-2012
Fri 29-JUN-2012 Mon 25-JUN-2012
Sat 30-JUN-2012 Mon 25-JUN-2012
Sun 01-JUL-2012 Mon 25-JUN-2012
Mon 02-JUL-2012 Mon 02-JUL-2012
Tue 03-JUL-2012 Mon 02-JUL-2012
Wed 04-JUL-2012 Mon 02-JUL-2012
Thu 05-JUL-2012 Mon 02-JUL-2012
Fri 06-JUL-2012 Mon 02-JUL-2012
Sat 07-JUL-2012 Mon 02-JUL-2012
Sun 08-JUL-2012 Mon 02-JUL-2012
17 rows selected.
SQL> alter session set nls_territory='AMERICA';
Session altered.
SQL> alter session set nls_date_format='Dy DD-MON-YYYY';
Session altered.
SQL> with t as (
  2    select date '2012-06-21' + level d from dual connect by level &lt;= 17)
  3  select
  4            d
  5          , trunc(d, 'iw')  monday
  6  from
  7            t;
D               MONDAY
Fri 22-JUN-2012 Mon 18-JUN-2012
Sat 23-JUN-2012 Mon 18-JUN-2012
Sun 24-JUN-2012 Mon 18-JUN-2012
Mon 25-JUN-2012 Mon 25-JUN-2012
Tue 26-JUN-2012 Mon 25-JUN-2012
Wed 27-JUN-2012 Mon 25-JUN-2012
Thu 28-JUN-2012 Mon 25-JUN-2012
Fri 29-JUN-2012 Mon 25-JUN-2012
Sat 30-JUN-2012 Mon 25-JUN-2012
Sun 01-JUL-2012 Mon 25-JUN-2012
Mon 02-JUL-2012 Mon 02-JUL-2012
Tue 03-JUL-2012 Mon 02-JUL-2012
Wed 04-JUL-2012 Mon 02-JUL-2012
Thu 05-JUL-2012 Mon 02-JUL-2012
Fri 06-JUL-2012 Mon 02-JUL-2012
Sat 07-JUL-2012 Mon 02-JUL-2012
Sun 08-JUL-2012 Mon 02-JUL-2012
17 rows selected.Also note that using the item source properties will only set the <tt>P2_FROM_DATE</tt> in the rendered page, not in session state.

Similar Messages

  • Create Test data using T-SQl script for each row

    Hi team,
    I am looking for a sql code snippet which read data from below table
    UserId username contact
     1      Anil    111
     2      Sunil   222
    and insert data to below table with some test data appending sequence number 1,2,3 for only City and Email. Both are different tables
    and does not have any referencial integrity
    No of records inserted for user is configurable for example count = 3
    Username  City  Email
    Anil      city1 email1
    Anil      city2 email2
    Anil      city3 email3
    Sunil      city1 email1
    Sunil      city2 email2
    Sunil      city3 email3

    DECLARE @cnt INT=3
    DECLARE @Users TABLE(UserId INT, UserName VARCHAR(99),Contact INT)
    INSERT INTO @Users VALUES
    (1,'Anil',111),
    (2,'Sunil',222)
    SELECT UserName,'city'+CAST(num AS varchar(10)) city FROM @Users
    CROSS APPLY
    SELECT TOP(@cnt) number +1 AS num
                    FROM master..spt_values
                    WHERE type = 'P') AS Der
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • Pl/sql expression for default value

    I'm trying to run this simple script as a default value using pl/sql expression, but I keep getting this error. THe select statement itself works fine as a sql statement source value, but will not work as a pl/sql exression as a default value. This (:P33_SYSUSERID_CREATED_BY ) is the field name on the form. Any ideas?
    begin
    select a.id || ', ' || A.NAME_LAST into :P33_SYSUSERID_CREATED_BY from S_USERSV a where a.name_last = 'HAMMAKER';
    end;
    Error ERR-9132 Error in PLSQL expression for item default code, item=P33_SYSUSERID_CREATED_BY
    OK
    ORA-06550: line 1, column 27: PLS-00103: Encountered the symbol "BEGIN" when expecting one of the following: ( - + case mod new not null avg count current exists max min prior sql stddev sum variance execute forall merge time timestamp interval date pipe

    Sudha,
    For a default value type of PL/SQL Expression, you could create a function that accepts an input and returns a value. If the function (not a procedure) is named GET_REFNO, you would call it using an expression in the default value field like:
    get_refno(:P3_REFTYPE)
    For a default value type of PL/SQL Function Body, you could call your existing procedure with a default value like:declare
        l_value varchar2(32767);
    begin
        get_refno(:P3_REFTYPE, l_value);
        return l_value;
    end;Scott

  • Write / store xml data in Xe and retrieve stored data using pl/sql

    Hi to all,
    i'm searching a tutorial on:
    A - how to write / store xml data in Xe and retrieve stored data using pl/sql
    I don't want to use other technologies, because i use htmldb and my best practice is with pl/sql.
    I was reading an ebook (quite old maybe) however it's about oracle 9 and it's talking about xmltype:
    1 - I don't understand if this is a user type (clob/varchar) or it's integrated in Oracle 9 however i will read it (it's chapter 3 titled Using Oracle xmldb).
    Please dont'reply here: i would be glad if someone can suggest me a good tutorial / pdf to achieve task A in Oracle XE.
    Thanx

    Thank you very much Carl,
    However my fault is that i've not tried to create the table via sql plus.
    Infact i was wrong thinking that oracle sql developer allows me to create an xmltype column via the create table tool.
    however with a ddl script like the following the table was created successfully.
    create table example1
    keyvalue varchar2(10) primary key,
    xmlcolumn xmltype
    Thank you very much for your link.
    Message was edited by:
    Marcello Nocito

  • Replace ' with ' in my data using pl/sql

    I want to replace all occurrence of special characters like &apos; with ' in my data using pl/sql.
    How can I achieve this?

    Thank you for your quick reply. My code is:
    DECLARE
    firstname varchar2(200) := 'cccc&a p o s;dddd'; ---> Please remove spaces between a p o s. Combine them as apos
    lastname varchar2(200) := 'eeee';
    BEGIN
    dbms_output.put_line('Before changing : firstname :' || firstname);
    dbms_output.put_line('After changing: firstname :' || replace(LastName, "&apos;" , "'") );
    END;
    When I run this in sqlplus, I see:
    SQL> @EscapeCharTesting.sql
    Enter value for apos:
    So I want to change all occurences of "&a p o s;" to CHR(39)

  • Can we use Data Pump to export data, using a SQL query, doing a join

    Folks,
    I have a quick question.
    Using Oracle 10g R2 on Solaris 10.
    Can Data Pump be used to export data, using a SQL query which is doing a join between 3 tables ?
    Thanks,
    Ashish

    Hello,
    No , this is from expdp help=Y
    QUERY                 Predicate clause used to export a subset of a table.
    Regards

  • I have been using final cut express for years and now want to switch to final cut studio 3. do I have to remove final cut express before installing final cut studio 3 or can I have them both installed at the same time on one computer?

    I am using a macpro 12 core computer
    I have been using final cut express for years and now want to switch to final cut studio 3. do I have to remove final cut express before installing final cut studio 3 or can I have them both installed at the same time on one computer?

    You can have them both on the same computer as I and many others have done for years.
    Just go ahead and install FCS 3 normally.
    There will be absolutely no problems.

  • How to display today date using formcalc

    Hi all,
    how to display today date using formcalc, eg April 20, 2009?
    Thanskks

    Num2Date(Date(), "DD/MMM/YYYY", "de_GB")

  • Using Final Cut Express for video editing without attaching external device

    Hello,
    I am a newbie to Final Cut Express as well as Mac's in general. I am wanting to use Final Cut Express for video editing of files, but without an attached camera. Is there any way to have Final Cut Express startup without having it prompt for an external A/V device? I just want to do some basic editing and use the chroma key feature. Can anyone help?
    Greatly Appreciated,
    Knight2000
    iMAC   Mac OS X (10.4.9)  

    Hi Zak,
    Unfortunately, I've tried that and I get into an issue that was addressed in this posting: http://discussions.apple.com/thread.jspa?threadID=836595&tstart=120 where FCE will show the splash screen and then the program doesn't start. I then have to delete FCE preferences and then I will get the Easy Setup dialog box prompt me again for choosing the external device.
    I am looking for a way to use FCE for video editing of files that I already have on my computer that I created using iClone software and is in .avi, or .mp4 format. I get FCE to work one time without the external device actually being attached, but then when restarting the program I get the dialog box asking for the external device and if it's not there, the program just closes, and to get it to work again, I have to delete the preference files and go through the process all over again which is time consuming especially when this is at work. If FCE is not the right program, can anyone suggest a good video editing program that doesn't require an external device and is as good or better than FCE?
    Thanks again for your help and support,
    Knight2000
    iMAC   Mac OS X (10.4.9)  

  • I now have internet thru AT&T Uverse with their wireless router.....do I still need to use my Airport Express for my 2 MACS or can I just unplug it?

    I now have internet thru AT&T Uverse with their wireless router.....do I still need to use my Airport Express for my 2 MACS or can I just unplug it?

    You can just unplug the express and use the Uverse wireless or ethernet directly to it.

  • HT3728 I do not need another wireless network but want to use the airport express for printer access only.  Can this be done and how?

    I do not need another wireless network but want to use the airport express for printer access only.  Can this be done and how?

    You can configure the AirPort Expess to "Join a wireless network" and enable the Ethernet port so that Ethernet devices will be able to connect.
    In order to print from the iOS devices, you will need to have an application like Printopia installed on your Mac. The Mac must be active when you want to print.
    More details here: Printopia - AirPrint to Any Printer - Print from iPad - Print from iPhone ...
    There is a free trial available for Printopia, so make sure that it will work before you buy the AirPort Express.

  • √using successfully airport express for internet/ when hooking up new airport extreme light glows green, but does NOT appear in devices seen????airport wifi devices

    using sucessfully airport express for internet
    when hooking up new airport extreme light glows green, but does NOT appear in devices sesn in 5.6 airport wifi devices
    wanting to use extreme at base and express in another part of the house

    How is the express getting internet? What modem is it plugged into?
    How is the extreme setup? New extreme cannot be setup with 5.6 utility.. you must use latest 6.3. Which also means you cannot setup from computer using less than Lion .. or you must use iOS with latest utility but it has limited configuration cf the computer version.
    IPv6 is also needed.. turn on local link.

  • SQL Expression for date conversion - version XI

    I am trying to convert a number field to a date field in order to use it in a date parameter in Infoview. The database field is in a 15 digit DTM format but is stored as a number. There is also a zero stored in the database field. When I try to create the date SQL Expression I get this error: Error in compiling SQL Expression: Failed to retrieve data from the database. Details: ORA-01840: input value not long enough for date format. How can I get the SQL Expression to not look at the zero? I tried putting a statement in my Record Selection to not pull any zero fields but that doesn't work. Any ideas? Thanks! Kelley

    Hi Kelly,
    It's been a while since I used Info View, so if it's about registering, etc. I won't know the
    answer.
    Did you link it ?  Have you tested that it should even return data ? 
    Check the filtering, etc in a query builder to make sure.
    Have you tested the sub report by running it by itself ? (just add a value to the parameter
    field request)
    Do you have suppression formulas in the sub report ?
    Is the section of the main report that is holding the sub report
    free of "suppresion" formulas ?

  • Using pl/sql function for each day between two dates.

    Hi,
    create TABLE EMP(
    ID_EMP NUMBER,
    DT_FROM DATE,
    DT_TO DATE,
    CREATE_DATE DATE);
    into EMP(ID_EMP, DT_FROM, DT_TO, CREATE_DATE)
    Values(100, TO_DATE('07/01/2008 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('04/30/2010 00:00:00', 'MM/DD/YYYY HH24:MI:SS'),TO_DATE('05/08/2009 14:11:21', 'MM/DD/YYYY HH24:MI:SS'));
    I have a function called  elig_pay_dates(date p_date), which returns the code for  person payment eligibility for a particular date. For paid dates it's 'P' and for unpaid dates it's 'N'.
    How can I check this function between two dates for each day. Example : 07/01/2008 to 04/30/2010.
    By using this function with select I needs to display the dates when there is a change in status.
    I am expecting data in following manner from above logic(this is example):
    07/01/2008 --- 07/01/2009 ---'P'
    07/02/2009 -- 07/25/2009 ----'N'
    07/26/2009 -- 01/01/2010 ---'P'
    01/02/2010 -- 01/13/2010 --'N'
    01/14/2010 -- 01/18/2010 --'P'
    01/19/2010 -- 04/30/2010 -- 'N'
    I thought of looping for each day date but that seems to be expensive for online application. Is there any way that I can achieve this requirement with sql query ?
    Thanks for your help,

    Certainly not the best way to code the requirement, but it does achieve the result you are looking for in a fairly quick time
    create or replace
    function test_ret_paid_unpaid (p_date in date)
    return varchar2
    is
      v_ret     varchar2(1);
    begin
      if ( (p_date between to_date('07/02/2009', 'MM/DD/YYYY') and to_date('07/25/2009', 'MM/DD/YYYY') ) or
           (p_date between to_date('01/02/2010', 'MM/DD/YYYY') and to_date('01/13/2010', 'MM/DD/YYYY') ) or
           (p_date between to_date('01/19/2010', 'MM/DD/YYYY') and to_date('04/30/2010', 'MM/DD/YYYY') )
        then v_ret := 'N';
      else
        v_ret := 'Y';
      end if;
      return v_ret;
    end;
    Wrote file afiedt.buf
      1  with get_paid_unpaid as
      2  (
      3    select dt_from start_date, dt_to end_date, dt_from + level - 1 curr_date, test_ret_paid_unpaid(dt_from + level - 1) paid_unpaid,
      4           row_number() over (order by dt_from + level - 1) rn_start,
      5           row_number() over (order by dt_from + level - 1 desc) rn_end
      6      from test_emp
      7    connect by level <= dt_to - dt_from + 1
      8  ),
      9  get_stop_date as
    10  (
    11  select start_date init_date, end_date, curr_date, paid_unpaid,
    12         case when paid_unpaid != lag(paid_unpaid) over (order by curr_date) or rn_start = 1 or rn_end = 1
    13          then curr_date
    14          else null
    15         end start_date,
    16         case when paid_unpaid != lead(paid_unpaid) over (order by curr_date) or rn_start = 1 or rn_end = 1
    17          then curr_date
    18          else null
    19         end stop_date
    20    from get_paid_unpaid
    21  )
    22  select period, paid_unpaid
    23    from (
    24  select init_date, curr_date, start_date, end_date, stop_date,
    25         case when paid_unpaid = lead(paid_unpaid) over (order by curr_date)
    26                then nvl(start_date, init_date) || ' - ' || lead(stop_date, 1, end_date) over (order by curr_date)
    27              else null
    28         end period,
    29         paid_unpaid
    30    from get_stop_date
    31   where stop_date is not null or start_date is not null
    32         )
    33*  where period is not null
    12:06:10 SQL> /
    PERIOD                                             PAID_UNPAID
    01-JUL-08 - 01-JUL-09                              Y
    02-JUL-09 - 25-JUL-09                              N
    26-JUL-09 - 01-JAN-10                              Y
    02-JAN-10 - 13-JAN-10                              N
    14-JAN-10 - 18-JAN-10                              Y
    19-JAN-10 - 30-APR-10                              N
    6 rows selected.
    Elapsed: 00:00:00.35

  • Entity DATE type attribute : Derieved From SQL Expression for date format

    Hi,
    I want to set one of the Entity's Date Attribute with specific format , for e.g DD-MM-YYYY
    I see a Derieved From SQL Expression checkbox, how can I define the SQL Expression
    can I use TO_DATE(EMP_START_DATE,'DD-MM-YYYY'), I want to insert a date in that format, when I am creating a row using viewObject.createRow()
    Java Type is oracle.jbo.domain.Date which take YYYY-MM-DD as a string, I do not want to use this format
    Thanks,

    Here is a solution, but I am sure it is not the best one. It will work in a hurry. Maybe you can create a helper method to generalize this conversion until something more succinct comes along for US:
    This code assumes an import of jbo.oracle.domain.Date.
        public void updateDateTest () {
            AddressesViewImpl lVO = (AddressesViewImpl)this.getAddressesView1();
            AddressesViewRowImpl lRow = (AddressesViewRowImpl)lVO.first();
            System.out.println("create date for current record is currently: " +
                               lRow.getCreationDate());
            java.util.Date today = new java.util.Date();
            SimpleDateFormat dateFormat =
                new SimpleDateFormat("dd-MM-yyyy");
            SimpleDateFormat jboDateFormat =
                new SimpleDateFormat("yyyy-MM-dd");
            String lSampleDateString = "15-04-2010";
            java.util.Date lSampleDate = null;
            try {
                lSampleDate = dateFormat.parse(lSampleDateString);
            } catch (ParseException e) {
                System.out.println("Parsing exception thrown:  " + e.getMessage() +
                                   "\n ==> caused by \n==>"+ e.getCause().getMessage());
                lRow.setCreationDate(new Date(jboDateFormat.format(lSampleDate)));
            System.out.println("about to commit; create date for current record is currently: " +
                               lRow.getCreationDate());
            this.getDBTransaction().commit();
            System.out.println("resetting to some other date; create date for current record is currently: " +
                               lRow.getCreationDate());
                lRow.setCreationDate(new Date(jboDateFormat.format(today)));
            this.getDBTransaction().commit();
        }I defined this code in my Application Module Impl file and ran it with the BC tester. Here was its output:
    Mar 18, 2010 8:27:54 AM oracle.jbo.jbotester.MainFrame main
    INFO: BC4J Tester started.
    Source breakpoint occurred at line 66 of FusionExperimentsAMImpl.java.
    create date for current record is currently: 2009-02-02 12:09:54.0
    about to commit; create date for current record is currently: 2010-04-15
    resetting to some other date; create date for current record is currently: 2010-04-15I spent a little time looking around the forum for additional solutions. I think several years ago I even wrote a blog entry on this subject. If I remember how to do this right I will amend with more information.

Maybe you are looking for