Evaluate Function in case when
hi,
i want to use evaluate function in case when statement.My req is
if report_date=8/31 and sales_qty>30....show 1
if report_date=7/15 and sales_qty>39...show 2..
in the formula section i am using
case WHEN "Fact- table"."Report Date"=evaluate('to_date(%1%2)',"Column_name",'DD/MM
/YYYY')) AND "Fact-table"."Sales_qty">30 THEN '1' ELSE '0' END Report date data type is date only...Its giving an error date format is not supported
Please help me out!!
hi,
thanks for u r quick response,i tried the code what u sent by its giving the error
A general error has occurred. [nQSError: 42015] Cannot function ship the following expression: Evaluate( to_char(%1,%2),cast(D1.c7 as DATE ) , 'MM/DD/YYYY') ADa.....
I tried in sql its giving correct results
SELECT * FROM table WHERE report_month=To_Date('15/09/2009','dd/mm/yyyy')
how to use the same in obiee?
thanks
Edited by: saichand on Oct 26, 2009 3:17 PM
Similar Messages
-
Hi gurus,
I am new to PL SQL and wanted to know that cant we put MIN inside the CASE WHEN.
I have following mentioned query:
It is not allowing me to execute it, can anyone help me out?
SELECT A,
B,
D,
E,
F,
SUM
(CASE
WHEN <Expression> THEN (CASE
WHEN ( <Expression>
THEN 0
ELSE min(<Expression>) or min(<Expression>)
END
ELSE 0
END
) AS sales
FROM tab1
WHERE ( column1 = 'x' )
GROUP BY A,
B,
D,
E,
F,
Edited by: user11001347 on Oct 29, 2009 2:34 AMGroup functions within a case are perfectly acceptable e.g.
select sum(case when dummy = 'X' then '1' else min(dummy) end) from dual group by dummy
SUM(CASEWHENDUMMY='X'THEN'1'ELSEMIN(DUMMY)END)
1There are other problems with your code...
This looks wrong to me:
min(<Expression>) or min(<Expression>)and you have a trailing comma after F in the group by clause.
When you're having problems with a piece of SQL, It's useful to us if you post the error you are getting back, and your table structure and sample test data too if possible.
Edited by: Cyn on Oct 29, 2009 9:43 AM -
CASE WHEN functionality in BI Publisher
I have previously used Discoverer to do our reporting and am investigating the differences between the two products. I understand that its chalk and cheese but one thing I am having trouble identifying is the CASE WHEN functionality that we use Discoverer in BI Publisher.
An example of the usage for our CASE WHEN would be creating a derived column in a report to convert existing data into a more standardised format.
I imagine this is quite a simple answer and I have just missed it but could anyone out there help me with where I can input the functionality in BI publisher.
I am not the most technically gifted so any answers with simple words help :-)
Edited by: 943098 on 27-Jun-2012 03:25You can use CASE WHEN in a sql query in a data model. You can also use it in the RTF template via "if then else", choose statements etc
Take a look at section 4.10 in the BI publisher Report Designer's guide for use cases/examples: http://docs.oracle.com/cd/E23943_01/bi.1111/e22254.pdf
Thanks,
Bipuser -
Using case when to an aggregate function
Hi,
I have a sql statement like below,
Select CASE WHEN (Sum(Amount) Over (Partition By Name),1,1) = '-' THEN 0 ELSE Sum(Amount) Over (Partition By Name) END AS Amount_Person
From tbPerson
But when I run the sql statement above I got error ORA-00920: invalid relational operator. What I'm trying to do is when the total amount for each person is negative then it will return 0 else it will return the positive value. I dont want to use the GROUP BY function. Is there any other way than using the Sum Over function? ThanksLike this?
SELECT CASE WHEN Sum(Amount) Over (Partition By Name) < 0 THEN 0
ELSE Sum(Amount) Over (Partition By Name)
END AS Amount_Person
FROM tbPerson
;or using GREATEST function :
SELECT GREATEST(
Sum(Amount) Over (Partition By Name)
, 0
) as Amount_Person
FROM tbPerson
;Edited by: odie_63 on 24 févr. 2011 09:12 -
How to use case when function to calculate time ?
Dear All,
May i know how to use case when function to calculate the time ?
for the example , if the First_EP_scan_time is 12.30, then must minus 30 min.
CASE WHEN FIRSTSCAN.EP_SHIFT <> 'R1' AND FIRSTSCAN.EP_SHIFT <> 'R2'
THEN ROUND(CAST((DATEDIFF(MINUTE,CAST(STUFF(STUFF((CASE WHEN SHIFTCAL.EP_SHIFT = 'N1'
THEN CONVERT(VARCHAR(8),DATEADD(DAY,+1,LEFT(FIRSTSCAN.EP_SCAN_DATE ,8)),112) + ' ' + REPLACE(CONVERT(VARCHAR(8),DATEADD(HOUR,+0,SHIFTDESC.EP_SHIFT_TIMETO + ':00'),108),':','')
ELSE LEFT(FIRSTSCAN.EP_SCAN_DATE ,8) + ' ' + REPLACE(CONVERT(VARCHAR(8),DATEADD(HOUR,+0,SHIFTDESC.EP_SHIFT_TIMETO + ':00'),108),':','') END),12,0,':'),15,0,':') AS DATETIME),CAST(STUFF(STUFF(LASTSCAN.EP_SCAN_DATE,12,0,':'),15,0,':') AS DATETIME)) / 60.0 - 0.25) AS FLOAT),2)
ELSE ROUND(CAST((DATEDIFF(MINUTE,CAST(STUFF(STUFF(FIRSTSCAN.EP_SCAN_DATE,12,0,':'),15,0,':') AS DATETIME),CAST(STUFF(STUFF(LASTSCAN.EP_SCAN_DATE,12,0,':'),15,0,':') AS DATETIME)) / 60.0) AS FLOAT),2) END AS OTWORK_HOURDo not use computations in a declarative language. This is SQL and not COBOL.
Use a table of time slots set to one more decimal second of precision than your data. You can now use temporal math to add it to a DATE to TIME(1) get a full DATETIME2(0). Here is the basic skeleton.
CREATE TABLE Timeslots
(slot_start_time TIME(1) NOT NULL PRIMARY KEY,
slot_end_time TIME(1) NOT NULL,
CHECK (start_time < end_time));
INSERT INTO Timeslots --15 min intervals
VALUES ('00:00:00.0', '00:14:59.9'),
('00:15:00.0', '00:29:59.9'),
('00:30:00.0', '00:44:59.9'),
('00:45:00.0', '01:00:59.9'),
('23:45:00.0', '23:59:59.9');
Here is the basic query for rounding down to a time slot.
SELECT CAST (@in_timestamp AS DATE), T.start_time
FROM Timeslots AS T
WHERE CAST (@in_timestamp AS TIME)
BETWEEN T.slot_start_time
AND T.slot_end_time;
--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
in Sets / Trees and Hierarchies in SQL -
DB Function errors out when trying to use in both Answers and RPD file.
Hi All,
Its a strange behaviour that one function which is in Database works fine the other does not. I have created 2 DB functions and accessing them from OBIEE in both Answers and RPD. One function which returns a Date is working fine, the one which is returning a number is throwing a error.
State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 16001] ODBC error state: S0022 code: 904 message: [Oracle][ODBC][Ora]ORA-00904: "APPS"."XXX_BUSINESS_DAYS": invalid identifier. [nQSError: 16001] ODBC error state: S0022 code: 904 message: [Oracle][ODBC][Ora]ORA-00904: "APPS"."XXX_BUSINESS_DAYS": invalid identifier. [nQSError: 16015] SQL statement execution failed. (HY000)
SQL Issued: SELECT "Soft cost Fact".Project saw_0, "Soft cost Fact"."Fiscal Year" saw_1, "Soft cost Fact".XXX_BUSINESS_DATE saw_2, CASE WHEN EVALUATE('APPS.XXX_BUSINESS_DAYS(%1,%2,%3)',"Soft cost Fact"."Soft Cost Date","Soft cost Fact"."Soft Cost Date",1) =0 THEN 'ZERO' ELSE 'NON-ZERO' END saw_3 FROM "Soft Cost" WHERE "Soft cost Fact".Project = '060096' ORDER BY saw_0, saw_1, saw_2, saw_3
Both functions are in same schema, have the similar grants.
Please help me resolving this error. Any pointers in resolving this is much appreciated.
Thanks,
VijayI noticed that you have not specified the type of return value that the function returns. It is good practice to do so..
EVALUATE('DB_Function(%1)' as returntype, {Comma separated Expression}).
Try EVALUATE('APPS.XXX_BUSINESS_DAYS(%1,%2,%3)' as number,"Soft cost Fact"."Soft Cost Date","Soft cost Fact"."Soft Cost Date",1) to see if that resolves the error.
Also check this out if you haven't already.
http://obiee101.blogspot.com/2007/12/evaluate-function-and-presentation.html
Hope this helps.Thanks. -
Evaluate function doesn't work with Static values
Hi All,
I have been trying to call a evaluate function and have been successfully in calling it..but i face problem when i pass any static values to it...
For eg
when i try calling the function using one of the columns...it works fine
Evaluate('dbo.Hello(%1)',"Dim table_name"."Department" )
the function normally changes it to upper case.so i get all the value in the column in department in upper case.
but when i call any static value like
Evaluate('dbo.Hello(%1)','hello') it throws the following error..
[nQSError: 43113] Message returned from OBIS. [nQSError: 43119] Query Failed: [nQSError: 42015] Cannot function ship the following expression: Evaluate( dbo.Hello(%1),'hello') . (HY000)
Can any one please help me in this
Regards
SKWhich version of Jdev are you using? What are the results you are getting?
-
Error i am getting while using the evaluate function in a reprot
hi all,
can't we use semicolon in Evaluate function
Semicolon is not allowed in Evaluate Functions without proper escape i.e. \; (HY000)
SQL Issued: {call NQSGetQueryColumnInfo('SELECT case when 1=0 then USER_INFORMATION.USERNAME else EVALUATE(''my_func(%1,%2,%3)'',''aa'',''bb'',''Hindu;All Natl and Local'') end FROM xxx_xxx_xx')}
SQL Issued: SELECT case when 1=0 then USER_INFORMATION.USERNAME else EVALUATE('my_func(%1,%2,%3)','aa','bb','Hindu;All Natl and Local') end FROM xxx_yyy
ThnxHi,
Try this
EVALUATE('my_func(%1,%2,%3)','aa','bb','Hindu\;All Natl and Local')Without any proper escape character '\' obiee(EVALUATE function) will not accept ';'
Thanks,
Saichand.v -
SQL Expression in decode function or case statement?
Can I put SQL expressions in decode function or case statement?
For example,
select le.profile, decode( select count(1) from profile_data where NAME= 'XXXX_AFTER' and object_id = le.profile, 0, 'N', 'Y')
from element le;
or
select le.profile, case WHEN ( select count(1) from profile_data where NAME= 'XXXX_AFTER' and object_id = le.profile) = 0 THEN 'N'
ELSE 'Y'
from element le;
None of the above work.
Can anyone tell me how to make it work?
Is there any workaround?
Thanks,
JYou simply needed and END to your CASE statement;
SQL> with profile_data as (
select 'XXXX_AFTER' name, 1 object_id from dual),
element as (
select 1 profile from dual union all
select 2 from dual)
select le.profile,
case WHEN ( select count(1) from profile_data where NAME= 'XXXX_AFTER' and object_id = le.profile) = 0
THEN 'N'
ELSE 'Y'
END new_col
from element le
PROFILE N
1 Y
2 N -
Can we use Evaluate function in Prompt
Hi all
Can we use Evaluate Function in Dashboard Prompt?
I need some exposure on how to use it.
I am working on a HRMS-OLTP Source where I need to work with Oracle Functions from OBIEE.
IF somebody can tell me that, It will be a favour for me....
ThanQ
Anand VHi All,
Here's an example of how to use evaluate. This use calls the Oracle TO_DATE function: EVALUATE('TO_DATE(%1,%2)' as DATE, '03/03/2009', 'MM/DD/YYYY')
Here's how it works: EVALUATE( '<FUNC>' AS <DATATYPE>, VALUE1,VALUE2,etc)
FUNC) Is the syntax for the function you are calling. Any parameters have to be replaced by %<number>, where number refers to the order in which you specify your parameters.
DATATYPE) The datatype that the function will evaluate to. In this case, DATE.
VALUE1) The latter part of the formula is a comma separated list of all the parameters used in the function. In this case, it's the date I want to cast
VALUE2) This is the second parameter. You need as many as you referenced in your function. In this case, it's the date format.
Good luck and if you found this post useful, please award points!
Best regards,
-Joe -
Using CASE WHEN in PL/SQL package
I am trying to convert the values in a selected column into 1 and 0 so that I can display all 1s in one column, all 0s in another. I am doing this in a PL/SQL package. However ORACLE compiler does not like the CASE construct.
Does anyone know how to group values in a column into several new columns. If CASE WHEN construct is not doable in PL/SQL, what alternatives are there? Thanks.
/******* My package starts here *******/
CREATE OR REPLACE PACKAGE TEST_NEED AS
PROCEDURE procTEST_NEED(STARTING_DATE IN VARCHAR2);
END CVRR_MON_NEED;
CREATE OR REPLACE PACKAGE BODY TEST_NEED
AS
PROCEDURE procTEST_NEED(STARTING_DATE IN VARCHAR2)
IS
TEST_START DATE := TO_DATE(STARTING_DATE,'MM/DD/YYYY');
CURSOR v_Cursor IS
SELECT A.D_CODE, A.M_CODE, TEST_START , C.C_NAME,C.P_ID,
SUM(CASE WHEN MONTHS_BETWEEN(SYSDATE, D.P_DOB)/12 > 40 AND MONTHS_BETWEEN(SYSDATE, D.P_DOB)/12 <85 AND B.B_CODE IN '11.1','222.2','272.4') THEN 1 ELSE 0 END) QUALIFIED
FROM A, B, C, D
WHERE A.ID = B.B_ID
AND RTRIM(A.P_CODE) = C.P_CODE
AND A.P_ID = D.P_ID
AND A.P_ID < 99999999999999999999
AND A.E_DATETIME < SYSDATE
GROUP BY A.D_CODE, A.M_CODE, TEST_START , C.C_NAME,C.P_ID;
v_RecordHolder v_Cursor%ROWTYPE;
BEGIN
OPEN v_Cursor;
FETCH v_CursorINTO v_RecordHolder ;
WHILE v_Cursor%FOUND LOOP
look for records in another table with matching keys of the cursor
if found then update by incrementing the existing values in the matching records with values of the current currsor row
else insert the current cursor row
FETCH v_Cursor INTO v_RecordHolder ;
END LOOP;
END procTEST_NEED;
END TEST_NEED;I am trying to convert the values in a selected
column into 1 and 0 so that I can display all 1s in
one column, all 0s in another. I am doing this in a
PL/SQL package. However ORACLE compiler does not
like the CASE construct.
Does anyone know how to group values in a column into
several new columns. If CASE WHEN construct is not
doable in PL/SQL, what alternatives are there?
Thanks.
CURSOR v_Cursor IS
SELECT A.D_CODE, A.M_CODE, TEST_START ,
, C.C_NAME,C.P_ID,
SUM(CASE WHEN MONTHS_BETWEEN(SYSDATE, D.P_DOB)/12 >
40 AND MONTHS_BETWEEN(SYSDATE, D.P_DOB)/12 <85 ANDB.B_CODE IN '11.1','222.2','272.4') THEN 1 ELSE 0
END) QUALIFIEDUse the Decode function. This has been around in oracle SQL for ages and works like a case construct.
You would do something like
select ...
sum( decode (MONTHS_BETWEEN(SYSDATE, D.P_DOB)/12 >
40 AND MONTHS_BETWEEN(SYSDATE, D.P_DOB)/12 <85 AND
B.B_CODE IN ('11.1','222.2','272.4') 1,0 ) -
Help in changing plsql case when to decode
Hi,
Can anyone help me to change this sql for it to use decode function instead of case when? Below is the sql code
Thanks in advance.
SELECT
parts,
weeks,
SUM(qty) qty
FROM (
SELECT
CASE
WHEN ((is_tbd = 'yes' AND is_tbd_order = 'no') OR ex_fac_date > v_asofdate + 131) THEN 'tbd'
WHEN ex_fac_date BETWEEN v_asofdate - 1 AND v_asofdate + 5 AND is_tbd = 'no' THEN 'wk1'
WHEN ex_fac_date BETWEEN v_asofdate + 6 AND v_asofdate + 12 AND is_tbd = 'no' THEN 'wk2'
WHEN ex_fac_date BETWEEN v_asofdate + 13 AND v_asofdate + 19 AND is_tbd = 'no' THEN 'wk3'
WHEN ex_fac_date BETWEEN v_asofdate + 20 AND v_asofdate + 26 AND is_tbd = 'no' THEN 'wk4'
WHEN (ex_fac_date < v_asofdate - 1) AND is_tbd = 'no' THEN 'past_due'
END weeks,
ffdate,
parts,
SUM(qty) qty
FROM
delivery)I can't use case because my oracle is 8i,Please join 21st Century
Can you help me checnge this to if then elsif insteadSQL does does contain IF statement! -
Hi All,
I tried using Evaluate and Evaluate_Aggr in the column formula of a report.
Evaluate_Aggr() is erroring saying the dimension Work Order is incorrectlly defines logical Table Source Mapping for a dimension of Work Order. If I revoke the implicit fact coniguration on this Subject Area which I have, the report executes as expected. But this implicit configuration is required in my scenario for other reports to work.
Using Evaluate() works perfectly.
Can anyone help me in fixing this?
Shld I add any other configuration in the RPD to resolve this issue?
Thanks996933 wrote:
hi all
i got this error when i try to execute evaluate function in obiee answer
nQSError: 10058] A general error has occurred. [nQSError: 27002] Near <(>: Syntax error [nQSError: 26012] . (HY000)
SQL Issued: SELECT DGN_TIME_RES_USAGE_CUBE.DRTCLN_WO_NO, DGN_TIME_RES_USAGE_CUBE.HOURS, DGN_TIME_RES_USAGE_CUBE.PROJ_NO, EVALUATE('FUNC_FIND_EMPLOYEE_DESC(%1,%2,%3)','KASA',DGN_TIME_RES_USAGE_CUBE.DRTCHD_EMP_ID,1), RMAX(DGN_TIME_RES_USAGE_CUBE.DRTCHD_DATE), RMIN(DGN_TIME_RES_USAGE_CUBE.DRTCHD_DATE) FROM LIVE2 years back post from the next time open new thread ? (Business Intelligence Suite Enterprise Edition )
Thanks,
Saichand -
Best practices on using EVALUATE functions
hi, experts,
I wanna know what is the best practices on using EVALUATE functions on obiee (calling oracle user defined functions)
I found that if I use evaluate functions in Answers,
obiee will construct a sql behind and then execute.
sometimes, obiee contructs some unexpected sqls, and returns errors.
so, is it better to use EVALUATE functions in logical columns ?
thanksEVALUATE('DB_Function(%1)' as returntype, {Comma separated Expression})
even when used in Logical columns, its gonna fire the same sql. -
Hi all!
I have a report in Discoverer Plus (Version 10.1.2.48.18) which contains 2 columns: One with actual spendings and one with budget figures. I want to make a third column which holds actual spendings in percentage of the budget. To do this, I need to make a calculation similar to:
CASE WHEN SUM(budget) <> 0 THEN SUM(spendings)/SUM(budget) ELSE NULL END
However, when I apply this calculation to the third column, my report don't return any numbers at all in any column.
What am I doing wrong? -- Is this a bug, and how should I solve my problem?
~MortenI can get something out if I do this (applying an aggregate function to it all):
SUM(CASE WHEN budget <> 0 THEN spendings/budget ELSE NULL END)
However, this is wrong (Summarizing these percentages doesn't give any meaning).
SQL lookes something like this:
SELECT /*+ NOREWRITE */ o100448.ACCOUNT as E100451,(decode((ADD_MONTHS(o100862.DATE1,-4)),null,to_date(null, 'MMDDYYYY'),to_date(to_char(trunc((ADD_MONTHS(o100862.DATE1,-4)),'YYYY'),'YYYY') || '01','YYYYMM'))) as E101004,MAX(o100448.ACCOUNTNUM) as as100473_100451_NEW,CASE WHEN ( SUM(o100862.BUDGET) ) <> 0 THEN ( SUM(o100862.AMOUNT) )/( SUM(o100862.BUDGET) ) ELSE NULL END as C_1,( SUM(o100862.BUDGET) )*o100448.SIGN as C_3,( SUM(o100862.AMOUNT) )*o100448.SIGN as C_2,GROUPING_ID(o100448.ACCOUNT,o100448.SIGN,(decode((ADD_MONTHS(o100862.DATE1,-4)),null,to_date(null, 'MMDDYYYY'),to_date(to_char(trunc((ADD_MONTHS(o100862.DATE1,-4)),'YYYY'),'YYYY') || '01','YYYYMM')))) as GID
FROM TANGO.TANGO_ACCOUNTS o100448,
TANGO.TANGO_SUMS o100862
WHERE ( (o100862.ORG = o100448.ORG AND o100862.ACCOUNTNUM = o100448.SUBACCOUNTNUM))
AND (o100448.ACCOUNTNUM BETWEEN 30000 AND 79999)
AND (o100862.DIM = '50')
AND (o100448.ORG = 'bru')
GROUP BY GROUPING SETS(( o100448.ACCOUNT,o100448.SIGN,(decode((ADD_MONTHS(o100862.DATE1,-4)),null,to_date(null, 'MMDDYYYY'),to_date(to_char(trunc((ADD_MONTHS(o100862.DATE1,-4)),'YYYY'),'YYYY') || '01','YYYYMM'))) ),( o100448.ACCOUNT,(decode((ADD_MONTHS(o100862.DATE1,-4)),null,to_date(null, 'MMDDYYYY'),to_date(to_char(trunc((ADD_MONTHS(o100862.DATE1,-4)),'YYYY'),'YYYY') || '01','YYYYMM'))) ))
HAVING (GROUP_ID()=0)
ORDER BY GID DESC;
I tried to fire this SQL up in TOAD (or whatever SQL-tool you might have), and columns C_2 and C_3 are empty. Seems like I'm doing something awfully wrong here.....
Any ideas? (There must be some SQL sharks out there ;-p)
~Morten
Maybe you are looking for
-
How can I connect a portable hard drive?
I use a number of portable hard drives with my MacBook Pro, mostly Seagate. The one I use for my TIme Machine back up has stopped working - when I connect it to my Mac, nothing happens (e.g. no sign of the drive within Finder). I have rebooted the Ma
-
How to save the data from AI Read.vi?
Hi, The main target is that testing the strength of a object which is extended by a force. The desired results are 1. The strength of object under the force(main target, I am trying now); 2. Displacement of object being extended(I have mimicly done);
-
Hi, 1. If we take full backup from RMAN utility, it will store the backup in either disk or tape. I want to know if we have 6 datafiles, one control file then what would be the name of the backup file? will it create 6 backup file? 2. Rman command is
-
FRM-92101 HOW I CAN FINISH THIS ERROR
APPLICATION.LOG IS SHOWING BELOW MESSAGE WHAT I DO PLEASE HELP RGDS TAHIR 06/08/06 13:20:49 formsweb: Forms session <19> aborted: unable to communicate with runtime process. 06/08/06 13:20:49 formsweb: Forms session <19> exception stack trace: java.i
-
Printing out of CS5 on Epson R3000 prints light cyan and grey background
I have an Imac with Mountain Lion, CS5 and have just replaced my Epson R2400 with an R3000. Now the white background round the image is covered in small cyan and light grey dots. If the image fills the paper, then the margin is affected. But when try