简体   繁体   中英

Conversion of Date for direct sql query in OBIEE using presentation variable

I am trying to achieve this use case: when there is no date picked I want to show all the results but when I have date picked I want it to filter.

fyi: the date getting picked are YYYY-MM-DD HH24:MI:SS in the presentation variable, but the date format in my query is dd-mon-yy. So when I need to convert the value of the presntation varible to dd-mon-yy. OBIEE doesnt like when I play around with the values, and the BI server does not let me look at the error message. I dont have access to change the format on the server level so my only option is to use formulas

I'm new to presentation variable. ALso I need you'll to remember if there is no date selected in the prompt I would want all values returned

code:

and 
   ( (       main_query.schd_compare >= (@{pv_task_sch_st_date}['@']{NVL(main_query.schd_compare,'None')})

        )
       AND (
            main_query.schd_compare  <= (@{pv_task_sch_end_date}['@']{NVL(main_query.schd_compare,'None')})
         ) ) 

I need help with syntax for obiee

Inside the database, it doesn't care if a date is "DD Mon YY" or "YYYY-MM-DD HH24:MI:SS". Those are just formatting, and the actual bit value of that date will be the same. So if both "dates" are actually a date datatype, then you can just use something like:

....
AND ( 
   (       
     main_query.schd_compare >= NVL(pv_task_sch_st_date,main_query.schd_compare)
   )
   AND 
   (
     main_query.schd_compare  <= NVL(pv_task_sch_end_date,main_query.schd_compare)
   )
) 

That's if your pv_task_sch_???_date are passed as NULL values when not selected. Oracle does seem to treat empty strings and NULL the same in comparisons like this, but you it can be hard to debug if you get in the habit of relying on NULL and '' being the same.

As for your query, my guess is that your pv_task... values are actually being passed to your query as a some sort of string. If that's the case, then you'll need to put a TO_DATE() around your pv_task... variables.

Take a look at https://dbfiddle.uk/?rdbms=oracle_11.2&fiddle=2066b2005a22769e785815f6b03750a1 . I stepped through a few examples of how your dates can be treated.

I did say earlier that the database doesn't care when format your date is in. And it is stored the same, no matter the format. But when you're using TO_DATE() or other similar functions, Oracle wants you to specify the proper mask of your data. If you send "01 Jan 99" to TO_DATE() , Oracle needs to know how to interpret that value. So you tell it that the string is "DD Mon YY". You can't do TO_DATE('2018-09-10','YYYY-MM-DD HH24:MI:SS') because my input doesn't have a time component. ( I would also caution about using 2-digit years. )

By the way, I hate dates. And dealing with dates in Oracle reinforces that hatred.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM