Using round off function in where clause
Hi All,
I'm trying to use round off function in where clause, I seek help in completing this script.
WITH CR_Details AS
(Select
request_id,
parent_request_id,
fcpt.user_concurrent_program_name Request_Name, phase_code, status_code,
round((fcr.actual_completion_date - fcr.actual_start_date),3) * 24 * 60 as Run_Time,
round(avg(round(to_number(actual_start_date - fcr.requested_start_date),3) * 1440),2) wait_time,
fu.User_Name Requestor,
fcr.argument_text parameters,
to_char (fcr.requested_start_date, 'MM/DD HH24:mi:SS') requested_start,
to_char(actual_start_date, 'MM/DD/YY HH24:mi:SS') ACT_START,
to_char(actual_completion_date, 'MM/DD/YY HH24:mi:SS') ACT_COMP,
fcr.completion_text
From
apps.fnd_concurrent_requests fcr,
apps.fnd_concurrent_programs fcp,
apps.fnd_concurrent_programs_tl fcpt,
apps.fnd_user fu
Where 1=1
and fcr.concurrent_program_id = fcp.concurrent_program_id
and fcp.concurrent_program_id = fcpt.concurrent_program_id
and fcr.program_application_id = fcp.application_id
and fcp.application_id = fcpt.application_id
and fcr.requested_by = fu.user_id
and fcpt.language = 'US'
and fcr.actual_start_date like sysdate )
select crd.*
from CR_Details crd
where Run_time <> '0'
AND wait_time <> '0'
GROUP BY
crd.request_id,
crd.parent_request_id,
crd.fcpt.user_concurrent_program_name,
crd.requested_start_date,
crd.User_Name,
crd.argument_text,
crd.actual_completion_date,
crd.actual_start_date,
crd.phase_code,
crd.status_code,
crd.resubmit_interval,
crd.completion_text,
crd.resubmit_interval,
crd.resubmit_interval_unit_code,
crd.description
Not sure about the GROUPBY function referencing the "crd." .
Hi,
The best thing for you to do is start over. Start as small as possible, then take baby steps.
Pick one of the tables; fcr perhaps, and write a query that just uses that table, like this:
SELECT *
FROM apps.fnd_concurrent_requests fcr
WHERE fcr.actual_start_date >= TRUNC (SYSDATE)
AND fcr.actual_start_dt < TRUNC (SYSDATE) + 1
;(I think this is what you meant to do when you said "... LIKE SYSDATE".)
Make sure this little query gets credible results. When that tiny query is working perfectly, add another line or two. You can cut and paste code from what you posted, if that helps you.
If you get stuck, post the last version of your code that worked perfectly, and the latest version (only a line or two bigger) that has the problem. Describe what the problem is. If you get an error, post the complete error message. In any event, post CREATE TABLE and INSERT statements for all the tables and columns needed to run the query, and the results you want to get from that query.
When you post any code, format it, so that how the code looks on the screen gives some clues about how it is working.
When you post any formatted text on this site, type these 6 characters:
\(small letters only, inside curly brackets) before and after each section of formatted text, to preserve spacing.
If you going to use the AVG function in the sub-query, then you probably need to do a GROUP BY in the sub-query.
If you're not using any aggregate functions (like AVG) in the main query, then you probably don't want to do a GROUP BY in the main query.
I know this is a lot of work. I'm sorry. If there was an easier way, I wouldn't ask you to do all this.
Similar Messages
-
How to use Round off function in TAX Formula
Dear All,
I have to do Round off in the Tax Formula. Hence I was suggested by the SAP Forum Team to use Round off function in the Tax Formulae.
But sir I don't know how to use Round off function in the Tax Formulae.
For Eg. BaseAmt = Total
TaxAmt = BaseAmt * Rate
Now within this Eg. How will i use the Round off function and where i will use it.
Please guide me with example.
Regards
Hitesh ParsawalaHi Hitesh,
you can do like this
Cess_ST_TaxAmt=Round(Cess_ST_BaseAmt*Cess_ST_Rate,0)
where you can introduce rounding function by choosing from dropdown available in Operation and by click on Insert.
It will post following in formulla window
Round (Number, Decimals as Number)
where in parameter you have to give 1.Number-which is to be round and 2.Decimals as Number-as per your requirement like by 2 decimal or 0 decimal
If required give me call,
BR
Samir Gandhi -
Strange errors when using user defined function in where clause
Hello,
I am having trouble with a function that, when used in the where clause of a select will cause an error if the first column selected is of type INTEGER. Not sure whether I am doing something wrong or whether this is a bug.
Here is a very simple test case:
create table test(
col1 integer not null,
col2 varchar(20) ascii default ''
insert into test values(1,'2011-03-15 05:00:00')
insert into test values(2,'2011-03-15 07:00:00')
CREATE FUNCTION BTR_TAG RETURNS VARCHAR AS
VAR ret VARCHAR(20);
SET ret='2011-03-15 06:00:00';
RETURN ret;
Select * from test where col2 >= BTR_TAG()
Select col1,col2 from test where col2 >= BTR_TAG()
=> Error in assignment;-3016 POS(1) Invalid numeric constant
Select '',* from test where col2 >= BTR_TAG()
Select col2,col1 from test where col2 >= BTR_TAG()
=> works as it should
MaxDB V 7.7.07.16 running on Windows Server 2003
I can replicated the test case above with Sql Studio and other ODBC based tools.
Thanks in advance,
Silke ArnswaldHello Siva,
sorry, but I don't understand your reply:
This is not right forum to posting this question.
You are from which module or working any 3rd party application.
MaxDB 7.7.07.16 is the community version of MaxDb,
we are not using it for SAP
and no 3rd party software is required to reproduce my problem,
Sql Studio or Database Studio will do.
Regards,
Silke Arnswald -
Using user defined function in where clause
Hi,
I have defined function to get maximum date before passed date on the table 'A' and I'm using the same function to get details on that date from the same table 'A' in where clause.
for ex:
SELECT x,y,z
FROM A
WHREE a.date = max_date;
But on one database instance it is running fine and on other it is going in a infinite loop.
Pls help me out
Thanks in advance,
PrashantHello Siva,
sorry, but I don't understand your reply:
This is not right forum to posting this question.
You are from which module or working any 3rd party application.
MaxDB 7.7.07.16 is the community version of MaxDb,
we are not using it for SAP
and no 3rd party software is required to reproduce my problem,
Sql Studio or Database Studio will do.
Regards,
Silke Arnswald -
Using function in where clause
I have created a function as follows
create or replace FUNCTION get_codes RETURN varchar2 IS
scodes varchar2(50) := 'A1,A2';
BEGIN
scodes := '('''||REPLACE(scodes,',',''',''')||''')';
return scodes;
END;
this function returns ('A1','A2')
now i want to use this in where clause, both below statements fetches no rows
select * from tablea where code in (select get_codes from dual);
select * from tablea where code in get_codes;
but the following will fetch rows
select * from tablea where code in ('A1','A2')
how to use function in where clause
ThanksHi,
The code that works:
where code in ('A1','A2')is testing whther code is either of two 2-character strings, A1 or A2.
The ones that don't work, such as:
where code in get_codes;are comparing code to one 9-character string: 'A1','A2', where characters 1, 4, 6 and 9 are single-quotes. (The function can only return one value.)
You can use dynamic SQL to embed that 9-character string in part of your query, where it will be interpreted as two 2-character strrings.
[Oracle Base|http://www.oracle-base.com/articles/misc/DynamicInLists.php] and AskTom have good pages on the subject of dynamic IN-lists.
Of you can use INSTR or LIKE:
where INSTR ( get_codes
, '''' || code || ''''
) > 0 -
How can we use DECODE function in where clause.
Hi Guys,
I have to use DECODE function in where clause.
like below
select * from tab1,tab2
where a.tab1 = b.tab2
and decode(code, 'a','approved')
in this manner its not accepting?
Can any one help me on this or any other aproach?
Thanks
-LKR>
I am looking for to decode the actual db value something in different for my report.
like if A then Accepted
elseif R then Rejected
elseif D then Denied
these conditions I have to check in where clause.
>
what are you trying to do?
may be you are looking for
select * from tab1,tab2
where a.tab1 = b.tab2
and
(decode(:code, 'A','Accepted') = <table_column>
or
decode(:code, 'R','Rejected') = <table_column>
or
decode(:code, 'D','Denied') = <table_column>
) -
Bad performance when calling a function in where clause
Hi All,
I have a performance problem when executing a query that contains a function call in my where clause.
I have a query with some joins and a where clause with some regular filters. But one of these filters is a function, and its input parameters are columns of the tables used in the query.
When I run it with only a few rows in the tables, it goes ok. But as the number of rows grows, performance falls geometrically, even when my where clause filters the result to only a few rows.
If I take the function call off of the where clause, then run the query and then call the function for each returned row, performance is ok. Even when the number of returned rows is big.
But I need the function call to be in the where clause, because I can't build a procedure to execute it.
Does anyone have any clue on how to improve performance?
Thanks,
RafaelYou have given very little information...
>
If I take the function call off of the where clause, then run the query and then call the function for each returned row, performance is ok. Even when the number of returned rows is big. Can you describe how you measured the performance for a big result set without the function? For example lets say there had been 10.000 rows returned (which is not really big, but it is astarting point). Did you see all 10.000 rows? A typical mistake is to execute the query in some tool like Oracle SQL Developer or TOAD and measure how fast the first couple of rows are returned. Not the performance of the full select.
As you can see from this little detail there are many questions that you need to address first before we can drill down to the root of your problem. Best way is to go through the thread that Centinul linked and provide all that information first. During the cause of that you might discover that you learn things on the way that help a lot for later tuning problems/approaches.
Edited by: Sven W. on Aug 17, 2009 5:16 PM -
Can't have aggregate function in WHERE clause clause
Dear all,
I've created object in BO XI 3.1 Designer with following criterias:
http://img4.imageshack.us/img4/833/20111201124314.th.jpg
It is a simple number - 1,2,3,4,5.
Now I need to use this object as a criteria for WHERE function in another object.
http://img607.imageshack.us/img607/1543/20111201124717.th.jpg
I receive an error "Can't have aggregate function in WHERE clause <clause>"
How can I overcome this?
P.S. I'm sorry in advance if such topic already exist - I didn't found one.
Edited by: Ashot Antonyan on Dec 1, 2011 9:50 AM
Edited by: Ashot Antonyan on Dec 1, 2011 9:51 AMHi,
You will have to use Sub query to achieve this. Give more details on what is available and what you need then i could help you out with the complete solution.
Thanks,
Ravichandra K -
Help:alternate for calling function in where clause
Hi ,
In below query i'm calling function in where clause to avoid COMPLETE status records,due to this query taking 700 secs to return result.If i'm remove below function condition it's returning results with in 5 secs.Can you some one advice to any alternate idea for this?
WHERE mark_status != 'COMPLETE'
SELECT assessment_school,
subject,
subject_option,
lvl,
component,mark_status,
mark_status
NULL AS grade_status,
NULL AS sample_status,
:v_year,
:v_month,
:v_formated_date,
:v_type,
cand_lang
FROM
(SELECT assessment_school,
subject,
subject_option,
lvl,
programme,
component,
paper_code,
cand_lang,
mark_entry.get_ia_entry_status(:v_year, :v_month, assessment_school, subject_option, lvl, cand_lang, component, paper_code) AS mark_status
FROM
(SELECT DISTINCT ccr.assessment_school,
ccr.subject,
ccr.subject_option,
ccr.lvl,
ccr.programme,
ccr.language AS cand_lang,
ccr.paper_code,
ccr.component
FROM candidate_component_reg ccr
WHERE ccr.split_session_year = :v_year
AND ccr.split_session_month = :v_month
AND EXISTS
(SELECT 1
FROM IBIS.subject_component sc
WHERE sc.year = ccr.split_session_year
AND sc.month = ccr.split_session_month
AND sc.paper_code = ccr.paper_code
AND sc.assessment_type = 'INTERNAL'
AND sc.subject_option NOT LIKE '%self taught%'
AND sc.component NOT IN ('PERFORMANCE PRODUCTION','PRESENTATION WORK','REFLECTIVE PROJECT','SPECIAL SYLLABUS INT. ASSESSMENT')
AND NVL(ccr.withdrawn,'N') = 'N'
AND ccr.mark_status != 'COMPLETE'
AND EXISTS
(SELECT 1
FROM school s
WHERE s.school_code = ccr.assessment_school
AND s.training_school = 'N'
WHERE mark_status != 'COMPLETE';One thing you can test quickly is to put the function call in it's own select ...from dual.
This might make a difference.
However, only you can check this, I don't have your tables or data.
So, what happens if you use:
paper_code,
cand_lang,
(select mark_entry.get_ia_entry_status(:v_year, :v_month, assessment_school, subject_option, lvl, cand_lang, component, paper_code) from dual ) AS mark_status
FROM
(SELECT DISTINCT ccr.assessment_school, --<< is the DISTINCT really needed?
ccr.subject,
ccr.subject_option,
...Also, try to find out the purpose of that above DISTINCT, is it really needed or is there some join missing? -
Call of constant function in where clause
Hi there,
I want to execute the following query
select a_field
from a_table
where another_field = a_func('10')
where a_func is a stored function and returns a value dependent on its argument. Same argument returns same result. How to see, the argument is a_table-independent (constant), so the result is a constant. How can I prevent oracle from executing a_func for each row of a_table? I know, that the following code works:
select a_field
from a_table
where another_field = (select a_func('10') from dual)
but this less readable and harder to explain to low-level-users in my eyes. Is there any pragma or anything else I can do, so the first statement can executed with a single(!) execution of a_func?
Thanks, ALu.
nullUnfortunately Variables do not help in this case. The query-text goes (in one of three uses) into a Delphi-TQuery-Object and after opening it the results are shown. Declaring Variables is not allowed this way. I want a single (very) easy(!) statement to be executed (see the first one above). To explain the use of the function is ok (instead of using any subselect this function calculates), but any subselect- or variable-usage is beyond most of my app-users that want access to the stored data. The solution must be found in declaration of a_func (to put it into a package an restrict it by WNPS, WNDS also did not help ...)
Thanx anyway, ALu.
<BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by Narayan Acharya ([email protected]):
How about defining a variable, assigning it a value by calling the function, then using the variable in the where clause ?
Trust that would work ?
Narayan.<HR></BLOCKQUOTE>
null -
My function in where clause? help me please.
hello friends, I need to call my function in where clause as dummy example below:
declare
name_ table1.name%type;
function return_id(id number) return number is
begin
return 1;
end return_id;
begin
select name into name_
from table1
where id = return_id(table1.id);
end;
raise exception: 'the function doesn't used in where clause'. why????-- CREATING A FUNCTION AVAILABLE THROUGH A PACKAGE SPEC.
SQL> ed
Wrote file afiedt.buf
1 create package mypackage is
2 function myfunc(p_val NUMBER) RETURN NUMBER;
3* end;
SQL> /
Package created.
SQL> ed
Wrote file afiedt.buf
1 create or replace package body mypackage is
2 function myfunc(p_val NUMBER) RETURN NUMBER IS
3 begin
4 RETURN (p_val*p_val)-1;
5 end;
6* end;
SQL> /
Package body created.
SQL> declare
2 v_myval NUMBER := 2;
3 begin
4 select mypackage.myfunc(v_myval)
5 into v_myval
6 from dual;
7 dbms_output.put_line(v_myval);
8 select mypackage.myfunc(v_myval)
9 into v_myval
10 from dual;
11 dbms_output.put_line(v_myval);
12 end;
13 /
3
8
PL/SQL procedure successfully completed.
-- CREATING A STANDALONE DATABASE FUNCTION.
SQL> create or replace function myfunc2(p_val number) return number is
2 begin
3 return (p_val*2)+1;
4 end;
5 /
Function created.
SQL> ed
Wrote file afiedt.buf
1 declare
2 v_myval NUMBER := 2;
3 begin
4 select myfunc2(v_myval)
5 into v_myval
6 from dual;
7 dbms_output.put_line(v_myval);
8 select myfunc2(v_myval)
9 into v_myval
10 from dual;
11 dbms_output.put_line(v_myval);
12* end;
SQL> /
5
11
PL/SQL procedure successfully completed.
-- CREATING A LOCAL FUNCTION IN THE ANONYMOUS PL/SQL BLOCK
SQL> ed
Wrote file afiedt.buf
1 declare
2 v_myval NUMBER := 2;
3 function myfunc3(p_val number) return number is
4 begin
5 return (p_val*p_val*p_val);
6 end;
7 begin
8 select myfunc3(v_myval)
9 into v_myval
10 from dual;
11 dbms_output.put_line(v_myval);
12 select myfunc3(v_myval)
13 into v_myval
14 from dual;
15 dbms_output.put_line(v_myval);
16* end;
SQL> /
select myfunc3(v_myval)
ERROR at line 8:
ORA-06550: line 8, column 10:
PLS-00231: function 'MYFUNC3' may not be used in SQL
ORA-06550: line 8, column 10:
PL/SQL: ORA-00904: : invalid identifier
ORA-06550: line 8, column 3:
PL/SQL: SQL Statement ignored
ORA-06550: line 12, column 10:
PLS-00231: function 'MYFUNC3' may not be used in SQL
ORA-06550: line 12, column 10:
PL/SQL: ORA-00904: : invalid identifier
ORA-06550: line 12, column 3:
PL/SQL: SQL Statement ignored
SQL>As you can see (and as previously mentioned by someone else) the function has to be available to the SQL engine either via a datavbase package or as a database function. If you declare the function locally within the anonymous PL/SQL block then the function only exists in the scope of that PL/SQL block and thus when your SQL statement is sent to the SQL engine for execution, the SQL engine can't see it.
;) -
i insert the below rows in a table cash_book.
PRJ_CODE PRJ_NAME
1203 SHIFA
1203 SHIFA
1203 SHIFA
1202 FATIMA
1202 FATIMA
1203 SHIFA
if i select 1202 code then return 1202 code rows, if i select 1203 then returns 1203 code rows, if i select other than both values then returns all rows. how can i define in one query with use (case or decode function) in where clause ??perhaps something like this:
create table test
as
select 1200 + rownum prj_code
from dual
connect by level <= 10;
select * from test;
PRJ_CODE
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
var v_PRJ_CODE number
exec :v_PRJ_CODE := 1200;
select *
from test
where PRJ_CODE = :v_PRJ_CODE
or 1 = case when :v_PRJ_CODE in (1202, 1203) then 0 else 1 end;
PRJ_CODE
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
exec :v_PRJ_CODE := 1203;
select *
from test
where PRJ_CODE = :v_PRJ_CODE
or 1 = case when :v_PRJ_CODE in (1202, 1203) then 0 else 1 end;
PRJ_CODE
1203Regards
Martin -
Query Tuning - using CASE statement in the WHERE clause - Duplicate Post
Duplicate Post by mistake.
Please check
Query Tuning - using CASE statement in the WHERE clause
Edited by: Chaitanya on Jun 9, 2011 2:45 AM
Edited by: Chaitanya on Jun 9, 2011 2:46 AMDuplicate Post by mistake.
Please check
Query Tuning - using CASE statement in the WHERE clause
Edited by: Chaitanya on Jun 9, 2011 2:45 AM
Edited by: Chaitanya on Jun 9, 2011 2:46 AM -
@prompt not functioning in where clause
I have attempted to use the following in a where clause of a dimension object:
ORGANIZATION_DIM.ORGANIZATION_ID = @Prompt('Which Organization?','A','Cash Receipts\Organization ID',mono,constrained,not_persistent,{'ORG0001'})
When I use the object in a WebI query, the following SQL is generated:
SELECT
ORGANIZATION_DIM.ORGANIZATION_ID
FROM
ORGANIZATION_DIM
WHERE
( ( ORGANIZATION_DIM.ORGANIZATION_ID = @Prompt('Which Organization?','A','Cash Receipts\Organization ID',mono,constrained,not_persistent,{'ORG0001'}) ) )
When I run the query, the "query in process" pop up appears briefly and then nothing but a windows hourglass.
If I use the same @prompt in the where clause of a filter object and use the filter object in my WebI query, the same SQL is generated. When I run the query using the filter, the prompt appears as expected and the query runs successfully.
Any thoughts on what may be happening here?Hi
two more question:
1) Does 'Cash Receipts\Organization ID' appear before or after the dimension object you are talking about in the object browser in your universe?
2) Can you consider installing the latest Fix PAck (1.9)?
Regards,
Stratos -
Error when using record group type as param in a function in where clause
Hi folks.
I have a record type defined in a packages specification. I have to use this record as parameter to call a function. I am able to call the function if as return its value to a string variable. However, the function should be called into a query to compare the returned value and this code is not compiled.
The code is below:
DECLARE
l_line_group_rec INL_CUSTOM_PUB.inl_ship_headers_rec;
l_name VARCHAR2(100);
l_count NUMBER;
BEGIN
l_name := INL_GET_PARTY_SITE_NAME(l_line_group_rec); -- Compiling successfully
SELECT COUNT(1)
INTO l_count
FROM dual
WHERE INL_GET_PARTY_SITE_NAME(l_line_group_rec) = 'Allied Manufacturing'; --- Error when compiling
END;
I got the error: PLS-00306: wrong number or types of arguments in call to 'INL_GET_PARTY_SITE_NAME'
I would like to know if there is any restriction in using record type as parameter in where clauses or if there is another way to do it.
Thanks in advanceHi.
The definition of INL_GET_PARTY_SITE_NAME:
FUNCTION INL_GET_PARTY_SITE_NAME(p_line_group_rec INL_CUSTOM_PUB.inl_ship_headers_rec) RETURN VARCHAR2 IS
l_party_site_name VARCHAR2(100);
BEGIN
l_party_site_name := 'Allied Manufacturing';
URN l_party_site_name;
END INL_GET_PARTY_SITE_NAME;
Thanks.
Maybe you are looking for
-
One way to get an iPhone out of Recovery Mode.
So browsing through this forums and many others trying to figure out how I can update to iOS5 with out error codes, I have noticed a lot of people are "bricking" their iPhones. This is the solution I use, and it does the trick everytime. Make sure wh
-
When recording on a basic track......
When recording on a basic track from an external DJ mixer, is GB considering it a real instrument or a software instrument? Furthermore, Can you record multiple times over a cycled region from a standard dj set-up (two turntables and mixer, mixer con
-
Is there such thing as a JSF Init Page Load? the same thing that .net has with Page_Load? How do i init the code behind bean?
-
I've updated my iphone 4S to iOS 5.1 recently and I've found some problems.
First, it drains my battery. It drops 15% in an hour even though I don't use it. Second, when I click the "Edit" button for photos, my iphone shuts down automatically and turns on again. I can't edit any photos! Third, I can't click the "Camera" butt
-
Oracle.apps.wsh.delivery.gen.shipconfirmed
Hello All, I have a custom WF event subscrption to the WF Event "oracle.apps.wsh.delivery.gen.shipconfirmed". Can anyone tell me the setup steps in Shipping ... so that the event will be fired. I am working on R12. Thanks in Advance. Senthil