Simple Date Arithmetic in Oracle APEX - oracle

What I need to do is, in my mind, incredibly simple. So simple in fact that it is probably obvious and therefore I cannot seem to find any place that documents how to do this.
What I need is just to take the value of a Date Picker page Item (:P1_DATE_1) and through a dynamic action set the value of a second Date Picker page Item (:P1_DATE_2). The value of (:P1_DATE_2) should be 2 years, or 730 days, greater than the value of (:P1_DATE_1). So all I need is a simple '+730' expression right?
I had this working using sysdate as the start date for this calculation. The below PL/SQL expression gave the appropriate output:
to_char(sysdate + 730,'dd-MON-rr')
But then I could not get it to translate to accepting the value of the page item. I already have the actions and everything set up I just can't get it to function when I try substituting :P1_DATE_1 for sysdate. I have tried as many different manifestations of that expression using the page item but it does not populate the 2nd page item.
Sorry for the probably stupid question but if anyone could help out I would appreciate it. Thanks!

#Justin Cave is correct: all values in page items are treated as varchar2
As for your dynamic action, this is what i've set up:
Region:
Dynamic action (date 2 add):
True action:

Are you getting an error? If so, what error? Since page items in APEX are always strings, you need to convert them to dates before doing date arithmetic on them. Something like this should work assuming that P1_DATE_1 is in the DD-MON-RR format as well.
to_char( add_months( to_date( :P1_DATE_1, 'DD-MON-RR' ),
24 ),
'DD-MON-RR' )
If you're not getting an error and the second item just isn't defaulting, my guess is that you have an order of operations problem. Are you certain that the first item is actually set to a non-NULL value when the initialization code for the second item is run? If you're trying to set the value in the second item based on a value that the human selects at runtime in the first date picker, you'd either need to submit the page or you'd need a bit of Javascript.

Related

SSRS Cache Report Parameters Previous Week

Is there a way to set the Parameter Values in the Cache Refresh Plan window to use the previous Sunday? The field is a Date/Time field and will not let me enter code such as =DateAdd(DateInterval.Day, -7,DateAdd(DateInterval.Day, 1-Weekday(today),Today)). It is looking for date format. Thanks in advance
I'm unaware of any parameter caching options. However, you should be able to get a default value to work. Perhaps the expression below will work.
=DateAdd(dd,1- DatePart(dw, CDate(Today())), CDate(Today()))
If you still can't get it to work, another option would be to add a data set that spits out the value. You could use something like:
SELECT DATEADD(dd,1- DATEPART(dw, CAST(GETDATE() AS DATE)), CAST(GETDATE() AS DATE))

Number filed is not processed correctly

I use Oracle Apex, I want that my 'display only field' is updated automatically. Well, when I use dynamic actions like this select 5 * price from ... or, for instance, random values, it works absolutely correctly, the field is filled with the value 5 * price (or set new random value). But when I use select :P4_COUNT * price from, the filed is empty. I think that the problem in :P4_COUNT (it is a number field) but I do not know what to do.
In the Dynamic Action, look for "Items to Submit" (usually under the SQL or PL/SQL code). Put the names of items that need to be submitted to session state prior to running the code. Also, note that currently, all values in session state are strings. So it's probably best to use to_number if you need a number.

OBIEE: Casting String to date then date to string

