Help needed on income statement query....
Hello BW gurus,
I need to make an income-statement query which gives the following output.
The 5 Variables are
Company Code
Plant
Fiscal Period (12 months) in column
Value Type
Version
#ACCOUNT 0METYPE METYPE-DESCRIPTION COMPANYCODE PLANT SALES0RG
Sales
Cost of Sales
Gross Margin
(Sales minus Cost Of Sales)
General &Admin
Other
Operating Income
(Gross margin minus G&A minus Other)
Interest Income
Interest Expense
Net Income before Tax
(Operating Income minus Interest Income - Interest expense)
Taxes
Net income
(Net Income before Tax minus Taxes)
Note: Sales,cost of sales,general and admin,other,interesat income,interest expense,taxes are under the hierarchy of ACCOUNT.
Please make a quick response.
100% points will be awarded.
Thanks in advance.
Sam Mathew
Please read these:
When your query takes too long
When your query takes too long ...
How to Post a SQL statement tuning request
HOW TO: Post a SQL statement tuning request - template posting
Similar Messages
-
Help needed to optimize the query
Help needed to optimize the query:
The requirement is to select the record with max eff_date from HIST_TBL and that max eff_date should be > = '01-Jan-2007'.
This is having high cost and taking around 15mins to execute.
Can anyone help to fine-tune this??
SELECT c.H_SEC,
c.S_PAID,
c.H_PAID,
table_c.EFF_DATE
FROM MTCH_TBL c
LEFT OUTER JOIN
(SELECT b.SEC_ALIAS,
b.EFF_DATE,
b.INSTANCE
FROM HIST_TBL b
WHERE b.EFF_DATE =
(SELECT MAX (b2.EFF_DATE)
FROM HIST_TBL b2
WHERE b.SEC_ALIAS = b2.SEC_ALIAS
AND b.INSTANCE =
b2.INSTANCE
AND b2.EFF_DATE >= '01-Jan-2007')
OR b.EFF_DATE IS NULL) table_c
ON table_c.SEC_ALIAS=c.H_SEC
AND table_c.INSTANCE = 100;To start with, I would avoid scanning HIST_TBL twice.
Try this
select c.h_sec
, c.s_paid
, c.h_paid
, table_c.eff_date
from mtch_tbl c
left
join (
select sec_alias
, eff_date
, instance
from (
select sec_alias
, eff_date
, instance
, max(eff_date) over(partition by sec_alias, instance) max_eff_date
from hist_tbl b
where eff_date >= to_date('01-jan-2007', 'dd-mon-yyyy')
or eff_date is null
where eff_date = max_eff_date
or eff_date is null
) table_c
on table_c.sec_alias = c.h_sec
and table_c.instance = 100; -
I need to fetch records from a table. Please help me to create a query
The Tablename is Employee. It has the following records
Department Empname Gender
Finance Tom Male
Finance Rick Male
Finance Stacy Female
Corporate Tom Male
Corporate Rob Male
I want to select the value of the Gender field from the Employee table corresponding to a Department
If all the values in the Gender field are 'MALE' corresponding to 'finance' in the Department field, the value should be 'MALE'
If there is a value 'FEMALE', the gender corresponding to the Empname 'TOM' should be considered as the genderTables have rows - not records.
Your question is a basic SQL language question - which means you do not know the SQL language. This forum is not a classroom for teaching you the SQL language.
Use the following as the basic outline of how your SQL language statement need to look like for selecting the required from the table:
SELECT
<<sql projection goes here>>
FROM <<table name goes here>>
WHERE <<filter conditions go here>>
{code}
The SQL projection specifies the list of columns the SQL need to return to the caller.
The filter condition is basic predicates and AND and OR can be used for multiple predicates.
Go to http://tahiti.oracle.com and look for the +SQL Reference Guide+ for the Oracle version you are using. The +SELECT+ statement syntax is covered in detail and sample statements are provided.
And please do not expect this forum to be used as a classroom, or expect this forum to do your homework for a class. -
Help needed to tune the Query:Statistics added
Can someone DBA please help me to tune this query:
SELECT DISTINCT K.ATTRIBUTE_VALUE AGENCY_ID,B.PROFILE_NM ,NVL(G.OFFICE_DESC,'--') OFFICE_DESC,f.OFFICE_ID,B.PROFILE_ID,'%' ROLE,'%' LAYOUT,
CASE
WHEN 'flagB' = '%' THEN
NVL(J.ISS_GRP_DESC,'BILLING')
WHEN 'flagO' = '%' THEN
NVL(J.ISS_GRP_DESC,'ORDERING')
WHEN 'flag' = '%' THEN
NVL(J.ISS_GRP_DESC,'BILLING/ORDERING')
ELSE
NVL(J.ISS_GRP_DESC,' ')
END ISS_GRP_DESC,
DECODE(NVL(H.USERID,' ') ,' ','--','<a sbcuid_in=' || H.USERID || ' target=NEW >'||H.FIRSTNAME || ' ' || H.LASTNAME || '( ' || H.USERID || ' )</a>' ) USER_NAME
FROM
PROFILE_PORTAL B ,
TBL_BDA_AGENCY_RESP_REP C ,
TBL_BDA_AGENCY_OFFICE F,
TBL_BDA_OFFICE G,
USERS_PORTAL H,
TBL_BDA_USR_ISS_GRP I ,
TBL_BDA_ISS_GROUP J,
ATTRIBUTE_VALUES_PORTAL K,
PROFILE_TYPE_PORTAL L
WHERE
B.PROFILE_ID = F.AGENCY_ID (+)
AND B.PROFILE_ID = C.AGENCY_ID (+)
AND G.OFFICE_ID (+)= F.OFFICE_ID
AND H.USERID (+)= C.RESP_USR_ID
AND C.ISS_GRP_ID = I.ISS_GRP_ID (+)
AND I.ISS_GRP_ID = J.ISS_GRP_ID(+)
AND 'PROFILE.'||B.PROFILE_ID = K.ENTITY_ID(+)
AND K.ATTRIBUTE_VALUE IS NOT NULL
AND L.PROFILE_TYPE_ID = B.PROFILE_TYPE_ID
AND L.APPLICATION_CD='BDA'
AND NOT EXISTS (SELECT agency_id
FROM TBL_BDA_AGENCY_RESP_REP t
WHERE t.ISS_GRP_ID IN ('%')
AND t.AGENCY_ID = C.AGENCY_ID)
AND K.ATTRIBUTE_VALUE LIKE '%'
AND UPPER(B.PROFILE_NM) LIKE UPPER('%')
AND (to_char(NVL(B.PROFILE_ID,0)) LIKE '%' OR NVL(B.PROFILE_ID,0) IN ('a'))
AND NVL(G.OFFICE_ID,0) IN ('%')
AND (to_char(NVL(C.RESP_USR_ID,'0')) LIKE '%' OR NVL(C.RESP_USR_ID,'0') IN ('k'))
ORDER BY PROFILE_NM
The number of rows in these tables are as follows:
PROFILE_PORTAL -- 2392
TBL_BDA_AGENCY_RESP_REP 3508
TBL_BDA_AGENCY_OFFICE 2151
TBL_BDA_OFFICE 3
USERS_PORTAL 270500
TBL_BDA_USR_ISS_GRP 234
TBL_BDA_ISS_GROUP 2
ATTRIBUTE_VALUES_PORTAL 2790
PROFILE_TYPE_PORTAL 3
The Explain pal nhas given this o/p to me:
SQL> select * from table(dbms_xplan.display) dual;
PLAN_TABLE_OUTPUT
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost |
| 0 | SELECT STATEMENT | | 807 | 102K| | 2533 |
| 1 | SORT UNIQUE | | 807 | 102K| 232K| 82 |
|* 2 | FILTER | | | | | |
|* 3 | HASH JOIN OUTER | | 807 | 102K| | 52 |
|* 4 | HASH JOIN OUTER | | 807 | 95226 | | 40 |
|* 5 | TABLE ACCESS BY INDEX ROWID | ATTRIBUTE_VALUES | 1 | 23 | | 2 |
| 6 | NESTED LOOPS | | 7 | 805 | | 37 |
| 7 | NESTED LOOPS OUTER | | 6 | 552 | | 25 |
|* 8 | FILTER | | | | | |
| 9 | NESTED LOOPS OUTER | | | | | |
|* 10 | FILTER | | | | | |
| 11 | NESTED LOOPS OUTER | | | | | |
| 12 | NESTED LOOPS OUTER | | 3 | 141 | | 10 |
|* 13 | HASH JOIN | | 3 | 120 | | 7 |
|* 14 | TABLE ACCESS FULL | PROFILE | 6 | 198 | | 4 |
|* 15 | TABLE ACCESS FULL | PROFILE_TYPE | 1 | 7 | | 2 |
|* 16 | INDEX RANGE SCAN | SYS_C0019777 | 1 | 7 | | 1 |
| 17 | TABLE ACCESS BY INDEX ROWID| TBL_BDA_OFFICE | 1 | 10 | | 1 |
|* 18 | INDEX UNIQUE SCAN | SYS_C0019800 | 1 | | | |
| 19 | TABLE ACCESS BY INDEX ROWID | TBL_BDA_AGENCY_RESP_REP | 2 | 26 | | 2 |
|* 20 | INDEX RANGE SCAN | IDX_AGECYRESP_AGNCYID | 2 | | | 1 |
| 21 | TABLE ACCESS BY INDEX ROWID | USER_ | 1 | 22 | | 1 |
|* 22 | INDEX UNIQUE SCAN | USER_PK | 1 | | | |
|* 23 | INDEX RANGE SCAN | IDX_ATTVAL_ENTATTID | 1 | | | 1 |
| 24 | TABLE ACCESS FULL | TBL_BDA_USR_ISS_GRP | 234 | 702 | | 2 |
| 25 | TABLE ACCESS FULL | TBL_BDA_ISS_GROUP | 2 | 24 | | 2 |
|* 26 | TABLE ACCESS BY INDEX ROWID | TBL_BDA_AGENCY_RESP_REP | 1 | 7 | | 3 |
|* 27 | INDEX RANGE SCAN | IDX_AGECYRESP_AGNCYID | 2 | | | 1 |
Predicate Information (identified by operation id):
2 - filter( NOT EXISTS (SELECT /*+ */ 0 FROM "TBL_BDA_AGENCY_RESP_REP" "T" WHERE "T"."AGENCY_ID"=:B1
AND "T"."ISS_GRP_ID"=TO_NUMBER('%')))
3 - access("I"."ISS_GRP_ID"="J"."ISS_GRP_ID"(+))
4 - access("SYS_ALIAS_1"."ISS_GRP_ID"="I"."ISS_GRP_ID"(+))
5 - filter("K"."ATTRIBUTE_VALUE" IS NOT NULL AND "K"."ATTRIBUTE_VALUE" LIKE '%')
8 - filter(NVL("SYS_ALIAS_1"."RESP_USR_ID",'0') LIKE '%' OR NVL("SYS_ALIAS_1"."RESP_USR_ID",'0')='k')
10 - filter(NVL("G"."OFFICE_ID",0)=TO_NUMBER('%'))
13 - access("L"."PROFILE_TYPE_ID"="B"."PROFILE_TYPE_ID")
14 - filter(UPPER("B"."PROFILE_NM") LIKE '%' AND (TO_CHAR(NVL("B"."PROFILE_ID",0)) LIKE '%' OR
NVL("B"."PROFILE_ID",0)=TO_NUMBER('a')))
15 - filter("L"."APPLICATION_CD"='BDA')
16 - access("B"."PROFILE_ID"="F"."AGENCY_ID"(+))
18 - access("G"."OFFICE_ID"(+)="F"."OFFICE_ID")
20 - access("B"."PROFILE_ID"="SYS_ALIAS_1"."AGENCY_ID"(+))
22 - access("H"."USERID"(+)="SYS_ALIAS_1"."RESP_USR_ID")
23 - access("K"."ENTITY_ID"='PROFILE.'||TO_CHAR("B"."PROFILE_ID"))
26 - filter("T"."ISS_GRP_ID"=TO_NUMBER('%'))
27 - access("T"."AGENCY_ID"=:B1)
Note: cpu costing is off
57 rows selected.
Elapsed: 00:00:01.08
Please help me.
Aashish S.Hello Eric,
Here is the code:
SELECT DISTINCT
K.ATTRIBUTE_VALUE AGENCY_ID,
B.PROFILE_NM ,
NVL(G.OFFICE_DESC,'--') OFFICE_DESC,
f.OFFICE_ID,
B.PROFILE_ID,
'%' ROLE,
'%' LAYOUT,
case
WHEN 'flagB' = '%' THEN
NVL(J.ISS_GRP_DESC,'BILLING')
WHEN 'flagO' = '%' THEN
NVL(J.ISS_GRP_DESC,'ORDERING')
WHEN 'flag' = '%' THEN
NVL(J.ISS_GRP_DESC,'BILLING/ORDERING')
else
NVL(J.ISS_GRP_DESC,' ')
END ISS_GRP_DESC,
DECODE(NVL(H.USERID,' ') ,' ','--','<a sbcuid_in=' || H.USERID || ' target=NEW >'||H.FIRSTNAME || ' ' || H.LASTNAME ||
'( ' || H.USERID || ' )</a>' ) USER_NAME
from
PROFILE_PORTAL B ,
TBL_BDA_AGENCY_RESP_REP C ,
TBL_BDA_AGENCY_OFFICE F,
TBL_BDA_OFFICE G,
USERS_PORTAL H,
TBL_BDA_USR_ISS_GRP I ,
TBL_BDA_ISS_GROUP J,
ATTRIBUTE_VALUES_PORTAL K,
PROFILE_TYPE_PORTAL L
WHERE
B.PROFILE_ID = F.AGENCY_ID (+)
AND B.PROFILE_ID = C.AGENCY_ID (+)
AND G.OFFICE_ID (+)= F.OFFICE_ID
AND H.USERID (+)= C.RESP_USR_ID
AND C.ISS_GRP_ID = I.ISS_GRP_ID (+)
AND I.ISS_GRP_ID = J.ISS_GRP_ID(+)
AND 'PROFILE.'||B.PROFILE_ID = K.ENTITY_ID(+)
AND K.ATTRIBUTE_VALUE IS NOT NULL
AND L.PROFILE_TYPE_ID = B.PROFILE_TYPE_ID
AND L.APPLICATION_CD='BDA'
AND NOT EXISTS
(SELECT agency_id
FROM TBL_BDA_AGENCY_RESP_REP t
WHERE t.ISS_GRP_ID IN (1)
AND t.AGENCY_ID = C.AGENCY_ID)
AND K.ATTRIBUTE_VALUE LIKE '%'
AND UPPER(B.PROFILE_NM) LIKE UPPER('%')
AND (to_char(NVL(B.PROFILE_ID,0))
LIKE '%'
OR NVL(B.PROFILE_ID,0) IN (1))
AND NVL(G.OFFICE_ID,0) IN (1)
AND (to_char(NVL(C.RESP_USR_ID,'0'))
LIKE '%'
OR NVL(C.RESP_USR_ID,'0') IN ('%'))
ORDER BY PROFILE_NM
This is the Query and the query takes some mins. to run in prod environment.
From the Query plan ,I am not able to get any idea for optimization.
Now,Can you tell me which steps I need to follow to run it faster and which all modifications should be made?
Thanks.
Aashish S. -
Help needed in writing a query
Hi all,
Following is the structure of my table.
Data
Key Number
Id Number
Value varchar2(100)
activity_name varchar2(100)
Creation_Date Date
Eval_Point varchar2(100)
In the above table Id is the primary key.
The column eval_point holds only two types of entries 'activation' or 'completion'
The activity_name column holds the name of the activity.
The sample entries in the table are as follows
Key Value activity_name Creation_Date Id Eval_Point
260002 XXX assign_1 2007-09-21 16:58:41.920000 951 activation
260002 XXX assign_1 2007-09-21 16:58:43.392000 953 completion
260002 XXX assign_2 2007-09-21 16:59:03.732000 956 activation
260002 XXX assign_2 2007-09-21 16:59:04.112000 954 completion
260002 XXX assign_3 2007-09-21 16:59:24.331000 958 activation
260002 XXX assign_3 2007-09-21 16:59:24.421000 957 completion
i need to write a query which gives me data in the following format
value id start_date end_date
XXX YYY 2007-09-21 16:58:41.920000 2007-09-21 16:58:43.392000
where start_date is the creation date of the 'activation' and end_date is the creation_date of 'completion'.
Can somebody help?
-thanks
lavanyahello all,
I would like to re frame my question.
this is the output of the base query
select id,instance_key,sensor_target,activity_sensor,creation_date,eval_point from bpel_variable_sensor_values where instance_key=260002;
953 260002 Assign_1 952 2007-09-21 16:58:43.392000 completion
951 260002 Assign_1 952 2007-09-21 16:58:41.920000 activation
956 260002 Assign_2 955 2007-09-21 16:59:03.732000 activation
954 260002 Assign_2 955 2007-09-21 16:59:04.112000 completion
958 260002 Assign_3 959 2007-09-21 16:59:24.331000 activation
957 260002 Assign_3 959 2007-09-21 16:59:24.421000 completion
962 260002 Assign_4 960 2007-09-21 16:59:44.741000 completion
961 260002 Assign_4 960 2007-09-21 16:59:44.640000 activation
964 260002 Assign_5 965 2007-09-21 17:00:05.290000 completion
963 260002 Assign_5 965 2007-09-21 17:00:04.950000 activation
I am trying out this query
select a.instance_key,a.creation_date,b.creation_date,a.id
from bpel_variable_sensor_values a, bpel_variable_sensor_values b
where a.instance_key=b.instance_key
and a.instance_key=260002
and a.eval_point='activation'
and b.eval_point='completion'
and i am getting 25 entries i.e a cartesian product of a.creation_date
260002 2007-09-21 16:58:41.920000 2007-09-21 16:58:43.392000 951
260002 2007-09-21 16:58:41.920000 2007-09-21 16:59:04.112000 951
260002 2007-09-21 16:58:41.920000 2007-09-21 16:59:24.421000 951
260002 2007-09-21 16:58:41.920000 2007-09-21 16:59:44.741000 951
260002 2007-09-21 16:58:41.920000 2007-09-21 17:00:05.290000 951
260002 2007-09-21 16:59:03.732000 2007-09-21 16:58:43.392000 956
260002 2007-09-21 16:59:03.732000 2007-09-21 16:59:04.112000 956
260002 2007-09-21 16:59:03.732000 2007-09-21 16:59:24.421000 956
260002 2007-09-21 16:59:03.732000 2007-09-21 16:59:44.741000 956
260002 2007-09-21 16:59:03.732000 2007-09-21 17:00:05.290000 956
260002 2007-09-21 16:59:24.331000 2007-09-21 16:58:43.392000 958
260002 2007-09-21 16:59:24.331000 2007-09-21 16:59:04.112000 958
260002 2007-09-21 16:59:24.331000 2007-09-21 16:59:24.421000 958
260002 2007-09-21 16:59:24.331000 2007-09-21 16:59:44.741000 958
260002 2007-09-21 16:59:24.331000 2007-09-21 17:00:05.290000 958
260002 2007-09-21 16:59:44.640000 2007-09-21 16:58:43.392000 961
260002 2007-09-21 16:59:44.640000 2007-09-21 16:59:04.112000 961
260002 2007-09-21 16:59:44.640000 2007-09-21 16:59:24.421000 961
260002 2007-09-21 16:59:44.640000 2007-09-21 16:59:44.741000 961
260002 2007-09-21 16:59:44.640000 2007-09-21 17:00:05.290000 961
260002 2007-09-21 17:00:04.950000 2007-09-21 16:58:43.392000 963
260002 2007-09-21 17:00:04.950000 2007-09-21 16:59:04.112000 963
260002 2007-09-21 17:00:04.950000 2007-09-21 16:59:24.421000 963
260002 2007-09-21 17:00:04.950000 2007-09-21 16:59:44.741000 963
260002 2007-09-21 17:00:04.950000 2007-09-21 17:00:05.290000 963
can soembody help me to reduce these to 5 rows. -
Help needed in framing SQL query.
Hi,
I have table having following schema:
PRODUCT_ID INT
DATE DATETIME
ITEMS_SOLD INT
This table contains data for a week (sunday to saturday). I want to write an SQL query to get (filter out) PRODUCT_ID of products which has same no. of ITEMS_SOLD for all 7 days. Also for given PRODUCT_ID I need to find the longest period of successive days where the no. of ITEMS_SOLD is same for all days in this period. Eg.(PRODUCT_ID 23 was sold as following along the week in no. of units sold: 4,6,6,6,6,7,4 .So the longest period is *4 days* from Monday to Thursday.) The first condition is special case of second condition where no. of days is 7.
Any help to get the SQL query will be appreciated.
Thanks,
Akshay.PRODUCT_ID DATE ITEMS_SOLD
1 10/10/2011 3
1 11/10/2011 3
1 12/10/2011 3
1 13/10/2011 3
1 16/10/2011 5
2 10/10/2011 4
2 11/10/2011 4
2 12/10/2011 4
2 13/10/2011 4
2 14/10/2011 4
2 15/10/2011 4
2 16/10/2011 4
Output:
PRODUCT_ID ITEMS_SOLD NO_OF_DAYS
1 3 4
2 4 7
Explanation of results:
The table to be queried contains data for 1 week: from 10/10/2011(Sunday) to 16/10/2011(Saturday). Now, product with PRODUCT_ID '1' was sold on dates 10,11,12,13,16. Out of these 5 days 3 units were sold on 4 successive days (from 10-13). So output should be like :
PRODUCT_ID ITEMS_SOLD NO_OF_DAYS
1 3 4
as longest period of successive days is 4 where same no. of units were sold i.e 3 units (other period is of 1 day on 16th ).
For PRODUCT_ID 2 we have only one period of 7 days where 4 units were sold each day. So we output :
PRODUCT_ID ITEMS_SOLD NO_OF_DAYS
2 4 7
Other case where same PRODUCT_ID have different units sold on each day should be ignored.
I hope that clarifies the problem more. Let me know in case I have missed out anything which should have been mentioned.
-Akshay. -
Urgent help needed....Query..
Hello Experts
Can someone help with writing a particular query. This is the test scenario
CREATE TABLE TEST (MONTH DATE,
AMOUNT NUMBER(17));
INSERT INTO TEST VALUES('01-FEB-06',100);
INSERT INTO TEST VALUES('01-MAR-06',100);
INSERT INTO TEST VALUES('01-APR-06',100);
INSERT INTO TEST VALUES('01-JUN-06',100);
INSERT INTO TEST VALUES('01-JUL-06',100);
INSERT INTO TEST VALUES('01-AUG-06',100);
INSERT INTO TEST VALUES('01-SEP-06',100);
INSERT INTO TEST VALUES('01-OCT-06',100);
INSERT INTO TEST VALUES('01-NOV-06',100);
INSERT INTO TEST VALUES('01-DEC-06',100);
INSERT INTO TEST VALUES('01-JAN-07',100);
INSERT INTO TEST VALUES('01-FEB-07',100);
INSERT INTO TEST VALUES('01-MAR-07',100);
INSERT INTO TEST VALUES('01-APR-07',100);
INSERT INTO TEST VALUES('01-MAY-07',100);
INSERT INTO TEST VALUES('01-JUN-07',100);
INSERT INTO TEST VALUES('01-JUL-07',100);
INSERT INTO TEST VALUES('01-AUG-07',100);
INSERT INTO TEST VALUES('01-SEP-07',100);
INSERT INTO TEST VALUES('01-OCT-07',100);
INSERT INTO TEST VALUES('01-NOV-07',100);
INSERT INTO TEST VALUES('01-DEC-07',100);
INSERT INTO TEST VALUES('01-JAN-08',100);
INSERT INTO TEST VALUES('01-FEB-08',100);
INSERT INTO TEST VALUES('01-MAR-08',100);
INSERT INTO TEST VALUES('01-APR-08',100);
INSERT INTO TEST VALUES('01-MAY-08',100);
INSERT INTO TEST VALUES('01-JUN-08',100);
Ok so thats my test table, I want a query which will give me the sum of the field Amount grouping by Year but it should give me the sum of the month from July 06 till July 07. For Example if i put the Date Range from 2003 to 2006 then it should give me out put by group the year from july till next year jun.
It should look something like this
Year Amount
07-2005/06-2006 5000
07-2006/06-2007 2000
07-2007/06-2008 1200
Can i get a query which will group in the above manner???
Thanks & Regards
vihangSQL> select '07'||extract(year from add_months(month,-7))||
2 '-07'||extract(year from add_months(month,5)) yr,
3 sum(amount) amt
4 from test
5 group by '07'||extract(year from add_months(month,-7))||
6 '-07'||extract(year from add_months(month,5));
YR AMT
072007-072008 1100
072006-072007 1200
072005-072006 500.
Message was edited by:
jeneesh -
Hi,
I need some help in performing tuning of a big query. Explain plan is as under:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
Edited by: AbdulHadi on Sep 16, 2011 3:56 PM
Edited by: AHadi on Sep 19, 2011 10:02 AM3 SORT GROUP BY 47916 25M 491G 15M (3) 17:30:31
4 VIEW 870M 445G 15M (2) 17:24:08
5 HASH GROUP BY 870M 427G 885G 15M (2) 17:24:08
In above steps its using very high temporary tablespace usage. please try to tune your query.
- dynamic sampling used for this statement
The statistics appears to be stale. -
Help needed with Update statements.
Hello All,
I am trying to learn Berkeley XMLDB and facing problem to query the inserted XML file. I have a small XML file with the following contents:
<?xml version="1.0" standalone="yes"?>
<Bookstore>
<Book>
<book_ID>1</book_ID>
<title>Harry Potter and the Order of the Phoenix</title>
<subtitle>A Photographic History</subtitle>
<author>
<author_fname>J.K.</author_fname>
<author_lname>Rowling</author_lname>
</author>
<price>9.99</price>
<year_published>2004</year_published>
<publisher>Scholastic, Inc.</publisher>
<genre>Fiction</genre>
<quantity_in_stock>28997</quantity_in_stock>
<popularity>20564</popularity>
</Book>
</Bookstore>
When I try to update the TITLE of this node I have the following error message:
C:\Users\Chandra\Desktop\BDB>javac -classpath .;"C:\Program Files\Sleepycat Soft
ware\Berkeley DB XML 2.1.8\jar\dbxml.jar";"C:\Program Files\Sleepycat Software\B
erkeley DB XML 2.1.8\jar\db.jar" bdb.java
bdb.java:75: illegal start of expression
public static final String STATEMENT1 = "replace value of node collection("twopp
ro.bdbxml")/Bookstore/Book/bookid/title with 'NEWBOOK'";
^
bdb.java:80: ')' expected
System.out.println("Done query: " + STATEMENT1);
^
2 errors
But when I remove the update statements and just try to display the TITLE of this node, I dont see any outputs. Please help me to catch up with my mistakes. Below is source code I am using to run this functionality.
Thanks.
import java.io.File;
import java.io.FileNotFoundException;
import com.sleepycat.db.DatabaseException;
import com.sleepycat.db.Environment;
import com.sleepycat.db.EnvironmentConfig;
import com.sleepycat.dbxml.XmlContainer;
import com.sleepycat.dbxml.XmlException;
import com.sleepycat.dbxml.XmlInputStream;
import com.sleepycat.dbxml.XmlManager;
import com.sleepycat.dbxml.XmlUpdateContext;
import com.sleepycat.dbxml.XmlDocument;
import com.sleepycat.dbxml.XmlQueryContext;
import com.sleepycat.dbxml.XmlQueryExpression;
import com.sleepycat.dbxml.XmlResults;
import com.sleepycat.dbxml.XmlValue;
public class bdb{
public static void main(String[] args)
Environment myEnv = null;
File envHome = new File("D:/xmldata");
try {
EnvironmentConfig envConf = new EnvironmentConfig();
envConf.setAllowCreate(true); // If the environment does not
// exits, create it.
envConf.setInitializeCache(true); // Turn on the shared memory
// region.
envConf.setInitializeLocking(true); // Turn on the locking subsystem.
envConf.setInitializeLogging(true); // Turn on the logging subsystem.
envConf.setTransactional(true); // Turn on the transactional
envConf.setRunRecovery(true);
// subsystem.
myEnv = new Environment(envHome, envConf);
// Do BDB XML work here.
} catch (DatabaseException de) {
// Exception handling goes here
} catch (FileNotFoundException fnfe) {
// Exception handling goes here
} finally {
try {
if (myEnv != null) {
myEnv.close();
} catch (DatabaseException de) {
// Exception handling goes here
XmlManager myManager = null;
XmlContainer myContainer = null;
// The document
String docString = "D:/xmldata/test.xml";
// The document's name.
String docName = "cia";
try {
myManager = new XmlManager(); // Assumes the container currently exists.
myContainer =
myManager.createContainer("twoppro.bdbxml");
myManager.setDefaultContainerType(XmlContainer.NodeContainer); // Need an update context for the put.
XmlUpdateContext theContext = myManager.createUpdateContext(); // Get the input stream.
XmlInputStream theStream =
myManager.createLocalFileInputStream(docString); // Do the actual put
myContainer.putDocument(docName, // The document's name
theStream, // The actual document.
theContext, // The update context
// (required).
null); // XmlDocumentConfig object
theStream.delete();
// Update the title
public static final String STATEMENT1 = "*replace value of node collection("twoppro.bdbxml")/Bookstore/Book/[bookid=1]/title with 'NEWBOOK'";*
XmlQueryContext context = myManager.createQueryContext();
XmlQueryExpression queryExpression1 = myManager.prepare(STATEMENT1, context);
System.out.println("Try to execute query: " +
System.out.println("Done query: " + STATEMENT1);
queryExpression1.execute(context);
// Get a query context
XmlQueryContext context = myManager.createQueryContext();
// Set the evaluation type to Lazy.
context.setEvaluationType(XmlQueryContext.Lazy);
// Declare the query string
String queryString =
"for $u in collection('twoppro.dbxml')/Bookstore/Book/[bookid=1]"
+ "*return $u/title";*
// Prepare (compile) the query
XmlQueryExpression qe = myManager.prepare(queryString, context);
XmlResults results = qe.execute(context);
System.out.println("ok");
System.out.println(results);
} catch (XmlException e) {
// Error handling goes here. You may want to check
// for XmlException.UNIQUE_ERROR, which is raised
// if a document with that name already exists in
// the container. If this exception is thrown,
// try the put again with a different name, or
// use XmlModify to update the document.
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
if (myContainer != null) {
myContainer.close();
if (myManager != null) {
myManager.close();
} catch (XmlException ce) {
// Exception handling goes hereThanks Rucong. The change you suggested did helped me to run the program correct. But I also have the display function to retrive the results and my program is parsed without any output.
C:\Users\C\Desktop\BDB>Clientbuild.bat
C:\Users\C\Desktop\BDB>javac -classpath .;"C:\Program Files\Sleepycat Soft
ware\Berkeley DB XML 2.1.8\jar\dbxml.jar";"C:\Program Files\Sleepycat Software\B
erkeley DB XML 2.1.8\jar\db.jar" bdb.java
C:\Users\C\Desktop\BDB>Client.bat
C:\Users\C\Desktop\BDB>java -classpath .;"C:\Program Files\Sleepycat Softw
are\Berkeley DB XML 2.1.8\jar\dbxml.jar";"C:\Program Files\Sleepycat Software\Be
rkeley DB XML 2.1.8\jar\db.jar" bdb
See there is no OUPUT displayed. Is there somethinglike a 'print' I have to use in this java code.
Any ideas ? Below is the code I am using now
import java.io.File;
import java.io.FileNotFoundException;
import com.sleepycat.db.DatabaseException;
import com.sleepycat.db.Environment;
import com.sleepycat.db.EnvironmentConfig;
import com.sleepycat.dbxml.XmlContainer;
import com.sleepycat.dbxml.XmlException;
import com.sleepycat.dbxml.XmlInputStream;
import com.sleepycat.dbxml.XmlManager;
import com.sleepycat.dbxml.XmlUpdateContext;
import com.sleepycat.dbxml.XmlDocument;
import com.sleepycat.dbxml.XmlQueryContext;
import com.sleepycat.dbxml.XmlQueryExpression;
import com.sleepycat.dbxml.XmlResults;
import com.sleepycat.dbxml.XmlValue;
public class bdb{
public static void main(String[] args)
Environment myEnv = null;
File envHome = new File("D:/xmldata");
try {
EnvironmentConfig envConf = new EnvironmentConfig();
envConf.setAllowCreate(true); // If the environment does not
// exits, create it.
envConf.setInitializeCache(true); // Turn on the shared memory
// region.
envConf.setInitializeLocking(true); // Turn on the locking subsystem.
envConf.setInitializeLogging(true); // Turn on the logging subsystem.
envConf.setTransactional(true); // Turn on the transactional
envConf.setRunRecovery(true);
// subsystem.
myEnv = new Environment(envHome, envConf);
// Do BDB XML work here.
} catch (DatabaseException de) {
// Exception handling goes here
} catch (FileNotFoundException fnfe) {
// Exception handling goes here
} finally {
try {
if (myEnv != null) {
myEnv.close();
} catch (DatabaseException de) {
// Exception handling goes here
XmlManager myManager = null;
XmlContainer myContainer = null;
// The document
String docString = "D:/xmldata/test.xml";
// The document's name.
String docName = "cia";
try {
myManager = new XmlManager(); // Assumes the container currently exists.
myContainer =
myManager.createContainer("twoppro.bdbxml");
myManager.setDefaultContainerType(XmlContainer.NodeContainer); // Need an update context for the put.
XmlUpdateContext theContext = myManager.createUpdateContext(); // Get the input stream.
XmlInputStream theStream =
myManager.createLocalFileInputStream(docString); // Do the actual put
myContainer.putDocument(docName, // The document's name
theStream, // The actual document.
theContext, // The update context
// (required).
null); // XmlDocumentConfig object
theStream.delete();
// Update the title
String STATEMENT1 = "for $n in collection('twoppro.bdbxml')/Bookstore/Book[book_ID=1]/title return replace value of node $n with 'NEWBOOK'";
XmlQueryContext context = myManager.createQueryContext();
XmlQueryExpression queryExpression1 = myManager.prepare(STATEMENT1, context);
System.out.println("Done query: " + STATEMENT1);
queryExpression1.execute(context);
// Get a query context
XmlQueryContext thiscontext = myManager.createQueryContext();
// Set the evaluation type to Lazy.
context.setEvaluationType(XmlQueryContext.Lazy);
// Declare the query string
String queryString =
"for $u in collection('twoppro.dbxml')/Bookstore/Book/[bookid=1]"
+ "return $u/title";
// Prepare (compile) the query
XmlQueryExpression qe = myManager.prepare(queryString, thiscontext);
XmlResults results = qe.execute(thiscontext);
System.out.println("ok");
System.out.println(results);
} catch (XmlException e) {
// Error handling goes here. You may want to check
// for XmlException.UNIQUE_ERROR, which is raised
// if a document with that name already exists in
// the container. If this exception is thrown,
// try the put again with a different name, or
// use XmlModify to update the document.
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
if (myContainer != null) {
myContainer.close();
if (myManager != null) {
myManager.close();
} catch (XmlException ce) {
// Exception handling goes here
Thanks. -
Help needed with if statement in a method
Hi I�ve created 2 string arrays. One holds a one digit user id no. and the other holds a 4 digit pin number. I�ve then written a method which should take the userId no that has been sent to the method in the UserCode parameter find the same number in the custid array if it does it should then check the same position of the pin array and check that the pin number matches the pin no. the method has received in PINCode parameter.
At the moment my method receives the parameters checks the userId no. but doesn�t move on and check the PIN array.
Any help would be great as I�ve been staring at this for days now and I can�t see the wood from the trees!
public boolean checkPinAndUserId(String pinCode, String userCode)
boolean found = false;
for (int i = 0; i < userId.length; i++)
if (userCode.equals(userId))
if (pinCode.equals(pin[i]))
found = true;
return found;I've posted my code in full so hopefully everyone can see exactly what I have been doing.
Note - my code uses the observer/observable model. The method I am having the problem with the if statement is in the class HSBC as are the string arrays. in the class ATM in the action performed PINInput button events section, when the pin count reaches 4 it sends the parameters over to the HSBC checkpin&userid method.
I've used the System.out.println() statements to see what's going on and it receives the parameters checkes the userid array but does not move on to check that the pin parameter matches the pin array?
Any help would be great - Hope this helps.
* @(#)BankAssignment.java 1.0 03/04/06
* This apllication l
package myprojects.bankassignment;
import java.awt.*; // import the component library
import java.awt.event.*; // import the evnet library
import javax.swing.*;
import java.util.*;
class Correct1v16 extends Frame // make a new application
public Correct1v16() // this is the constructor method
HSBC HSBCobj = new HSBC();
public static void main(String args[]) // this invokes the constructor of the class and creates a runable object 'mainframe'
Correct1v16 mainFrame = new Correct1v16(); // the constructor call of the class which creates an object of that class
class HSBC implements Observer, ActionListener
Frame f5;
JLabel refill, launch;
TextField tRefill, tLaunch;
JButton refillbut, launchbut;
int count;
String [] userId=new String [10];
String [] pin=new String [10];
public boolean authenticate = false;
int i;
public HSBC()
drawFrame();
Atm Atmobj = new Atm(this);
System.out.println("Starting HSBC constructor");
public void drawFrame()
System.out.println("Start HSBC drawframe method...");
f5=new Frame("HSBC");
f5.setLayout(new FlowLayout());
f5.setSize(200, 200);
f5.addWindowListener(new WindowAdapter()
public void windowClosing(WindowEvent e)
f5.dispose();
System.exit(0);
refill=new JLabel("Refill ATM");
launch=new JLabel("Launch new ATM");
tRefill=new TextField(20);
tLaunch=new TextField(10);
refillbut=new JButton("Refill ATM");
refillbut.addActionListener(this);
launchbut=new JButton("Launch new ATM");
launchbut.addActionListener(this);
f5.add(refill);
f5.add(tRefill);
f5.add(refillbut);
f5.add(launch);
f5.add(tLaunch);
f5.add(launchbut);
f5.setVisible(true);
//*********** POPULATE THE ARRAYS */
pin[0]="1234";
pin[1]="2345";
pin[2]="3456";
pin[3]="4567";
pin[4]="5678";
pin[5]="6789";
pin[6]="7890";
pin[7]="8901";
pin[8]="9012";
pin[9]="0123";
userId[0]="0";
userId[1]="1";
userId[2]="2";
userId[3]="3";
userId[4]="4";
userId[5]="5";
userId[6]="6";
userId[7]="7";
userId[8]="8";
userId[9]="9";
}// end drawframe method
// public Atm atmLink = (Atm)o;
public void update(Observable gm1, Object o)
Atm atmLink = (Atm)o;
tRefill.setText("Refill ATM ?");
atmLink.refill();
}//end update method
public void actionPerformed(ActionEvent ae)
if(ae.getSource() == refillbut)
// Atm Atmobj.refill();
// tRefill.setText("text area");
// atmLink.refill();
// Atmobj.refill();
// setChanged();
// notifyObservers();
if(ae.getSource() == launchbut)
tLaunch.setText("new ATM opened");
Atm Atmobj1 = new Atm(this);
//******** THIS METHOD RECEIVES THE PARAMETERS FROM THE ATM METHOD (LINE 580) (PINCODE AND USERCODE) BUT
//******** IT ONLY THE ARRAY CALLED USERID (WHICH HOLDS THE USER CODE MATCHES ONE OF THE USERID'S)
//******** I DO WANT IT TO DO THIS BUT I ALSO WANT IT TO MOVE ON AND CHECK THE PINCODE WITH THE PIN ARRAY)
//******** IF THEY ARE BOTH TRUE I WANT IT TO RETURN TRUE - ELSE FALSE. */
public boolean checkPinAndUserId(String pinCode, String userCode)
boolean found = false;
System.out.println("in checkpin method");
for (int i = 0; i < userId.length; i++)
System.out.println("in the userid array" + userId);
if (userCode.equals(userId[i]))
System.out.println("checking user code array");
if (pinCode.equals(pin[i]))
System.out.println("checking the pin array" + pinCode);
System.out.println("pin[i] = "+pin[i]);
found = true;
return found;
}// end HSBC class
class Atm extends Observable implements ActionListener
Frame f1;
TextField t3, t5;
JTextArea display = new JTextArea("Welcome to HSBC Bank. \n Please enter your User Identification number \n", 5, 40);
JPanel p1, p2, p3,p4;
private JButton but1, but2, but3, but4,but5,but6,but7,but8,but9,but0,enter,
cancel,fivepounds,tenpounds,twentypounds,fiftypounds,clearbut, refillbut;
int state = 1;
public String pinCode ="";
public String userCode ="";
int userCodeCount = 0;
int PINCount = 0;
String withdrawAmount = "";
int atmBalance =200;
private HSBC HSBCobj;
//ATM constructor that receives the HSBCobj g1 reference to where the HSBC class
// in in the program
// Calls the drawATMFrame method
// add the observer to the HSBCobj reference so that the ATM can tell HSBC that
// something has changed
public Atm(HSBC g1)
HSBCobj = g1;
drawATMFrame();
System.out.println("Starting Atm constructor");
addObserver(HSBCobj);
// this is the method that draws the ATM interface
// also apply the Border Layout to the frame
public void drawATMFrame()
f1=new Frame("ATM");
f1.setLayout(new BorderLayout());
f1.setSize(350, 250);
f1.addWindowListener(new WindowAdapter()
public void windowClosing(WindowEvent e)
f1.dispose();
System.exit(0);
// declare & instantiate all the buttons that will be used on the ATM
but1 =new JButton("1");
but1.addActionListener(this);
but2 =new JButton("2");
but2.addActionListener(this);
but3 =new JButton("3");
but3.addActionListener(this);
but4 =new JButton("4");
but4.addActionListener(this);
but5 =new JButton("5");
but5.addActionListener(this);
but6 =new JButton("6");
but6.addActionListener(this);
but7 =new JButton("7");
but7.addActionListener(this);
but8 =new JButton("8");
but8.addActionListener(this);
but9 =new JButton("9");
but9.addActionListener(this);
but0 =new JButton("0");
but0.addActionListener(this);
enter=new JButton("Enter");
enter.addActionListener(this);
cancel=new JButton("Cancel/ \n Restart");
cancel.addActionListener(this);
fivepounds =new JButton("?5");
fivepounds.addActionListener(this);
tenpounds = new JButton("?10");
tenpounds.addActionListener(this);
twentypounds = new JButton("?20");
twentypounds.addActionListener(this);
fiftypounds = new JButton("?50");
fiftypounds.addActionListener(this);
clearbut = new JButton("Clear");
clearbut.addActionListener(this);
refillbut = new JButton("Refill");
refillbut.addActionListener(this);
//declare & instantiate a textfield
t3=new TextField(5);
// instantiate 4 JPanels
p1=new JPanel();
p2=new JPanel();
p3=new JPanel();
p4=new JPanel();
// add some buttons to p1
p1.add(but1);
p1.add(but2);
p1.add(but3);
p1.add(but4);
p1.add(but5);
p1.add(but6);
p1.add(but7);
p1.add(but8);
p1.add(but9);
p1.add(but0);
//add the text area field to p2
p2.add(display);
// apply the grid layout to p3
GridLayout layout3 = new GridLayout(4,1,5,5);
p3.setLayout(layout3);
p3.add(fivepounds);
p3.add(tenpounds);
p3.add(twentypounds);
p3.add(fiftypounds);
// apply grid layout to p4
GridLayout layout4 = new GridLayout(4,1,5, 5);
p4.setLayout(layout4);
p4.add(clearbut);
p4.add(enter);
p4.add(cancel);
p4.add(refillbut);
//add the panels to the different parts of the screen
f1.add("North", display);
f1.add("Center", p1);
f1.add("East", p4);
f1.add("West", p3);
f1.setVisible(true);
}// end drawATMframe method
public void actionPerformed(ActionEvent ae)
if(state == 1)
getUserIdNo(ae);
else if(state == 2)
doPINInput(ae);
else
withdrawCash(ae);
}// end action performed method
//******** STATE 1 events
//******** USER ID INPUT
public void getUserIdNo (ActionEvent ae)
if (ae.getSource() == but1)
display.append("*");
userCode = userCode + "1";
userCodeCount++;
if (ae.getSource() == but2)
display.append("*");
userCode = userCode + "2";
userCodeCount++;
if (ae.getSource() == but3)
display.append("*");
userCode = userCode + "3";
userCodeCount++;
System.out.println("user id ="+userCode);
if (ae.getSource() == but4)
display.append("*");
userCode = userCode = "4";
userCodeCount++;
System.out.println("user id ="+userCode);
if (ae.getSource() == but5)
display.append("*");
userCode = userCode + "5";
userCodeCount++;
System.out.println("user id ="+userCode);
if (ae.getSource() == but6)
display.append("*");
userCode = userCode + "6";
userCodeCount++;
System.out.println("user id ="+userCode);
if (ae.getSource() == but7)
display.append("*");
userCode = userCode + "7";
userCodeCount++;
System.out.println("user id ="+userCode);
if (ae.getSource() == but8)
display.append("*");
userCode = userCode + "8";
userCodeCount++;
System.out.println("user id ="+userCode);
if (ae.getSource() == but9)
display.append("*");
userCode = userCode + "9";
userCodeCount++;
System.out.println("user id ="+userCode);
if (ae.getSource() == but0)
display.append("*");
userCode = userCode + "0";
userCodeCount++;
System.out.println("user id ="+userCode);
if (ae.getSource() == cancel)
display.setText("Welcome to HSBC Bank.\n Please enter your User Identification number \n");
userCode = "";
state = 2;
if (ae.getSource() == clearbut)
display.setText("Please enter your user ID number again\n");
userCode = "";
userCodeCount = 0;
if (ae.getSource() == refillbut)
refill();
if (ae.getSource() == enter)
display.setText("Please enter your PIN \n");
state = 2;
System.out.println(" User id enter button = " + userCode);
if (userCodeCount == 1)
display.setText("Please enter your PIN \n");
userCode = "";
userCodeCount = 0;
state = 2;
//******** STATE 2
//******** PIN INPUT
public void doPINInput(ActionEvent ae)
if (ae.getSource() == but1)
{ pinCode = pinCode.concat("1");
display.append("*");
PINCount++;
if (ae.getSource() == but2)
{ pinCode = pinCode.concat("2");
display.append("*");
PINCount++;
if (ae.getSource() == but3)
{ pinCode = pinCode.concat("3");
display.append("*");
PINCount++;
if (ae.getSource() == but4)
{ pinCode = pinCode.concat("4");
display.append("*");
PINCount++;
if (ae.getSource() == but5)
{ pinCode = pinCode.concat("5");
display.append("*");
PINCount++;
if (ae.getSource() == but6)
{ pinCode = pinCode.concat("6");
display.append("*");
PINCount++;
if (ae.getSource() == but7)
{ pinCode = pinCode.concat("7");
display.append("*");
PINCount++;
if (ae.getSource() == but8)
{ pinCode = pinCode.concat("8");
display.append("*");
PINCount++;
if (ae.getSource() == but9)
{ pinCode = pinCode.concat("9");
display.append("*");
PINCount++;
if (ae.getSource() == but0)
{ pinCode = pinCode.concat("0");
display.append("*");
PINCount++;
if (ae.getSource() == clearbut)
display.setText("Please enter your PIN number again \n");
pinCode = "";
PINCount = 0;
if (ae.getSource() == cancel)
display.setText("Welcome to HSBC Bank.\n Please enter your User Identification number \n");
state = 1;
pinCode ="";
PINCount = 0;
if (ae.getSource() == refillbut)
refill();
/// ************************ THIS BUTTON SENDS THE PIN & USER CODE OVER TO THE MAIN BANK
/// ************************ (LINE 152)
if (ae.getSource() == enter)
// if(HSBCobj.checkPinAndUserId(pinCode, userCode))
// display.setText("How much would you like to withdraw \n");
// else
// display.setText("Your UserId and Pin code do not match");
if(PINCount ==4)
if(HSBCobj.checkPinAndUserId(userCode,pinCode))
display.setText("Enter the amount you \n want to withdraw \n ?");
PINCount=0;
else
display.setText("Your User Identification Number \n and PIN number do not match! \n please try again\n");
//*********** STATE 3 events
//*********** withdrawCash
public void withdrawCash(ActionEvent ae)
// if (ae.getSource() == but1)
// display.append("1");
/// withdrawAmount = withdrawAmount+1;
// pinCode = pinCode.concat("2");
// System.out.println("Withdrawal Amount = "+withdrawAmount);
if(ae.getSource( ) == but1)
withdrawAmount = withdrawAmount + "1";
display.setText(withdrawAmount);
if(ae.getSource( ) == but2)
withdrawAmount = withdrawAmount + "2";
display.setText(withdrawAmount);
if(ae.getSource( ) == but3)
withdrawAmount = withdrawAmount + "3";
display.setText(withdrawAmount);
if(ae.getSource( ) == but4)
withdrawAmount = withdrawAmount + "4";
display.setText(withdrawAmount);
if(ae.getSource( ) == but5)
withdrawAmount = withdrawAmount + "5";
display.setText(withdrawAmount);
if(ae.getSource( ) == but6)
withdrawAmount = withdrawAmount + "6";
display.setText(withdrawAmount);
if(ae.getSource( ) == but7)
withdrawAmount = withdrawAmount + "7";
display.setText(withdrawAmount);
if(ae.getSource( ) == but8)
withdrawAmount = withdrawAmount + "8";
display.setText(withdrawAmount);
if(ae.getSource( ) == but9)
withdrawAmount = withdrawAmount + "9";
display.setText(withdrawAmount);
if(ae.getSource( ) == but0)
withdrawAmount = withdrawAmount + "0";
display.setText(withdrawAmount);
if (ae.getSource() == fivepounds)
withdrawAmount = withdrawAmount + "5";
display.setText(withdrawAmount);
atmBalance();
if (ae.getSource() == tenpounds)
withdrawAmount = withdrawAmount + "10";
display.setText(withdrawAmount);
atmBalance();
if (ae.getSource() == twentypounds)
withdrawAmount = withdrawAmount + "20";
display.setText(withdrawAmount);
atmBalance();
if (ae.getSource() == fiftypounds)
withdrawAmount = withdrawAmount + "50";
display.setText(withdrawAmount);
atmBalance();
// if (ae.getSource() == tenpounds)
// display.append("10");
// withdrawAmount = 10;
// pinCode = pinCode.concat("2");
// System.out.println("10 pound button pressed");
// atmBalance();
if (ae.getSource() == enter)
atmBalance();
if (ae.getSource() == refillbut)
System.out.println("refill but pressed");
refill();
if (ae.getSource() == clearbut)
System.out.println("clear but pressed");
display.setText("Enter the amount you want to withdraw \n ?");
withdrawAmount="";
if (ae.getSource() == cancel)
display.setText("Welcome to HSBC Bank.\n Please enter your User Identification number \n");
withdrawAmount="";
pinCode ="";
PINCount = 0;
userCode = "";
userCodeCount = 0;
state = 1;
}// end withdraw cash input method
// checks balace of atm and withdraws cash. Also notifies onserver if atm balance is low
public void atmBalance()
String s = withdrawAmount;
int n = Integer.parseInt(s);
if ( atmBalance >= n)
atmBalance = atmBalance - n;
System.out.println("atm balance = "+ atmBalance);
display.setText("Thankyou for using HSBC. \nYou have withdrawn ?"+n);
if (atmBalance<40)
System.out.println("atm balance is less than 40 - notify HSBC" );
setChanged();
notifyObservers(this);
/// note the refil should send a message to the controller
// advising a refil is needed. The Bank will send an engineer
// out who will fill the atm up
}// end atmBalance method
/// note the refil should send a message to the controller
/// then th coontroller will send a message to this method to fill machine
/// (this is simulating a clerk filling atm)
public void refill()
System.out.println("in refill method" );
atmBalance = 200;
System.out.println("Atm has been refilled. Atm balance = " + atmBalance);
// setChanged();
// notifyObservers(this);
}// end refill method
// NOTE SURE ABOUT THIS - DO I USE THE UPDATE METHOD TO NOTIFY HSBC THAT ATM REQUIRES FILLING
// THIS IS THE WRONG PART OF THE PROGRAM (SHOULD BE IN HSBC) - IGNORE
public void update(Observable gm1, Object gameObj)
display.setText("Congratulations");
}//end update method
}// end Atm method
}// end Assignment2 class -
Help needed in getting a query
Hi,
I have two tables issues and comments. Issues is parent table and comments is a child table with issue_id as the foreign key. There are two columns in master table Creation_date and closed_date . As the name suggests they refer to issue creation and closing date. I have say 4 statuses in comments table. Say 'open',moreInfo','Closed','Reopen'. There is also update_time column for the comments_table. So whenver the status is updated date and time is captured. Also when a issue is closed the update_time is entered into closing_date of the issues table as well. Also when the issue is reopened that closing date of the issue will be set to null. I wanted a query to calculate the average time required in closing the issue which I got that from the issues table by doing '-' of closingdate and creation_date.
But now I want to calculate the average time spent on the issues without taking the time spent on the status moreinfo into consideration. Also the status can change at any point of time. THere is no sequence in status change.
I want a SQL query for the above scenario.
ThanksHi,
868875 wrote:
Hi,
I have two tables issues and comments. Issues is parent table and comments is a child table with issue_id as the foreign key. There are two columns in master tableIs "master table" the same as issues?
Creation_date and closed_date . As the name suggests they refer to issue creation and closing date. I have say 4 statuses in comments table. Say 'open',moreInfo','Closed','Reopen'. There is also update_time column for the comments_table. So whenver the status is updated date and time is captured. Also when a issue is closed the update_time is entered into closing_date of the issues table as well. Also when the issue is reopened that closing date of the issue will be set to null. I wanted a query to calculate the average time required in closing the issue which I got that from the issues table by doing '-' of closingdate and creation_date.
But now I want to calculate the average time spent on the issues without taking the time spent on the status moreinfo into consideration. Also the status can change at any point of time. THere is no sequence in status change.
I want a SQL query for the above scenario.Maybe you just need to add
comments.status != 'moreinfo' to your WHERE clause. Without more specific information about your daya and your requirements, I can't be sure.
As mentioned before, post your query.
Whenever you have a problem, please post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) from all tables involved.
Also post the results you want from that data, and an explanation of how you get those results from that data, with specific examples.
Always say which version of Oracle you're using. -
Help needed in MERGE statement
Hi,
I am new to PL/SQL, I want to update a table called "final_test" based on the below query result.
1. I want to check whether that particular record is present or not in my "final_test" table.
2. If its present in the "final_test" table and the process_status got changed then I want to update that alone in my "final_test" table.
3. If its not present then I want to insert that record into my "final_test" table.
Basically I am retrieving the report and its status for a particular date.
select
b.id,
a.name,
a.t_name,
c.process_status,
c.time_process
from rep_tab_map a, j_tab_map b, proc_status c
where a.t_name=b.t_name
and b.id=c.id (+)
and trunc(c.date_start)=trunc(sysdate -1)
group by a.name,b.id,c.process_status,c.time_process,a.t_name
order by 2
I thought of using Merge statement but i am not sure what i have to use in ":USING" and "ON" clause.
Please help me with MERGE or with someother way.
ThanksAssuming final_test has same structure as select list in your query:
merge
into final_test a
using (
select b.id,
a.name,
a.t_name,
c.process_status,
c.time_process
from rep_tab_map a,
j_tab_map b,
proc_status c
where a.t_name=b.t_name
and b.id=c.id(+)
and trunc(c.date_start)=trunc(sysdate -1)
group by a.name,b.id,c.process_status,c.time_process,a.t_name
) b
on (b.id = a.id)
when matched then update set a.name = case a.process_status
when b.process_status then a.name
else b.name
end,
a.t_name = case a.process_status
when b.process_status then a.t_name
else b.t_name
end,
a.process_status = b.process_status,
a.time_process = case a.process_status
when b.process_status then a.time_process
else b.time_process
end
when not matched then insert(
a.id,
a.name,
a.t_name,
a.process_status,
a.time_process
values(
b.id,
b.name,
b.t_name,
b.process_status,
b.time_process
/SY. -
Help needed in tuning this query
This is the SQL i would like to tune for performace...
The table structure is given below.
The table has about 2 million rows.
From the second day onwards only around 10% of records will be between Load_Start_Time and Load_End_Time. Among these around 50% will have THAMES_URN_WITH_ROLE_SUFFIX as 'TP%'. At present there are unique and primary key indexes on THAMES_URN_WITH_ROLE_SUFFIX .
I'm sure that we need a b-tree index on STG_UPDATE_DATE_TIME as it is the column with good selectivity.
I'm primarily concerned about the substr, instr and reverese on THAMES_URN_WITH_ROLE_SUFFIX.
Also pls. let me know if the order of predicates is right.
Thanks in advance.
SELECT TPD_STG_TL_SF_LEGAL_OWNER.THAMES_URN, TPD_STG_TL_SF_LEGAL_OWNER.UPDATE_SOURCE, TPD_STG_TL_SF_LEGAL_OWNER.SOURCE_EXTRACT_DATE_TIME, TPD_STG_TL_SF_LEGAL_OWNER.LEGAL_OWNERSHIP_ISSUE_IND, TPD_STG_TL_SF_LEGAL_OWNER.CONTACTABLE_INDICATOR, TPD_STG_TL_SF_LEGAL_OWNER.ADMIN_CONTROL_INDICATOR, TPD_STG_TL_SF_LEGAL_OWNER.BANKRUPTCY_INDICATOR, TPD_STG_TL_SF_LEGAL_OWNER.ASSIGNED_INDICATOR, TPD_STG_TL_SF_LEGAL_OWNER.IN_TRUST_INDICATOR, TPD_STG_TL_SF_LEGAL_OWNER.DIVORCE_CASE_INDICATOR, TPD_STG_TL_SF_LEGAL_OWNER.POA_COP_INDICATOR, TPD_STG_TL_SF_LEGAL_OWNER.CLEANSING_STATUS, TPD_STG_TL_SF_LEGAL_OWNER.CATEGORY
FROM
TPD_STG_TL_SF_LEGAL_OWNER
WHERE
((TPD_STG_TL_SF_LEGAL_OWNER.STG_UPDATE_DATE_TIME > '$$Load_Start_Time'
AND
TPD_STG_TL_SF_LEGAL_OWNER.STG_UPDATE_DATE_TIME <= '$$Load_End_Time')
OR
(TPD_STG_TL_SF_LEGAL_OWNER.TPDB_PROCESSED_IDENTIFIER != 'Y') )
AND
SUBSTR(TPD_STG_TL_SF_LEGAL_OWNER.THAMES_URN_WITH_ROLE_SUFFIX,1,2)='TP'
AND
SUBSTR(REVERSE( TPD_STG_TL_SF_LEGAL_OWNER.THAMES_URN_WITH_ROLE_SUFFIX),INSTR(REVERSE( TPD_STG_TL_SF_LEGAL_OWNER.THAMES_URN_WITH_ROLE_SUFFIX),'-',1)-1,1)!='S'
========================================
CREATE TABLE TPD_STG_TL_SF_LEGAL_OWNER
THAMES_URN VARCHAR2(35 BYTE) NOT NULL,
UPDATE_SOURCE VARCHAR2(3 BYTE),
SOURCE_EXTRACT_DATE_TIME DATE,
LEGAL_OWNERSHIP_ISSUE_IND CHAR(1 BYTE),
CONTACTABLE_INDICATOR CHAR(1 BYTE),
ADMIN_CONTROL_INDICATOR CHAR(1 BYTE),
BANKRUPTCY_INDICATOR CHAR(1 BYTE),
ASSIGNED_INDICATOR CHAR(1 BYTE),
IN_TRUST_INDICATOR CHAR(1 BYTE),
DIVORCE_CASE_INDICATOR CHAR(1 BYTE),
POA_COP_INDICATOR CHAR(1 BYTE),
THAMES_URN_WITH_ROLE_SUFFIX VARCHAR2(39 BYTE),
THAMES_LEGAL_OWNERSHIP_IND CHAR(1 BYTE),
PRODUCT_HOLDING_ROLE_TYPE VARCHAR2(21 BYTE),
OWNERSHIP_SPLIT_PERCENTAGE NUMBER(3),
SOURCE_SYSTEM VARCHAR2(3 BYTE),
TITLE VARCHAR2(50 BYTE),
FIRST_NAME VARCHAR2(50 BYTE),
MIDDLE_INITIAL VARCHAR2(50 BYTE),
SURNAME VARCHAR2(50 BYTE),
GENDER CHAR(1 BYTE),
BIRTH_DATE DATE,
DEATH_INDICATOR CHAR(1 BYTE),
DEATH_RECORD_DATE DATE,
NATIONAL_INSURANCE_NUMBER VARCHAR2(9 BYTE),
GONE_AWAY_INDICATOR CHAR(1 BYTE),
ADDRESS_LINE_1 VARCHAR2(50 BYTE),
ADDRESS_LINE_2 VARCHAR2(50 BYTE),
ADDRESS_LINE_3 VARCHAR2(50 BYTE),
ADDRESS_LINE_4 VARCHAR2(50 BYTE),
ADDRESS_LINE_5 VARCHAR2(50 BYTE),
POST_CODE VARCHAR2(12 BYTE),
COUNTRY VARCHAR2(50 BYTE),
OVERSEAS_ADDRESS_INDICATOR CHAR(1 BYTE),
ORGANISATION_NAME VARCHAR2(50 BYTE),
TPDB_PROCESSED_IDENTIFIER CHAR(2 BYTE),
CLEANSING_STATUS VARCHAR2(30 BYTE),
CATEGORY VARCHAR2(50 BYTE),
SCHEME_NAME VARCHAR2(50 BYTE),
STG_CREATE_DATE_TIME DATE,
STG_UPDATE_DATE_TIME DATE,
LAST_UPDATED_DATE_TIME DATE
TABLESPACE TPDBS01A_DATA
PCTUSED 0
PCTFREE 10
INITRANS 1
MAXTRANS 255
STORAGE (
INITIAL 128K
NEXT 128K
MINEXTENTS 1
MAXEXTENTS 2147483645
PCTINCREASE 0
BUFFER_POOL DEFAULT
LOGGING
NOCOMPRESS
NOCACHE
NOPARALLEL
MONITORING;
CREATE UNIQUE INDEX TPD_STG_TL_SF_LEGAL_OWNER_PK ON TPD_STG_TL_SF_LEGAL_OWNER
(THAMES_URN_WITH_ROLE_SUFFIX)
LOGGING
TABLESPACE TPDBS01A_DATA
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 128K
NEXT 128K
MINEXTENTS 1
MAXEXTENTS 2147483645
PCTINCREASE 0
BUFFER_POOL DEFAULT
NOPARALLEL;
ALTER TABLE TPD_STG_TL_SF_LEGAL_OWNER ADD (
CONSTRAINT TPD_STG_TL_SF_LEGAL_OWNER_PK
PRIMARY KEY
(THAMES_URN_WITH_ROLE_SUFFIX)
USING INDEX
TABLESPACE TPDBS01A_DATA
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 128K
NEXT 128K
MINEXTENTS 1
MAXEXTENTS 2147483645
PCTINCREASE 0
));> If indexes don't help, is the only way to gain REAL
performance gain on this type of query is to
partition the table
If a Full Table Scan on a table takes "too long" (and
this is purely subjective - "too long" is different
for every problem) and indexes can't help, and we
need <100% of the rows, and if partitioning will give
us the performance we desire, is it OK do it ? Also
would STG_UPDATE_DATE_TIME be the best column to do a
index partion ?
For this type of query, partitioning on STG_UPDATE_DATE_TIME would be good.
However, partitioning is not done just for one query. It has to fit in your total design. For example, if you are also doing queries with a predicate like <column with a local unique index but not the partition key> = <constant>, it would have to visit all partitions instead of just one, and those queries would take much longer to execute. You can make the index global, but there all kind of maintenance issues with that. In short: be careful about partitioning and think it through first.
> But is it a good option to partition tables with
total no. of rows between 2 million and 5 million ? I
thought partitioning is better done for tables > 20
million.
Please throw some light on that.
Generally, partitioning is done on bigger tables, yes. But it is not about some specific number of rows. You partition a table when all forecasted use of the table is known, so you can make a good judgement which usages will benefit, which ones won't be affected and which ones are likely to suffer. When the benefits outweigh the disadvantages, you partition...
Above I had an example about queries that are going to suffer. Partitioning is beneficial for example when once in some period you'd have to delete A LOT of old rows. Or when you have some data warehousing queries that need like 10% of only the most recent data in a huge table.
The decision is yours.
Regards,
Rob. -
Help needed in mapping BI query output to use as input for BAPI
Hi,
After wrestling with it for quite some time I choose to ask yet another question here. I want to use the output of a BI query I use as input for a BAPI. I just can not get the mapping correctly:
The query delivers: 104908BA092F7501F5E1008000829000AC
I need: 104908BA092F7501F5E1008000829000AC
How can I lose the two first digits? Thanks in advance!
Best regards,
JanNevermind. I found out myself. I am now using the statement MID(@GUID,2,32) in the connection.
-
Help needed in writing a Query/Procedure
Hello All,
Need all ur help in writing a query or procedure
Lets say the Table name is DEMO
There i have one column like num it has values
1
2
3
4
5
8
9
10
my query output should be
1-5
8-10
i,e .. if the diff between two rows is greater than 1 then it result should be in a separate group
I need a query/Procedure for this. Kindly help
Regards,
ChandraTried obtaining the output using SQL and the result is as follows:
SQL> WITH T AS
2 (
3 SELECT 1 COL1 FROM DUAL
4 UNION
5 SELECT 2 COL1 FROM DUAL
6 UNION
7 SELECT 3 COL1 FROM DUAL
8 UNION
9 SELECT 4 COL1 FROM DUAL
10 UNION
11 SELECT 5 COL1 FROM DUAL
12 UNION
13 SELECT 8 COL1 FROM DUAL
14 UNION
15 SELECT 9 COL1 FROM DUAL
16 UNION
17 SELECT 10 COL1 FROM DUAL
18 UNION
19 SELECT 13 COL1 FROM DUAL
20 UNION
21 SELECT 14 COL1 FROM DUAL
22 UNION
23 SELECT 15 COL1 FROM DUAL
24 UNION
25 SELECT 16 COL1 FROM DUAL
26 UNION
27 SELECT 23 COL1 FROM DUAL
28 UNION
29 SELECT 24 COL1 FROM DUAL
30 )
31 SELECT OUTPUT FROM
32 (
33 SELECT DECODE(COL3,NULL,COL1, COL2) || '-' || LEAD(DECODE(COL3,NULL,COL3, COL1)) OVER (ORDER BY DECODE(COL3,NULL,COL1, COL2)) OUTPUT FROM
34 (
35 SELECT COL1, LEAD(COL1) OVER (ORDER BY COL1) COL2, LAG(COL1) OVER (ORDER BY COL1) COL3 FROM T
36 )
37 WHERE
38 (COL2 - COL1 > 1 OR COL2 IS NULL OR COL3 IS NULL)
39 )
40 WHERE OUTPUT != '-';
OUTPUT
1-5
8-10
13-16
23-24
Maybe you are looking for
-
Unable to connect to mail server on iphone
I have been getting an" unable to connect to yahoo mail server" on my iphone since yesterday. I have re-started the phone, deleted my mail account and re-added and nothing seems to work. Any ideas?
-
Merge/concatenate animation codec movie files in the command line/shell
We know how to join 2 mp4/h264 movies together in the command line/shell via MP4Box. We have not been able to find a similar tool for joining to Quicktime Animation codec movie together via command line/shell. Anyone know how to do that of have sugge
-
SRM-MDM Catalog latest version and SRM 6.0
Hi MDM Users, could anybody tell me when will be released SRM-MDM Catalog 2.0? As I know, latest version is 1.0 Patch03. Do you have any information about release of SRM 6.0? Thanks and regards, Álmos Message was edited by: Álmos Paksi
-
PC crashed! How do I get my photos back on it from iPhone?
I used iTunes to sync my photos on my PC to my iPhone. My PC crashed this last week and I had to reinstall the OS. Now when I sync my iPhone it tells me it will erase all the pics on it. I just want to put the pics from the iPhone back to my PC. How
-
Hello, Using Oracle 11g R2. I'm trying to present data in the following format. I've come up with the query below, but I don't think it's right. COL1 COL2 COL3 NVL(COL4,SUM(COL4)) NVL(COL5,SUM(COL5)) NVL(COL4-COL5,SUM(COL4-COL5)) 1 10 10/29/2013 12:0