Helping Query
Dear All,
I am writing a following query and i am getting below o/p with null rows. I want to eliminate to null rows please help me
Please see the o/p with edit mode or run the query.
Query :
Select Decode (e.deptno, 10, e.Empno||'---->'|| e.ename) DEPRTNO_10,
Decode (e.deptno, 20, e.Empno||'---->'|| e.ename) DEPRTNO_20,
Decode (e.deptno, 30, e.Empno||'---->'|| e.ename) DEPRTNO_30,
Decode (e.deptno, 40, e.Empno||'---->'|| e.ename) DEPRTNO_40,
Decode (e.deptno, 50, e.Empno||'---->'|| e.ename) DEPRTNO_50
FROM emp e
O/P:
DEPRTNO_10 DEPRTNO_20 DEPRTNO_30 DEPRTNO_40 DEPRTNO_50
7369---->SMITH
7499---->ALLEN
7521---->WARD
7566---->JONES
7654---->MARTIN
7698---->BLAKE
7782---->CLARK
7788---->SCOTT
7839---->KING
7844---->TURNER
7876---->ADAMS
7900---->JAMES
7902---->FORD
7934---->MILLER
Edited by: YKING on Oct 1, 2011 5:47 PM
Edited by: YKING on Oct 1, 2011 6:03 PM
Hi ,
you are concatenating employee number ( which i would assume it is your primary key ) with employee name that most probably would be null ...
there are several solutions to this , one would be to run the query while employee name is not null
example :
Select *
From Emp
Where Ename IS NOT NULL;
Hope this helps out ...
Similar Messages
-
Query help: query to return column that represents multiple rows
I have a table with a name and location column. The same name can occur multiple times with any arbitrary location, i.e. duplicates are allowed.
I need a query to find all names that occur in both of two separate locations.
For example,
bob usa
bob mexico
dot mexico
dot europe
hal usa
hal europe
sal usa
sal mexico
The query in question, if given the locations usa and mexico, would return bob and sal.
Thanks for any help or advice,
-=beekyHow about this?
SELECT NAME
FROM <LOCATIONS_TABLE>
WHERE LOCATION IN ('usa','mexico')
GROUP BY NAME
HAVING COUNT(DISTINCT LOCATION) >= 2Results:
SQL> WITH person_locations AS
2 (
3 SELECT 'bob' AS NAME, 'USA' AS LOCATION FROM DUAL UNION ALL
4 SELECT 'bob' AS NAME, 'Mexico' AS LOCATION FROM DUAL UNION ALL
5 SELECT 'dot' AS NAME, 'Mexico' AS LOCATION FROM DUAL UNION ALL
6 SELECT 'dot' AS NAME, 'Europe' AS LOCATION FROM DUAL UNION ALL
7 SELECT 'hal' AS NAME, 'USA' AS LOCATION FROM DUAL UNION ALL
8 SELECT 'hal' AS NAME, 'Europe' AS LOCATION FROM DUAL UNION ALL
9 SELECT 'sal' AS NAME, 'USA' AS LOCATION FROM DUAL UNION ALL
10 SELECT 'sal' AS NAME, 'Mexico' AS LOCATION FROM DUAL
11 )
12 SELECT NAME
13 FROM person_locations
14 WHERE LOCATION IN ('USA','Mexico')
15 GROUP BY NAME
16 HAVING COUNT(DISTINCT LOCATION) >= 2
17 /
NAM
bob
salHTH!
Edited by: Centinul on Oct 15, 2009 2:25 PM
Added sample results. -
Need Help: Query Designer
Hi experts,
In Query designer, is it possible to create an IF statement for "IRRATIONAL NUMBERS"?
Lets say 10.03, 1.26, 3.1 and so on...
The statement would be as follow:
If Val1==N.x then 0 else Val1.
To summary, if the value is N.x (N for rational numbers 1,2,3,... and .x for decimal values like .23, .44, .01 and so on...),
then the value N.x will be changed or converted into "0".
Example: If the value of FieldA on the report is 10.3, it then should be converted into Zero "0".
another is if value is 1.03, then the report should show 0 instead of 1.03
I arrived to a solution wherein I have to create three logic expression.
First is to convert first the Irrational Number into Zero "0".
Second is to create new selection in KF wherein it will pull the data containing the converted "N.x to Zero".
And third is to create the IF statement logic that will satisfy my expected value.
I'm having this problem on the first one as I have no idea how to convert irrational number into zero "0" value.
the second and the last part would be fine as my main problem here is how can I convert the irrational number in to zero?
Any suggestions?Hi,
Please try the below.. Hope this will solve your issue
Eg. of data
Dist. Channel -
Value
Dom1----100.5
exp1----200.4
dom2---50
exp2---75
Expected out put
Dist. Channel -
Value
Dom1----0
exp1----0
dom2---50
exp2---75
Steps1
Drag and drop Dist.Channel in row and value in colum
create a formula1 using ur kf value
CEIL(value) --- which will provide us integior part with out decimal
Steps2
create another fomula2
using boolean operator compare the value
(formula2==value)*value
this formula compare our two values and will produce a boolean value ie 1 or 0
: Eg 100.5 ceil(100.5) = 100 Now in our formula1 we are comparing these two values are equal or not ie 100.5 - 100 so out come will be 0 then 0100.5 = 0 always if our condition is true then 1100 = 100
Related Links :
Boolean Operator
http://help.sap.com/saphelp_nw04/helpdata/EN/71/0aec3b6e011341e10000000a114084/frameset.htm
Thanks
BVR -
Please Help: query matching string value in WHERE clause
Hi Everyone,
I am trying to query customers that has matching first and last name but, I am getting result of every customer that has first and last name. Here is what my query looks like:
SELECT * FROM CUSTOMERS WHERE
CUSTOMER_FNAME IN
'JOHN', 'MIKE'
AND CUSTOMER_LNAME IN
'DOE', 'MILLER'
); I am trying to query customer name that is JOHN DOE and MIKE MILLER but, i get result of all names that has the first/last names not exact match. Is there way i can do that get exact match?
Thanks,
SMFrank Kulash wrote:
Hi,
chris227 wrote:
SMCR wrote:
Thanks everyone for your help!
There are two correct answers, I am using following:I just see one, it's Franks.If fname never contains a '~' (or if lname never contains a '~") then
{code}
where fname||'~'||lname in ('JOHN~DOE', 'MIKE~MILLER');
{code}
will work.Yes, I realized that. For the purpose i am using i will not have any issue with '~'
I did however changed it up a little, here is how it looks like:
{code}
SELECT CUSTOMER_ID, CUSTOMER_FNAME, CUSTOMER_LNAME, DATE_OF_BIRTH
FROM CUSTOMERS
WHERE (CUSTOMER_FNAME||'~'||CUSTOMER_LNAME, DATE_OF_BIRTH) IN
(('JOHN~DOE'), (TO_DATE('20130101', 'YYYYMMDD'))),
(('MIKE~MILLER'), (TO_DATE('20130101', 'YYYYMMDD')))
{code} -
I am trying to write a query to return data from 4 different tables and it is doubling my summed values. I can get the separate queries to work, but not combined and I need them combined so that I can get a balance due and limit the records to only those that had a total billed (fees) less than $200.
Query #1 Gets the total of the fees due for each appeal type and invoice:
Note: There is always at least one fee attached to an invoice.
SELECT APT.APTY_DESCR "APPEAL TYPE",
INV.INVC_ID_SEQ INVOICE,
SUM( ALL FEE.AMT_DUE) "TOTAL BILLED AMOUNT"
FROM WRD_APPEALS AP,
WRD_INVOICES INV,
WRD_FEES_DUE FEE,
WRD_APPEAL_TYPES APT
WHERE AP.APST_CD = 'PEND'
AND AP.INVC_ID_SEQ = INV.INVC_ID_SEQ
AND AP.INVC_ID_SEQ = FEE.INVC_ID_SEQ
AND AP.APTY_CD = APT.APTY_CD
GROUP BY APT.APTY_DESCR, INV.INVC_ID_SEQ
ORDER BY APT.APTY_DESCR, INV.INVC_ID_SEQ
4 BILLING CATEGORY INCORRECT 4147 1200
5 BILLING CATEGORY INCORRECT 4203 1100
6 BILLING CATEGORY INCORRECT 4216 72600
7 BILLING CATEGORY INCORRECT 4826 1000
8 BILLING CATEGORY INCORRECT 4951 2060
Query #2 Gets the total amount paid for each appeal type and invoice:
Note: An invoice may or may not have a payment, thus the outer join.
SELECT APT.APTY_DESCR "APPEAL TYPE",
INV.INVC_ID_SEQ INVOICE,
SUM(ALL PMT.PAID_AMT) "AMOUNT PAID"
FROM WRD_APPEALS AP,
WRD_INVOICES INV,
WRD_APPEAL_TYPES APT,
WRD_PAYMENTS PMT
WHERE AP.APST_CD = 'PEND'
AND AP.INVC_ID_SEQ = INV.INVC_ID_SEQ
AND AP.APTY_CD = APT.APTY_CD
AND INV.INVC_ID_SEQ = PMT.INVC_ID_SEQ(+)
GROUP BY APT.APTY_DESCR, INV.INVC_ID_SEQ
ORDER BY APT.APTY_DESCR, INV.INVC_ID_SEQ
4 BILLING CATEGORY INCORRECT 4147 200
5 BILLING CATEGORY INCORRECT 4203 0
6 BILLING CATEGORY INCORRECT 4216 72600
7 BILLING CATEGORY INCORRECT 4826
8 BILLING CATEGORY INCORRECT 4951
Combined Query - Gets all of the above as well as the balance due. Note the doubled values for some records.
SELECT APT.APTY_DESCR "APPEAL TYPE",
INV.INVC_ID_SEQ INVOICE,
SUM( ALL FEE.AMT_DUE) "TOTAL BILLED AMOUNT",
SUM(ALL PMT.PAID_AMT) "AMOUNT PAID",
(SUM(ALL FEE.AMT_DUE) -
NVL2(SUM(ALL PMT.PAID_AMT), SUM(ALL PMT.PAID_AMT), 0)) "BALANCE DUE"
FROM WRD_APPEALS AP,
WRD_INVOICES INV,
WRD_FEES_DUE FEE,
WRD_APPEAL_TYPES APT,
WRD_PAYMENTS PMT
WHERE AP.APST_CD = 'PEND'
AND AP.INVC_ID_SEQ = INV.INVC_ID_SEQ
AND INV.INVC_ID_SEQ = PMT.INVC_ID_SEQ(+)
AND INV.INVC_ID_SEQ = FEE.INVC_ID_SEQ
AND AP.APTY_CD = APT.APTY_CD
GROUP BY APT.APTY_DESCR, INV.INVC_ID_SEQ
ORDER BY APT.APTY_DESCR, INV.INVC_ID_SEQ,
4 BILLING CATEGORY INCORRECT 4147 1200 400 800
5 BILLING CATEGORY INCORRECT 4203 2200 0 2200
6 BILLING CATEGORY INCORRECT 4216 72600 435600 -363000
7 BILLING CATEGORY INCORRECT 4826 1000 1000
8 BILLING CATEGORY INCORRECT 4951 2060 2060
HELP PLEASE!
Thank you.When you have multiple child rows, the parent row gets returned once for each child row found. Therefore, if you have summed the invoice, it gets summed again for each payment. Perhaps this little example will help you understand the problem.
Note that I used a sub query here to obtain the desired results. Analytic functions can do the same I believe, but I am still learning them :-)
D> DROP TABLE DMILL.invoice;
Table dropped.
D>
D> DROP TABLE DMILL.payments;
Table dropped.
D>
D> CREATE TABLE invoice AS
SELECT 1 id, 10 amount FROM DUAL UNION ALL
SELECT 2 id, 10 FROM DUAL UNION ALL
SELECT 2 id, 10 FROM DUAL UNION ALL
SELECT 3 id, 10 FROM DUAL;
Table created.
D>
D> CREATE TABLE payments AS
SELECT 1 inv_id, 5 amount FROM DUAL UNION ALL
SELECT 1 inv_id, 5 amount FROM DUAL UNION ALL
SELECT 2 inv_id, 5 amount FROM DUAL UNION ALL
SELECT 2 inv_id, 5 amount FROM DUAL UNION ALL
SELECT 2 inv_id, 5 amount FROM DUAL;
Table created.
D>
D> select * from invoice;
ID AMOUNT
1 10
2 10
2 10
3 10
D>
D> select * from payments;
INV_ID AMOUNT
1 5
1 5
2 5
2 5
2 5
D>
D> select id
,sum (amount)
from invoice
group by id;
ID SUM(AMOUNT)
1 10
2 20
3 10
D>
D> select inv_id
,sum(amount)
from payments
group by inv_id;
INV_ID SUM(AMOUNT)
1 10
2 15
D>
D> select inv.id
,inv.amount
,pay.amount
from invoice inv
,payments pay
where pay.inv_id = inv.id;
ID AMOUNT AMOUNT
1 10 5
1 10 5
2 10 5
2 10 5
2 10 5
2 10 5
2 10 5
2 10 5
8 rows selected.
D>
D> select inv.id
,sum(inv.amount)
,sum(pay.amount)
from invoice inv
,payments pay
where pay.inv_id = inv.id
group by inv.id;
ID SUM(INV.AMOUNT) SUM(PAY.AMOUNT)
1 20 10
2 60 30
D>
D> select inv.id
,sum(inv.amount)
,(SELECT sum(pay.amount)
FROM payments pay
WHERE pay.inv_id = inv.id)
from invoice inv
group by inv.id;
ID SUM(INV.AMOUNT) (SELECTSUM(PAY.AMOUNT)FROMPAYMENTSPAYWHEREPAY.INV_ID=INV.ID)
1 10 10
2 20 15
3 10Let me know if you need further explanation. -
Hi all experts,
I have a problem making my selection criteria on this query for the user to input the numbers 1 to 10 variables
is there anything that can help me to resolve this
I have tried many times but it just does not work
Query me this:
SELECT
T1.[DocEntry], T0.[CardCode], T0.[CardName], T0.[DocDate], T1.[ItemCode], T1.[Dscription], T1.[Price], T2.[LastPurPrc]T1.[NumPerMsr] AS 'Last Purchase Price', (T1.[Price] - (T2.[LastPurPrc]T1.[NumPerMsr])) AS 'Variance', (((T1.[Price] - (T2.[LastPurPrc]T1.[NumPerMsr]))/(T2.[LastPurPrc]T1.[NumPerMsr]))*100) AS 'Variance%', T3.[SlpName]
FROM
OPCH T0 INNER JOIN PCH1 T1 ON T0.DocEntry = T1.DocEntry INNER JOIN OITM T2 ON T1.ItemCode = T2.ItemCode INNER JOIN OSLP T3 ON T0.SlpCode = T3.SlpCode
WHERE
(T2.[LastPurPrc] > 0) AND Month(T0.[DocDate]) = Month(Getdate()) AND Year(T0.[Docdate]) = Year(Getdate()) AND ((((T1.[PriceBefDi] - (T2.[LastPurPrc]T1.[NumPerMsr]))/(T2.[LastPurPrc]T1.[NumPerMsr]))*100) Between >= '[%0]'AND <= '[%1]')
ThanksTry this:
SELECT
T1.DocEntry, T0.CardCode, T0.CardName, T0.DocDate,
T1.ItemCode, T1.Dscription, T1.Price,
T2.LastPurPrc*T1.NumPerMsr AS 'Last Purchase Price',
(T1.Price - (T2.LastPurPrc*T1.NumPerMsr)) AS 'Variance',
(((T1.Price - (T2.LastPurPrc*T1.NumPerMsr))/(T2.LastPurPrc*T1.NumPerMsr))*100) AS 'Variance%',
T3.SlpName
FROM
OPCH T0 INNER JOIN PCH1 T1 ON T0.DocEntry = T1.DocEntry
INNER JOIN OITM T2 ON T1.ItemCode = T2.ItemCode
INNER JOIN OSLP T3 ON T0.SlpCode = T3.SlpCode
WHERE
(T2.LastPurPrc > 0) AND Month(T0.DocDate) = Month(Getdate())
AND Year(T0.Docdate) = Year(Getdate())
AND ((((T1.PriceBefDi - (T2.LastPurPrc*T1.NumPerMsr))/(T2.LastPurPrc*T1.NumPerMsr))*100)
Between [%0] AND [%1]) -
Hi
could you help me rewriting query without using joins
select * from A ,B,C
LEFT OUTER JOIN A
ON (A.account_no = B.account_no
AND C.id_type = B.id_type
AND B.value = 1) ;
thanks ,
-RajWHERE A.account_no = B.account_no(+)
AND C.id_type = B.id_typeIf these aren't joins what are they? -
I'm unable get XML output from the most basic of queries. I'm currently working through the Sql In Xml out document. Everytime i try to output xml i get a list (without errors) of
EMPLOYEE
<Xmltype>
<Xmltype>
<Xmltype>
<Xmltype>
<Xmltype>
for each record. Can anyone help.
Im running 10g release 2.A couple more questions
First, is the XML stored in the table as XMLType column with a schema?
Second, in sqplus, on 10R2, I just ran the following query, try it and see if what you get.
select xmlforest(object_name as "name") from user_objects where object_type = 'TABLE' and rownum < 5;
XMLFOREST(OBJECT_NAMEAS"NAME")
<name>BIN$+1aDxmVbQIau51oiplxCAw==$0</name>
<name>BIN$+3Y2EpX4TvGY4j1SIGBAMQ==$0</name>
<name>BIN$+AugUYpGSS29uaP5DnYsZQ==$0</name>
<name>BIN$+ptFT7gqTX2GgNrndS5azw==$0</name>
Elapsed: 00:00:00.02
of course your names will vary.
Scott -
Help - query dates in Object browser!
Hi to everybody,
I need help on simple thing...
how can I build a query for dates in Object browser, in Oracle XE 10g?
I tried: >01-jan-2010, >"01-jan-2010", >'01-jan-2010', <>01-jan-2010 + ... all kind of derivations and nothing.
I always receive report error:
ORA-01858: a non-numeric character was found where a numeric was expected
I just want to filter some dates ...
thanksWith dates, its usually better to be specific with the date format, and not depend on "default" settings although (for US-English) the '01-jan-2011' should have worked, maybe not.
Are you trying to filter for a specific date, or range, i.e. ... where ... <date column> = <some date> or perhaps where <date column> between <date1> and <date2> ... ?
When looking for a date, it can be helpful to ignore the time component of a date field with the TRUNC() function:
select ... where trunc( <date column>) = to_date( '01-01-2011','yyyy-mm-dd') ...Note the to_date with the format mask, that will avoid troubles with assumptions about default date formats (which can also change with the locale ... i.e. UK-English the default client date format is 'dd-mm-yyyy') -
I am running windows xp with Oracle 9i Net client to connect to 8.1.7 database. I need to know if any one knows if query builder is bundled in any package certified for XP.
I have query builder in forms 6i but it does not work under XP. I noticed that Jdeveloper has a product called query builder, but looks nothing like the one in forms 6i. Is
this a totally differnt product or it's replacment?
Thanks for any help.Hi Dave,
In 9i, Query Builder stand alone has been obsoleted. It's still accessible in the Reports Builder, but I don't know if that helps you.
Toby -
Hi all,
i need your help here. i want to make a formatted search in AR invoice to take document number in Sales Order.
is my query correct like this:
select T0.docnum from ORDR left join OINV T1 where T1.docnum = $[$8.1.0]
please help me urgently...
thanksHello Fransisca,
You would take the documentnumber from salesOrder to Invoice?
It's not possible (with a query) to add the document number from the order to an invoice. Only when the order is closed INV1.TrgetEntry
But if you close the salesOrder you can click in the toolbar (Below the menubar (File - Edit - View - etc)) ' target document" SBO.opens the correct invoice.
I hope this helps you.
Good luck.
Best regards,
Teun
Edited by: Teun Aben on Jan 4, 2008 2:42 PM -
Query help : Query to get values SYSDATE-1 18:00 hrs to SYSDATE 08:00 hrs
Hi Team
I want the SQl query to get the data for the following comparison : -
Order Created is a Date Column , and i want to find out all the values from (SYSDATE-1) 18:00 hours to SYSDATE 08:00 hours
i.e.
(SYSDATE-1) 18:00:00 < Order.Created < SYSDATE 08:00:00.
RegardsHi, Rohit,
942281 wrote:
If i want the data in the below way i.e.
from (SYSDATE-1) 18:00 hours to SYSDATE 17:59 hours ---> (SYSDATE-1) 18:00:00 < Order.Created < SYSDATE 07:59:00.If you want to include rows from exactly 18:00:00 yesterday (but no earlier), and exclude rows from exatly 08:00:00 today (or later), then use:
WHERE ord_dtl.submit_dt >= TRUNC (SYSDATE) - (6 / 24)
AND ord_dtl.submit_dt < TRUNC (SYSDATE) + (8 / 24)
So can i use the below format : -
ord_dtl.submit_dt BETWEEN trunc(sysdate)-(6/24) and trunc(sysdate)+(7.59/24) . Please suggest . .59 hours is .59 * 60 * 60 = 2124 seconds (or .59 * 60 = 35.4 minutes), so the last time included in the range above is 07:35:24, not 07:59:59.
If you really, really want to use BETWEEN (which includes both end points), then you could do it with date arithmentic:
WHERE ord_dtl.submit_dt BETWEEN TRUNC (SYSDATE) - (6 / 24)
AND TRUNC (SYSDATE) + (8 / 24)
- (1 / (24 * 60 * 60))but it would be simpler and less error prone to use INTERVALs, as Karthick suggested earlier:
WHERE ord_dtl.submit_dt BETWEEN TRUNC (SYSDATE) - INTERVAL '6' HOUR
AND TRUNC (SYSDATE) + INTERVAL '8' HOUR
- INTERVAL '1' SECONDEdited by: Frank Kulash on Apr 17, 2013 9:36 AM
Edited by: Frank Kulash on Apr 17, 2013 11:56 AM
Changed "- (8 /24)" to "+ (8 /24)" in first code fragment (after Blushadown, below) -
Hi sap GURUS,
I NEED TO CREATE A F4 HELP FOR A FIELD IN MY SCREEN.THE FIELD IS INPUT FIELD AND ITS FROM A ZTABLE SOMETHING LIKE ZABC-ZDEF WHERE zABC IS TABLE AND ZDEF IS FIELD.
WHAT IS THE DIFFERENCE BETWEEN BETWEEN SEARCH HELP AND F4 HELP.IF ANY ONE HAS CODE RELATED TO THIS PLS DO SEND IT TO
[email protected]Hi,
Check this...instead of the standard table give ur table name
we can restrict the values in the F4 help as shown below when we use it like this.
if we create normal search help all the values come
types: begin of itab,
pernr type pernr_d,
end of itab.
data: itab type standard table of itab with header line.
parameters: p_pernr type vbpa-pernr ,"matchcode object zpernr,
p_parvw type vbpa-parvw ."matchcode object zparvw..
data: dynfields type table of dynpread ,
wa type dynpread.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_pernr.
select pernr from vbpa into table itab where parvw = 'KB'.
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
DDIC_STRUCTURE = ' '
RETFIELD = 'PERNR'
PVALKEY = ' '
DYNPPROG = sy-repid
DYNPNR = sy-dynnr
DYNPROFIELD = 'P_PERNR'
STEPL = 0
WINDOW_TITLE = WINDOW_TITLE
VALUE = ' '
VALUE_ORG = 'S'
MULTIPLE_CHOICE = ' '
DISPLAY = ' '
CALLBACK_PROGRAM = ' '
CALLBACK_FORM = ' '
MARK_TAB = MARK_TAB
IMPORTING
USER_RESET = USER_RESET
TABLES
VALUE_TAB = itab
FIELD_TAB = FIELD_TAB
RETURN_TAB = RETURN_TAB
DYNPFLD_MAPPING = DYNPFLD_MAPPING
EXCEPTIONS
PARAMETER_ERROR = 1
NO_VALUES_FOUND = 2
OTHERS = 3
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
Regards,
Vidya -
Very Urgent Help : Query Clarification
I have installed 0IC_C03 cube.Data is matching perfectly with R/3. I have one query regarding opening and closing stock. Opening stock for this month is stock of last day of previous month. How to get this thing in Bex report.
I tried restricting stock quantity to the last date of previous month using restricted key figure but output is not correct. Restriction is not having any effect.
Can you please suggestBaljith,
Display your Previous month stock in the report and hide it. For current month opening stock column, create a variable, get last month stock and put into current month opening stock.
hope this will work...
mahantesh -
The below query runs in a second where the po_requisition_header _d in line 42 (5063 value) is hard coded. However, when it is joined to the outer query it takes minutes.
I have tried using hints. maybe I'm not using the right hint? Could does someone have any insight on how i can optimize this SQL query?
SELECT GCC.SEGMENT1
||'-'
||PORH.SEGMENT1
||'-'
||TO_CHAR(PORH.CREATION_DATE,'yy') CER_NUMBER,
PORH.AUTHORIZATION_STATUS STATUS,
REPLACE(SUBSTR(PORH.DESCRIPTION,DECODE(INSTR(PORH.DESCRIPTION,'~'),0,1,
(INSTR(PORH.DESCRIPTION,'~') + 1)),
LENGTH(PORH.DESCRIPTION)),'"') DESCRIPTION,
PORH.SEGMENT1 REQ_NUMBER,
PHA.SEGMENT1 PO_NUMBER,
MC.ATTRIBUTE3 MAJOR_CATEGORY,
GCC.SEGMENT1 DIVISION,
GCC.SEGMENT2 DISTRICT,
GCC.SEGMENT4 CCC,
PPX2.FULL_NAME PREPARER,
PPX.FULL_NAME REQUESTER,
PAA.ADDRESS_LINE1 ADDRESS_LINE1,
NVL(PAA.STATE,PAA.PROVINCE) STATE,
PAA.CITY CITY,
PLA.LOCATION_CODE BUILDING,
PORH.ATTRIBUTE1 PROJECT_NUMBER,
FV.DESCRIPTION PROJECT_DESCRIPTION,
PORH.ATTRIBUTE4 BREASON,
PORH.ATTRIBUTE9 BUSINESS_UNIT,
PORH.ATTRIBUTE3 ORIGINAL_CER,
TRUNC(PORH.CREATION_DATE) SUBMIT_DATE,
TRUNC(PORH.APPROVED_DATE) APPROVED_DATE,
(SELECT TO_CHAR(SUM((NVL(PORL2.UNIT_PRICE,0) * NVL(PORL2.QUANTITY,0))),
'FM999999990D00')
FROM PO_REQUISITION_LINES_ALL PORL2
WHERE PORL2.REQUISITION_HEADER_ID = PORH.REQUISITION_HEADER_ID) REQUISITION_AMOUNT,
(SELECT TO_CHAR(SUM(NVL(AIA.INVOICE_AMOUNT,0)),'FM999999990D00')
FROM AP_INVOICES_ALL AIA
WHERE AIA.INVOICE_ID in
(SELECT AIA3.INVOICE_ID
FROM PO_REQUISITION_LINES_ALL PORL3,
AP_INVOICES_ALL AIA3,
AP_INVOICE_DISTRIBUTIONS_ALL AID3,
PO_DISTRIBUTIONS_ALL PDA3,
PO_REQ_DISTRIBUTIONS_ALL PRDA3
WHERE PORL3.REQUISITION_HEADER_ID = PORH.REQUISITION_HEADER_ID -- 5063 is the header id for rec 12168
AND PORL3.REQUISITION_LINE_ID = PRDA3.REQUISITION_LINE_ID
AND PRDA3.DISTRIBUTION_ID = PDA3.REQ_DISTRIBUTION_ID (+)
AND PDA3.PO_DISTRIBUTION_ID = AID3.PO_DISTRIBUTION_ID (+)
AND AID3.INVOICE_ID = AIA3.INVOICE_ID
group by AIA3.INVOICE_ID)) INVOICE_AMOUNT
FROM PO_REQUISITION_HEADERS_ALL PORH,
PO_REQUISITION_LINES_ALL PORL,
MTL_CATEGORIES MC,
PN_LOCATIONS_ALL PLA,
PN_ADDRESSES_ALL PAA,
PER_PEOPLE_X PPX,
PER_PEOPLE_X PPX2,
PO_HEADERS_ALL PHA,
PO_LINES_ALL PLA,
PO_LINE_LOCATIONS_ALL PLLA,
FND_FLEX_VALUES_VL FV,
FND_FLEX_VALUE_SETS FVS,
PO_REQ_DISTRIBUTIONS_ALL PRDA,
GL_CODE_COMBINATIONS GCC
WHERE PORH.REQUISITION_HEADER_ID = PORL.REQUISITION_HEADER_ID
AND PORL.LINE_NUM = (SELECT MIN(PORL2.LINE_NUM)
FROM PO.PO_REQUISITION_LINES_ALL PORL2
WHERE PORH.REQUISITION_HEADER_ID = PORL2.REQUISITION_HEADER_ID)
AND PORL.REQUISITION_LINE_ID = PRDA.REQUISITION_LINE_ID
AND PRDA.CODE_COMBINATION_ID = GCC.CODE_COMBINATION_ID
AND PORL.TO_PERSON_ID = PPX.PERSON_ID
AND PORH.PREPARER_ID = PPX2.PERSON_ID
AND MC.CATEGORY_ID = PORL.CATEGORY_ID
AND PORH.ATTRIBUTE5 = PLA.LOCATION_ID
AND PLA.ADDRESS_ID = PAA.ADDRESS_ID (+)
AND PORL.LINE_LOCATION_ID = PLLA.LINE_LOCATION_ID
AND PLA.PO_LINE_ID = PLLA.PO_LINE_ID
AND PHA.PO_HEADER_ID = PLA.PO_HEADER_ID
AND DECODE(PORH.ATTRIBUTE1,'N/A','XNULL',PORH.ATTRIBUTE1) = FV.FLEX_VALUE (+)
AND FV.FLEX_VALUE_SET_ID (+) = 1009209 --SR12372
AND FV.FLEX_VALUE_SET_ID = FVS.FLEX_VALUE_SET_ID (+)
AND PORH.AUTHORIZATION_STATUS IN ('APPROVED')
AND PORH.ATTRIBUTE2 IN ('Budgeted',
'Unbudgeted',
'Additional Amount')
AND PORH.ATTRIBUTE_CATEGORY = 'CAPEX'
and porh.segment1 = '12168'
Thank you,
paulWell...Here is the explain plan.
The problem line in this explain plain is ...
TABLE ACCESS FULL AP.AP_INVOICES_ALL 2 M 30 M 35641
Operation Object Name Rows Bytes Cost Object Node In/Out PStart PStop
SELECT STATEMENT Optimizer Mode=ALL_ROWS 1 66
SORT AGGREGATE 1 13
TABLE ACCESS BY INDEX ROWID PO.PO_REQUISITION_LINES_ALL 3 39 4
INDEX RANGE SCAN PO.PO_REQUISITION_LINES_U2 3 2
SORT AGGREGATE 1 11
FILTER
TABLE ACCESS FULL AP.AP_INVOICES_ALL 2 M 30 M 35641
FILTER
SORT GROUP BY 1 42 1403
NESTED LOOPS 2 84 1402
NESTED LOOPS 2 72 1402
NESTED LOOPS 2 56 9
NESTED LOOPS 3 57 7
TABLE ACCESS BY INDEX ROWID PO.PO_REQUISITION_LINES_ALL 3 27 4
INDEX RANGE SCAN PO.PO_REQUISITION_LINES_U2 3 2
TABLE ACCESS BY INDEX ROWID PO.PO_REQ_DISTRIBUTIONS_ALL 1 10 1
INDEX RANGE SCAN PO.PO_REQ_DISTRIBUTIONS_N1 1 0
TABLE ACCESS BY INDEX ROWID PO.PO_DISTRIBUTIONS_ALL 1 9 1
INDEX RANGE SCAN PO.PO_DISTRIBUTIONS_N2 1 0
TABLE ACCESS BY INDEX ROWID AP.AP_INVOICE_DISTRIBUTIONS_ALL 1 8 1393
INDEX RANGE SCAN AP.AP_INVOICE_DISTRIBUTIONS_N7 2 K 0
INDEX UNIQUE SCAN AP.AP_INVOICES_U1 1 6 0
NESTED LOOPS OUTER 1 459 64
NESTED LOOPS 1 416 63
NESTED LOOPS 1 397 62
NESTED LOOPS 1 379 61
NESTED LOOPS 1 321 58
NESTED LOOPS 1 311 57
NESTED LOOPS 1 303 57
NESTED LOOPS OUTER 1 295 56
HASH JOIN OUTER 1 289 56
NESTED LOOPS 1 254 10
NESTED LOOPS 1 241 9
NESTED LOOPS 1 233 8
NESTED LOOPS 1 225 7
NESTED LOOPS 1 201 6
TABLE ACCESS BY INDEX ROWID PO.PO_REQUISITION_HEADERS_ALL 1 143 3
INDEX RANGE SCAN PO.PO_REQUISITION_HEADERS_U2 1 2
TABLE ACCESS BY INDEX ROWID HR.PER_ALL_PEOPLE_F 1 58 3
INDEX RANGE SCAN HR.PER_PEOPLE_F_PK 3 0
TABLE ACCESS BY INDEX ROWID PO.PO_REQUISITION_LINES_ALL 1 24 1
INDEX UNIQUE SCAN PO.PO_REQUISITION_LINES_U2 1 0
SORT AGGREGATE 1 7
FIRST ROW 3 21 2
INDEX RANGE SCAN (MIN/MAX) PO.PO_REQUISITION_LINES_U2 3 21 2
TABLE ACCESS BY INDEX ROWID PO.PO_LINE_LOCATIONS_ALL 1 8 1
INDEX UNIQUE SCAN PO.PO_LINE_LOCATIONS_U1 1 0
TABLE ACCESS BY INDEX ROWID PO.PO_LINES_ALL 1 8 1
INDEX UNIQUE SCAN PO.PO_LINES_U1 1 0
TABLE ACCESS BY INDEX ROWID PO.PO_HEADERS_ALL 1 13 1
INDEX UNIQUE SCAN PO.PO_HEADERS_U1 1 0
VIEW APPS.FND_FLEX_VALUES_VL 55 1 K 45
NESTED LOOPS 55 2 K 45
TABLE ACCESS BY INDEX ROWID APPLSYS.FND_FLEX_VALUES 41 820 4
INDEX RANGE SCAN APPLSYS.FND_FLEX_VALUES_N3 41 1
TABLE ACCESS BY INDEX ROWID APPLSYS.FND_FLEX_VALUES_TL 1 31 1
INDEX UNIQUE SCAN APPLSYS.FND_FLEX_VALUES_TL_U1 1 0
INDEX UNIQUE SCAN APPLSYS.FND_FLEX_VALUE_SETS_U1 1 6 0
TABLE ACCESS BY INDEX ROWID INV.MTL_CATEGORIES_B 1 8 1
INDEX UNIQUE SCAN INV.MTL_CATEGORIES_B_U1 1 0
INDEX UNIQUE SCAN INV.MTL_CATEGORIES_TL_U1 1 8 0
TABLE ACCESS BY INDEX ROWID PO.PO_REQ_DISTRIBUTIONS_ALL 1 10 1
INDEX RANGE SCAN PO.PO_REQ_DISTRIBUTIONS_N1 1 0
TABLE ACCESS BY INDEX ROWID HR.PER_ALL_PEOPLE_F 1 58 3
INDEX RANGE SCAN HR.PER_PEOPLE_F_PK 3 0
TABLE ACCESS BY INDEX ROWID GL.GL_CODE_COMBINATIONS 1 18 1
INDEX UNIQUE SCAN GL.GL_CODE_COMBINATIONS_U1 1 0
TABLE ACCESS BY INDEX ROWID PN.PN_LOCATIONS_ALL 1 19 1
INDEX RANGE SCAN PN.PN_LOCATIONS_U1 1 0
TABLE ACCESS BY INDEX ROWID PN.PN_ADDRESSES_ALL 1 43 1
INDEX UNIQUE SCAN PN.PN_ADDRESSES_U1 1 0
Maybe you are looking for
-
I've tried a few browsers, but want to go back to only Firefox as default browser. I can find it and allocate it in the Administrator profile, but not my daily use, standard user. It doesn't even appear in the list of programs to assign defaults. And
-
Cannot sync my ipad because the connection was reset?
I can't sync my ipad or iphone because an error code comes up stating that it cannot be synced because the connection was reset. It comes up after the backup process of the sync session.
-
When I connected my Ipod Touch (4g) to my WIndows XP PC on iTunes I selected transfer purchases from my iPod and after having to restart the process(crashed) I realized I had lost significant amount of songs. (missing entire albums) How do I get them
-
Mass deletion of Parked doucments
hi all, is there a tran code we could use to delete parked documents in mass. thank you nagesh
-
How to get system temp dir. path on the fly ,system may be XP or Linux ??
How to get system temp dir. path on the fly ,system may be XP or Linux ?? please suggest solution