FILTER("source"."recordCount" USING "source"."snapshot_date" =
EVALUATE('TO_CHAR(%1, ''YYYYMMDD'')', TIMESTAMPADD(SQL_TSI_DAY, -7, EVALUATE('TO_DATE(%1, %2)', "source"."snapshot_date" , 'YYYYMMDD'))))
So i have this piece of code here. I know some will say "Just use the AGO function" But somehow it's causing problems because of it's connection with other tables so what I'm trying to achieve here is like a remake. The process goes this way:
The snapshot_date there is actually in varchar format and not date. So it's like "20131016" and I'm trying to change it to a date then subtract 7 days from it using the TIMESTAMPADD function and then finally returning it back to varchar to use it with FILTER.
This snippet somehow works when testing the FILTER using hardcoded values like "20131016" for example but when tested out with the code above all the row are blank. On paper, the process i assumed would happen goes lke this. "20131016" turns to a date with a format of 20131016 (yyyymmdd) and then less 7 days: 20131009 and then turned into char again "20131009" to be used in the filter.
But somehow that doesn't happen. I think the data format is not applying either to the string->date or the date->string conversion. which results to the values not getting a match at all.
Anyone have any idea what's wrong with my code?
By the way I've already tried to use CAST instead of EVALUATE or TO_TIMEDATE with the same result. Oh and this goes to the formula of the column in BMM.
Thanks
You might get some clues by looking at the SQL generated by the BI Server. I can't see any issues with your column expression, so I wouldn't limit your debugging to that alone.
A query returning nulls is often caused by incorrect levels being set (especially on logical table sources, but potentially on a measure column too). This will often result in some form of SELECT NULL FROM ... in the physical SQL.
Try this :
FILTER("source"."recordCount" USING "source"."snapshot_date" =
EVALUATE('TO_CHAR(%1, %2)', TIMESTAMPADD(SQL_TSI_DAY, -7, EVALUATE('TO_DATE(%1, %2)', TO_CHAR("source"."snapshot_date" , 'YYYYMMDD') , 'YYYYMMDD')) , 'YYYYMMDD'))

ApplySimple Formula for Current year in Microstrategy

I'd like to nkow how to extract the current year using an ApplySimple formula for an Oracle DB being used on microstrategy.
The formula I tried is :
ApplySimple("to_char(SYSTIMESTAMP,'Year')")
Even though this formula is a valid one - when I try using this formula to create an attribute , and display it in a report , I get no results( blank column )
What I'm essentially trying to do is compare this current year attribute to another year attribute and create afilter based on this.
Any help wll be much appreciated!
I wouldn't bother with ApplySimple at all, it can be done directly in a filter.
Qualify on the attribute form that you want to compare (presumably the Year ID), and then in the Operator section, change the dropdown from its default 'Value' to 'Custom'.
This allows you to use MicroStrategy's built-in functions in your qualification. The current year can be returned by putting:
Year(CurrentDate())
for your comparison.
Are you sure you want to compare the string "twenty fourteen"? Because, TO_CHAR(SYSTIMESTAMP,'year') would return that. Instead, you might need the YYYY format :
TO_CHAR(SYSTIMESTAMP,'YYYY')
But that is still a string.
You probably need NUMBER :
So, I would prefer, EXTRACT(YEAR FROM SYSTIMESTAMP) Because, this will return 2014 as NUMBER.
SQL> SELECT EXTRACT(YEAR FROM SYSTIMESTAMP) FROM DUAL;
EXTRACT(YEARFROMSYSTIMESTAMP)
-----------------------------
2014
Formula
If the attribute is NUMBER data type, you might need this formula :
ApplySimple("EXTRACT(YEAR FROM SYSTIMESTAMP)")

Oracle: error while trying to use formulas

I created an element with an input value of type "Day" , when i write a formula i get this error.
Any idea what's wrong?
APP-FF-33232:
EATC_EXTRA_DAYS_ENTRY_EFFECTIVE_DATE_ENTRY_VALUE has null or not found allowed, but no
default set specified.
Cause: If a Database Item has
null allowed, or not found allowed,
then the item must also specify a
default set to be used to provide
default values in the event of these
occurring. The item named has one of
these conditions allowed, but the
default set column in the
FF_DATABASE_ITEMS table is null.
Action: Please refer to your
local support representative.
-
I'm not an expert in Oracle Apps (to say the least) but the error message is fairly clear. You - or someone - have written a Fast Formula which references a database column EATC_EXTRA_DAYS_ENTRY_EFFECTIVE_DATE_ENTRY_VALUE. Apparently this column can be nullable, in which case your Formula needs to provide a default value. Something like:
default for EATC_EXTRA_DAYS_ENTRY_EFFECTIVE_DATE_ENTRY_VALUE is 01-JAN-2010
Or perhaps you can use SYSDATE or CURRENT_DATE rather than a fixed value.
Solution to error: You called database item in Fast formula,
you need to initialize the date to specific date
alias EATC_EXTRA_DAYS_ENTRY_EFFECTIVE_DATE_ENTRY_VALUE as day
default for day is 01-jan-2010

Resources