Please help me abut tis query(UNION)
Hi.
I have two tables,users_log_file and compare_url.
compare_url has id and url columns.
when i run this query , it give back duplicate rows!
SELECT ALL A.EXIST,ROWNUM,U.CLINT_IP, U.CLIENT_USER_NAME, U.LOG_DATE,
U.LOG_TIME, U.PROCESSING_TIME, U.BYTE_SENT, U.BYTE_RECIEVED, U.OBJECT_NAME
FROM USERS_LOG_FILE U ,
(SELECT 1 EXIST from users_log_file where exists (SELECT 'X' FROM COMPARE_URL WHERE OBJECT_NAME LIKE '%'||URL||'%')
UNION
SELECT 2 EXIST FROM users_log_file where exists
(SELECT 'X' FROM COMPARE_URL WHERE OBJECT_NAME LIKE '%'||URL||'%'))A
thanks.
Hi All,
I don't think CASE can be used in PL/SQL as oraras wants this query in a format trigger/conditional formatting of report builder. Instead use
SELECT decode(instr(object_name,'URL'),0,1,2) into v_placeholder from COMPARE_URL
If the column OBJECT_NAME in your sub-query belongs to the table users_log_file then ignore the lines given below and try using NOT EXISTS in the second part of the UNION.
*** Please give the full details of the tables
Oraras,
What are you trying to do with WHERE EXISTS in your query. For example, in your query you have given something like this..
(SELECT 1 EXIST from users_log_file where exists (SELECT 'X' FROM COMPARE_URL WHERE OBJECT_NAME LIKE '%'||URL||'%')
If you are using WHERE EXISTS there has to a relationship between the sub and main query like the one given below where there is a reference to the main query table in the sub-query.
select A.a from A where exists(select B.b from B where A.a = B.b)
Rgds,
TRB
Hi. thanks alot.at the first problem (sequence) you can help me.thanks alot.
in this question: i have two tables and i want compare them , when object_name(url address) from >users_log_file like url from compare_url table i want take 1 (for exam) and when not like i take 2.
i want this query for report builder, i want check the url if this condision give 1 i change text color.
but when i run this query i cann't get uniqe data and it select duplicate data!
thanks alot.
Try using the CASE stmt
example
select (case when object_name like '%'||URL||'%' then 1 else 2) Color_Value
from table
I have two tables,users_log_file and compare_url.
compare_url has id and url columns.
when i run this query , it give back duplicate rows!
SELECT ALL A.EXIST,ROWNUM,U.CLINT_IP, U.CLIENT_USER_NAME, U.LOG_DATE,
U.LOG_TIME, U.PROCESSING_TIME, U.BYTE_SENT, U.BYTE_RECIEVED, U.OBJECT_NAME
FROM USERS_LOG_FILE U ,
(SELECT 1 EXIST from users_log_file where exists (SELECT 'X' FROM COMPARE_URL WHERE OBJECT_NAME LIKE '%'||URL||'%')
UNION
SELECT 2 EXIST FROM users_log_file where exists
(SELECT 'X' FROM COMPARE_URL WHERE OBJECT_NAME LIKE '%'||URL||'%'))A
thanks.
Similar Messages
-
Could you please help me make this query less complicated
could you please help me make this query less complicated
select t1.R_OBJECT_ID
from dm_relation_sp a, ddt_resolution_sp t1
where a.parent_id = '0900000283560456' -----------ID
and a.child_id = t1.R_OBJECT_ID
union all
select t3.R_OBJECT_ID
from ddt_resolution_sp t3
where t3.R_OBJECT_ID in (select t2.child_id
from dm_relation_sp t2
where t2.parent_id in (select a.child_id
from asud_fsk.dm_relation_sp a, asud_fsk.ddt_resolution_sp t1
where a.parent_id = '0900000283560456' -----------ID
and a.child_id = t1.R_OBJECT_ID))
union all
select t4.R_OBJECT_ID
from ddt_resolution_sp t4
where t4.R_OBJECT_ID in(
select t3.child_id from dm_relation_sp t3
where t3.parent_id in (
select t2.child_id
from asud_fsk.dm_relation_sp t2
where t2.parent_id in (select a.child_id
from asud_fsk.dm_relation_sp a, asud_fsk.ddt_resolution_sp t1
where a.parent_id = '0900000283560456' -----------ID
and a.child_id = t1.R_OBJECT_ID))
and t3.relation_name = 'RESOLUTION_RELATION')
union all
select t5.R_OBJECT_ID
from ddt_resolution_sp t5
where t5.R_OBJECT_ID in
(select t4.child_id
from dm_relation_sp t4
where t4.parent_id in(
select t3.child_id from dm_relation_sp t3
where t3.parent_id in (
select t2.child_id
from asud_fsk.dm_relation_sp t2
where t2.parent_id in (select a.child_id
from asud_fsk.dm_relation_sp a, asud_fsk.ddt_resolution_sp t1
where a.parent_id = '0900000283560456' -----------ID
and a.child_id = t1.R_OBJECT_ID))
and t3.relation_name = 'RESOLUTION_RELATION')
and t4.relation_name = 'RESOLUTION_RELATION')
Edited by: user13025450 on 29.04.2010 16:23Hi,
Welcome to the forum! You'll find that there are many qualified people (such as Tubby) willing to help you. Will you do what you can to help them? In order to simplify the query you posted,someone will first have to understand what it does, what the tables that it uses are like, and what tools you have to work with (that is, what version of Oracle, and any other software you are using). To actually test their ideas, people will need versions of your tables.
Many people, if they spent enough time, might be able to figure out roughly what you are doing, make some tables themselves and test a solution. You can help with all of that. I assume you already know what the appliction is, and what this particular query is supposed to do: you don't have to figure out any of that, you just have to say it. You know what all your tables are, what the datatypes of all the columns are, and what kinds of data are in the tables: you don't have to guess at any of that.
Describe what you're doing. Think about it: how do we know that
SELECT NULL
FROM dual;doesn't do what you want?
Post CREATE TABLE and INSERT statements for a little sample data.
Post the results that this query is supposed to produce from those results. (Is it producing the right output now? Then it should be easy to post the correct results.)
Describe, as well as you can, how the present query is doing it.
Format your existing code, so it's easy to see what the different branches of the UNION are, and what the main clauses are in each one.
When posting formatted text (code or results) type these 6 characters
\(all small letters, inside curly brackets) before and after each formatted section, to keep this site from compressing the spaces.
Say what versions of Oracle (e.g. 10.2.0.3.0) and any other relevant software you are using.
I know it's a lot of work, but it really helps. You can do it as well (probably better) than anyone else, and if you're unwilling to do it, why should anyone else be willing? -
Please help to modifiy this query for better performance
Please help to rewrite this query for better performance. This is taking long time to execute.
Table t_t_bil_bil_cycle_change contains 1200000 rows and table t_acctnumberTab countains 200000 rows.
I have created index on ACCOUNT_ID
Query is shown below
update rbabu.t_t_bil_bil_cycle_change a
set account_number =
( select distinct b.account_number
from rbabu.t_acctnumberTab b
where a.account_id = b.account_id
Table structure is shown below
SQL> DESC t_acctnumberTab;
Name Type Nullable Default Comments
ACCOUNT_ID NUMBER(10)
ACCOUNT_NUMBER VARCHAR2(24)
SQL> DESC t_t_bil_bil_cycle_change;
Name Type Nullable Default Comments
ACCOUNT_ID NUMBER(10)
ACCOUNT_NUMBER VARCHAR2(24) YIshan's solution is good. I would avoid updating rows which already have the right value - it's a waste of time.
You should have a UNIQUE or PRIMARY KEY constraint on t_acctnumberTab.account_id
merge rbabu.t_t_bil_bil_cycle_change a
using
( select distinct account_number, account_id
from rbabu.t_acctnumberTab
) t
on ( a.account_id = b.account_id
and decode(a.account_number, b.account_number, 0, 1) = 1
when matched then
update set a.account_number = b.account_number -
Please help me with this query -- i am trying with Dense rank
version 10g
i received a quote for an account. if the same quote is received under different account then i should mark the previous account received as deleted.
please help me .
/* Formatted on 2010/06/28 14:13 (Formatter Plus v4.8.8) */
WITH temp AS
(SELECT '1-11TWQL' quote_id, 'COPS' ACCOUNT, 'Ordered' status,
TO_DATE ('12/23/2009 3:37:54',
'mm/dd/yyyy hh:mi:ss PM'
) captured_date
FROM DUAL
UNION ALL
SELECT '1-11TWQL', 'COPS', 'RFS',
TO_DATE ('12/23/2009 3:37:50', 'mm/dd/yyyy hh:mi:ss PM')
FROM DUAL
UNION ALL
SELECT '1-11TWQL', 'COPS', 'Rejected',
TO_DATE ('12/23/2009 3:37:52', 'mm/dd/yyyy hh:mi:ss PM')
FROM DUAL
UNION ALL
SELECT '1-11TWQL', 'COPS', 'Validated',
TO_DATE ('12/23/2009 3:37:51', 'mm/dd/yyyy hh:mi:ss PM')
FROM DUAL
UNION ALL
SELECT '1-11TWQL', 'D1', 'Ordered',
TO_DATE ('12/23/2009 3:04:24', 'mm/dd/yyyy hh:mi:ss PM')
FROM DUAL
UNION ALL
SELECT '1-11TWQL', 'D1', 'RFS',
TO_DATE ('12/23/2009 3:04:23', 'mm/dd/yyyy hh:mi:ss PM')
FROM DUAL
UNION ALL
SELECT '1-11TWQL', 'D1', 'Rejected',
TO_DATE ('12/23/2009 3:04:22', 'mm/dd/yyyy hh:mi:ss PM')
FROM DUAL
UNION ALL
SELECT '1-11TWQL', 'D1', 'Validated',
TO_DATE ('12/23/2009 3:04:23', 'mm/dd/yyyy hh:mi:ss PM')
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'COPS', 'RFS',
TO_DATE ('3/5/2010 12:04:24', 'mm/dd/yyyy hh:mi:ss PM')
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'COPS', 'RFS',
TO_DATE ('3/16/2010 7:55:50', 'mm/dd/yyyy hh:mi:ss PM')
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'COPS', 'RFS',
TO_DATE ('3/16/2010 7:55:51', 'mm/dd/yyyy hh:mi:ss PM')
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'COPS', 'Rejected',
TO_DATE ('3/5/2010 12:04:24', 'mm/dd/yyyy hh:mi:ss PM')
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'COPS', 'Rejected',
TO_DATE ('3/16/2010 7:55:50', 'mm/dd/yyyy hh:mi:ss PM')
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'COPS', 'Rejected',
TO_DATE ('3/16/2010 7:55:51', 'mm/dd/yyyy hh:mi:ss PM')
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'COPS', 'Validated',
TO_DATE ('12/23/2009 3:37:54', 'mm/dd/yyyy hh:mi:ss PM')
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'COPS', 'Validated',
TO_DATE ('12/23/2009 3:37:54', 'mm/dd/yyyy hh:mi:ss PM')
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'COPS', 'Validated',
TO_DATE ('12/23/2009 3:37:54', 'mm/dd/yyyy hh:mi:ss PM')
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'D1', 'Ordered',
TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'D1', 'Ordered',
TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'D1', 'RFS',
TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'D1', 'RFS',
TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'D1', 'Validated',
TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'D1', 'Validated',
TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
FROM DUAL
UNION ALL
SELECT '1-249A8Z', 'COPS', 'Validated',
TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
FROM DUAL
UNION ALL
SELECT '1-249A8Z', 'COPS', 'Ordered',
TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
FROM DUAL)
SELECT quote_id, ACCOUNT, status, captured_date,
DENSE_RANK () OVER (PARTITION BY quote_id ORDER BY quote_id,
ACCOUNT) rn
-- ,CASE DENSE_RANK () OVER (PARTITION BY quote_id ORDER BY quote_id,
-- ACCOUNT)
-- WHEN 1
-- THEN 'Y'
-- ELSE 'N'
-- END deleted_flag
FROM temp
ORDER BY quote_id, captured_date;output required
WITH temp AS
(SELECT '1-11TWQL' quote_id, 'COPS' ACCOUNT, 'Ordered' status,
TO_DATE ('12/23/2009 3:37:54',
'mm/dd/yyyy hh:mi:ss PM'
) captured_date, 'N' deleted_flag
FROM DUAL
UNION ALL
SELECT '1-11TWQL', 'COPS', 'RFS',
TO_DATE ('12/23/2009 3:37:50', 'mm/dd/yyyy hh:mi:ss PM'), 'N' deleted_flag
FROM DUAL
UNION ALL
SELECT '1-11TWQL', 'COPS', 'Rejected',
TO_DATE ('12/23/2009 3:37:52', 'mm/dd/yyyy hh:mi:ss PM'), 'N' deleted_flag
FROM DUAL
UNION ALL
SELECT '1-11TWQL', 'COPS', 'Validated',
TO_DATE ('12/23/2009 3:37:51', 'mm/dd/yyyy hh:mi:ss PM'), 'N' deleted_flag
FROM DUAL
UNION ALL
SELECT '1-11TWQL', 'D1', 'Ordered',
TO_DATE ('12/23/2009 3:04:24', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
FROM DUAL
UNION ALL
SELECT '1-11TWQL', 'D1', 'RFS',
TO_DATE ('12/23/2009 3:04:23', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
FROM DUAL
UNION ALL
SELECT '1-11TWQL', 'D1', 'Rejected',
TO_DATE ('12/23/2009 3:04:22', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
FROM DUAL
UNION ALL
SELECT '1-11TWQL', 'D1', 'Validated',
TO_DATE ('12/23/2009 3:04:23', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'COPS', 'RFS',
TO_DATE ('3/5/2010 12:04:24', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'COPS', 'RFS',
TO_DATE ('3/16/2010 7:55:50', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'COPS', 'RFS',
TO_DATE ('3/16/2010 7:55:51', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'COPS', 'Rejected',
TO_DATE ('3/5/2010 12:04:24', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'COPS', 'Rejected',
TO_DATE ('3/16/2010 7:55:50', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'COPS', 'Rejected',
TO_DATE ('3/16/2010 7:55:51', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'COPS', 'Validated',
TO_DATE ('12/23/2009 3:37:54', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'COPS', 'Validated',
TO_DATE ('12/23/2009 3:37:54', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'COPS', 'Validated',
TO_DATE ('12/23/2009 3:37:54', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'D1', 'Ordered',
TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM'), 'N' deleted_flag
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'D1', 'Ordered',
TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM'), 'N' deleted_flag
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'D1', 'RFS',
TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM'), 'N' deleted_flag
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'D1', 'RFS',
TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM'), 'N' deleted_flag
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'D1', 'Validated',
TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM'), 'N' deleted_flag
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'D1', 'Validated',
TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM'), 'N' deleted_flag
FROM DUAL
UNION ALL
SELECT '1-249A8Z', 'COPS', 'Validated',
TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM'), 'N' deleted_flag
FROM DUAL
UNION ALL
SELECT '1-249A8Z', 'COPS', 'Ordered',
TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM'), 'N' deleted_flag
FROM DUAL)
SELECT quote_id, ACCOUNT, status, captured_date, deleted_flag
FROM temp
ORDER BY quote_id, captured_date;try to wrap your query to become an in-line view. use a case statement or decode to your derived column RN from the analytic query of DENSE RANK. either way they both will work.
SQL> WITH temp AS
2 (SELECT '1-11TWQL' quote_id, 'COPS' ACCOUNT, 'Ordered' status,
3 TO_DATE ('12/23/2009 3:37:54',
4 'mm/dd/yyyy hh:mi:ss PM'
5 ) captured_date
6 FROM DUAL
7 UNION ALL
8 SELECT '1-11TWQL', 'COPS', 'RFS',
9 TO_DATE ('12/23/2009 3:37:50', 'mm/dd/yyyy hh:mi:ss PM')
10 FROM DUAL
11 UNION ALL
12 SELECT '1-11TWQL', 'COPS', 'Rejected',
13 TO_DATE ('12/23/2009 3:37:52', 'mm/dd/yyyy hh:mi:ss PM')
14 FROM DUAL
15 UNION ALL
16 SELECT '1-11TWQL', 'COPS', 'Validated',
17 TO_DATE ('12/23/2009 3:37:51', 'mm/dd/yyyy hh:mi:ss PM')
18 FROM DUAL
19 UNION ALL
20 SELECT '1-11TWQL', 'D1', 'Ordered',
21 TO_DATE ('12/23/2009 3:04:24', 'mm/dd/yyyy hh:mi:ss PM')
22 FROM DUAL
23 UNION ALL
24 SELECT '1-11TWQL', 'D1', 'RFS',
25 TO_DATE ('12/23/2009 3:04:23', 'mm/dd/yyyy hh:mi:ss PM')
26 FROM DUAL
27 UNION ALL
28 SELECT '1-11TWQL', 'D1', 'Rejected',
29 TO_DATE ('12/23/2009 3:04:22', 'mm/dd/yyyy hh:mi:ss PM')
30 FROM DUAL
31 UNION ALL
32 SELECT '1-11TWQL', 'D1', 'Validated',
33 TO_DATE ('12/23/2009 3:04:23', 'mm/dd/yyyy hh:mi:ss PM')
34 FROM DUAL
35 UNION ALL
36 SELECT '1-249A8X', 'COPS', 'RFS',
37 TO_DATE ('3/5/2010 12:04:24', 'mm/dd/yyyy hh:mi:ss PM')
38 FROM DUAL
39 UNION ALL
40 SELECT '1-249A8X', 'COPS', 'RFS',
41 TO_DATE ('3/16/2010 7:55:50', 'mm/dd/yyyy hh:mi:ss PM')
42 FROM DUAL
43 UNION ALL
44 SELECT '1-249A8X', 'COPS', 'RFS',
45 TO_DATE ('3/16/2010 7:55:51', 'mm/dd/yyyy hh:mi:ss PM')
46 FROM DUAL
47 UNION ALL
48 SELECT '1-249A8X', 'COPS', 'Rejected',
49 TO_DATE ('3/5/2010 12:04:24', 'mm/dd/yyyy hh:mi:ss PM')
50 FROM DUAL
51 UNION ALL
52 SELECT '1-249A8X', 'COPS', 'Rejected',
53 TO_DATE ('3/16/2010 7:55:50', 'mm/dd/yyyy hh:mi:ss PM')
54 FROM DUAL
55 UNION ALL
56 SELECT '1-249A8X', 'COPS', 'Rejected',
57 TO_DATE ('3/16/2010 7:55:51', 'mm/dd/yyyy hh:mi:ss PM')
58 FROM DUAL
59 UNION ALL
60 SELECT '1-249A8X', 'COPS', 'Validated',
61 TO_DATE ('12/23/2009 3:37:54', 'mm/dd/yyyy hh:mi:ss PM')
62 FROM DUAL
63 UNION ALL
64 SELECT '1-249A8X', 'COPS', 'Validated',
65 TO_DATE ('12/23/2009 3:37:54', 'mm/dd/yyyy hh:mi:ss PM')
66 FROM DUAL
67 UNION ALL
68 SELECT '1-249A8X', 'COPS', 'Validated',
69 TO_DATE ('12/23/2009 3:37:54', 'mm/dd/yyyy hh:mi:ss PM')
70 FROM DUAL
71 UNION ALL
72 SELECT '1-249A8X', 'D1', 'Ordered',
73 TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
74 FROM DUAL
75 UNION ALL
76 SELECT '1-249A8X', 'D1', 'Ordered',
77 TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
78 FROM DUAL
79 UNION ALL
80 SELECT '1-249A8X', 'D1', 'RFS',
81 TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
82 FROM DUAL
83 UNION ALL
84 SELECT '1-249A8X', 'D1', 'RFS',
85 TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
86 FROM DUAL
87 UNION ALL
88 SELECT '1-249A8X', 'D1', 'Validated',
89 TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
90 FROM DUAL
91 UNION ALL
92 SELECT '1-249A8X', 'D1', 'Validated',
93 TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
94 FROM DUAL
95 UNION ALL
96 SELECT '1-249A8Z', 'COPS', 'Validated',
97 TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
98 FROM DUAL
99 UNION ALL
100 SELECT '1-249A8Z', 'COPS', 'Ordered',
101 TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
102 FROM DUAL)
103 select vt.quote_id,
104 vt.account,
105 vt.status,
106 vt.captured_date,
107 case when vt.rn = 1 then 'N'
108 else 'Y'
109 end deleted_flag
110 from (SELECT quote_id, ACCOUNT, status, captured_date,
111 DENSE_RANK () OVER (PARTITION BY quote_id ORDER BY quote_id, ACCOUNT) rn
112 FROM temp
113 ORDER BY quote_id, captured_date) vt;
QUOTE_ID ACCOUNT STATUS CAPTURED_DATE DELETED_FLAG
1-11TWQL D1 Rejected 23-Dec-2009 3 Y
1-11TWQL D1 RFS 23-Dec-2009 3 Y
1-11TWQL D1 Validated 23-Dec-2009 3 Y
1-11TWQL D1 Ordered 23-Dec-2009 3 Y
1-11TWQL COPS RFS 23-Dec-2009 3 N
1-11TWQL COPS Validated 23-Dec-2009 3 N
1-11TWQL COPS Rejected 23-Dec-2009 3 N
1-11TWQL COPS Ordered 23-Dec-2009 3 N
1-249A8X COPS Validated 23-Dec-2009 3 N
1-249A8X COPS Validated 23-Dec-2009 3 N
1-249A8X COPS Validated 23-Dec-2009 3 N
1-249A8X COPS RFS 05-Mar-2010 1 N
1-249A8X COPS Rejected 05-Mar-2010 1 N
1-249A8X COPS RFS 16-Mar-2010 7 N
1-249A8X COPS Rejected 16-Mar-2010 7 N
1-249A8X COPS Rejected 16-Mar-2010 7 N
1-249A8X COPS RFS 16-Mar-2010 7 N
1-249A8X D1 Ordered 26-Mar-2010 1 Y
1-249A8X D1 Ordered 26-Mar-2010 1 Y
1-249A8X D1 RFS 26-Mar-2010 1 Y
1-249A8X D1 RFS 26-Mar-2010 1 Y
1-249A8X D1 Validated 26-Mar-2010 1 Y
1-249A8X D1 Validated 26-Mar-2010 1 Y
1-249A8Z COPS Validated 26-Mar-2010 1 N
1-249A8Z COPS Ordered 26-Mar-2010 1 N
25 rows selected
SQL> -
Can you please help me write below query in efficient way
Hello-
I have wrote one query and its very slow to get the data because i am counting the code at every column from the table in from clause.
SELECT SUM(diag_total) diag_total,
SUM(diag_complete) diag_complete,
SUM(diag_remaining) diag_remaining,
SUM(diag_declined) diag_declined
FROM (SELECT hpc.dmpc_hicn,(SELECT COUNT(DISTINCT d.msd_icd9_ref)
FROM d4c_map_suspects_to_diagnosis d
WHERE trim(d.msd_sd_hicn) = trim(hpc.dmpc_hicn)) diag_total,
(SELECT COUNT(DISTINCT dd.dspd_icd9)
FROM d4c_suspect_provider_diagnosis dd
WHERE dd.dspd_ds_id_ref = 1000
AND trim(dd.dspd_hicn) = trim(hpc.dmpc_hicn)
AND trim(dd.dspd_npi) = trim(hpc.dpmc_provider_no)) diag_complete,
-- AND hpc.dmpc_ss_id_ref = 1020) diag_complete,
(SELECT COUNT(DISTINCT dd.dspd_icd9)
FROM d4c_suspect_provider_diagnosis dd
WHERE dd.dspd_ds_id_ref = 1010
AND trim(dd.dspd_hicn) = trim(hpc.dmpc_hicn)
AND trim(dd.dspd_npi) = trim(hpc.dpmc_provider_no)) diag_remaining,
-- AND hpc.dmpc_ss_id_ref = 1020) diag_remaining,
(SELECT COUNT(DISTINCT dd.dspd_icd9)
FROM d4c_suspect_provider_diagnosis dd
WHERE dd.dspd_ds_id_ref = 1020
AND trim(dd.dspd_hicn) = trim(hpc.dmpc_hicn)
AND trim(dd.dspd_npi) = trim(hpc.dpmc_provider_no)) diag_declined
--AND hpc.dmpc_ss_id_ref = 1020) diag_declined
FROM d4c_provider_assignment pc, d4c_hicn_provider_claims hpc
WHERE pc.pa_assignedto = &imrrid
AND trim(pc.pa_providerid) = trim(hpc.dpmc_provider_no));
Can you please help me in this?
Thanks in advance.
Kind regards,
NikMay be this?
You dont even need sum as we are doing count for the whole data at a time. Please check the results and let us know if there is any issue.
SELECT COUNT (DISTINCT d.msd_icd9_ref) diag_total
,COUNT (DISTINCT CASE WHEN dd.dspd_ds_id_ref = 1000 THEN dd.dspd_icd9 END) diag_complete
,COUNT (DISTINCT CASE WHEN dd.dspd_ds_id_ref = 1010 THEN dd.dspd_icd9 END) diag_remaining
,COUNT (DISTINCT CASE WHEN dd.dspd_ds_id_ref = 1020 THEN dd.dspd_icd9 END) diag_declined
FROM d4c_provider_assignment pc
,d4c_hicn_provider_claims hpc
,d4c_suspect_provider_diagnosis dd
,d4c_map_suspects_to_diagnosis d
WHERE pc.pa_assignedto = &imrrid
AND TRIM (pc.pa_providerid) = TRIM (hpc.dpmc_provider_no)
AND TRIM (dd.dspd_hicn(+)) = TRIM (hpc.dmpc_hicn)
AND TRIM (dd.dspd_npi(+)) = TRIM (hpc.dpmc_provider_no)
AND TRIM (d.msd_sd_hicn(+)) = TRIM (hpc.dmpc_hicn); -
I would like to create a view on this table with four columns
1. PN#_EXP_DATE
2. PN#
3. PN#_EFF_DATE
4. PN#
P_S_C A_C P EXP_DT
21698 13921 1 5/29/2009 3:15:41 PM
21698 13921 1 5/29/2009 3:54:57 PM
21698 1716656 4 5/29/2009 3:15:41 PM
21698 3217 3 5/29/2009 3:15:40 PM
21698 3217 3 5/29/2009 3:54:57 PM
21698 60559 2 5/29/2009 3:15:41 PM
21698 60559 2 5/29/2009 3:54:57 PM
I have a trigger on A, which inserts the DML records into B. (Table A and B structure is the almost the same,
where table B will have one extra column exp_dt)
NOw Table B can have records with same P_S_C and A_C columns and exp_dt will capture the history.
for example: from the above sample data, let us take first two records..
P_S_C A_C P EXP_DT
21698 13921 1 5/29/2009 3:15:41 PM --- Record 1
21698 13921 1 5/29/2009 3:54:57 PM --- Record 2
from this..
Note: 1. Table A and Table C can be joined using A.P_S_C and C.R_C to get the start_date.
2. PN# comes from table D. It contains numbers for the resp. weeks.
3. PN#_EFF_DATE is the previous immediate previous date for that record in history table (Table B).
I wanted the data like..
---- this is for the second record in the above..
PN#_EXP_DATE PN# PN#_EFF_DATE PN#
5/29/2009 3:54:57 PM 214 5/29/2009 3:15:41 PM 214
---- this is for the first record in the above..
PN#_EXP_DATE PN# PN#_EFF_DATE PN#
5/29/2009 3:54:41 PM 214 ( for this we should query the table C to get the
start_date, for this combinatation of P_S_C and A_C in table B
where B.P_S_C = C.A_C
and that value should be the EFF_DT for this record)
Please help me with this....
Thanks in advance..Hi All,
select d.P# as "PN#_EXP_DATE", exp_date
from daily_prd d, cbs1_assoc_hist b
where to_char(d.day_date,'MM/DD/YYYY') = to_char(b.exp_date,'MM/DD/YYYY')
and d.period_type = 'TIMEREPORT';
This above query gives the output as follows:
pn#_exp_date exp_date
214 5/29/2009 3:15:40 PM
214 5/29/2009 3:15:41 PM
214 5/29/2009 3:15:41 PM
214 5/29/2009 3:15:41 PM
214 5/29/2009 3:54:57 PM
214 5/29/2009 3:54:57 PM
214 5/29/2009 3:54:57 PM
This below is the data from history table (Table B).
P_S_C A_C PLACE EXP_DATE
21698 3217 3 5/29/2009 3:15:40 PM
21698 13921 1 5/29/2009 3:15:41 PM
21698 1716656 4 5/29/2009 3:15:41 PM
21698 60559 2 5/29/2009 3:15:41 PM
21698 13921 1 5/29/2009 3:54:57 PM
21698 3217 3 5/29/2009 3:54:57 PM
21698 60559 2 5/29/2009 3:54:57 PM
I got the pn#_exp_date from the Table 'D', for the given exp_date from Table B.
My question is again....
CASE - 1
from the given records above, I need to look for exp_date for the given same P_S_C and A_C.
in this case we can take the example...
P_S_C A_C PLACE EXP_DATE
21698 3217 3 5/29/2009 3:15:40 PM
21698 3217 3 5/29/2009 3:54:57 PM
In this case, the
pn#_exp_date exp_date pn#_eff_date eff_date
214 5/29/2009 3:15:57 PM < PN# corresponding to the 5/29/2009 3:15:40 PM
eff_date .>
<Basically the eff_date is
nothing but the exp_date only.
we should take the immediate before one.
In this case, our eff_date is '5/29/2009 3:15:40 PM'.
but how to get this.
CASE - 2
from the above sample data, consider this
P_S_C A_C PLACE EXP_DATE
21698 1716656 4 5/29/2009 3:15:41 PM
In this case, there is only one record for the P_S_C and A_C combination.
The expected result :
pn#_exp_date exp_date pn#_eff_date eff_date
214 5/29/2009 3:15:41 PM < PN# corresponding to the 5/29/2009 3:15:40 PM
eff_date .>
<Basically the eff_date is
nothing but the exp_date only.
we should take the immediate before one.
In this case to get the eff_date, we should query the Table 'C', to get the eff_date, which is START_DT column in this table.
for this join B.P_S_C and C.R_C.
Hope I am clear now..
Thanks in advance..... -
Please help with an embedded query (INSERT RETURNING BULK COLLECT INTO)
I am trying to write a query inside the C# code where I would insert values into a table in bulk using bind variables. But I also I would like to receive a bulk collection of generated sequence number IDs for the REQUEST_ID. I am trying to use RETURNING REQUEST_ID BULK COLLECT INTO :REQUEST_IDs clause where :REQUEST_IDs is another bind variable
Here is a full query that use in the C# code
string sql = "INSERT INTO REQUESTS_TBL(REQUEST_ID, CID, PROVIDER_ID, PROVIDER_NAME, REQUEST_TYPE_ID, REQUEST_METHOD_ID, " +
"SERVICE_START_DT, SERVICE_END_DT, SERVICE_LOCATION_CITY, SERVICE_LOCATION_STATE, " +
"BENEFICIARY_FIRST_NAME, BENEFICIARY_LAST_NAME, BENEFICIARY_DOB, HICNUM, CCN, " +
"CLAIM_RECEIPT_DT, ADMISSION_DT, BILL_TYPE, LANGUAGE_ID, CONTRACTOR_ID, PRIORITY_ID, " +
"UNIVERSE_DT, REQUEST_DT, BENEFICIARY_M_INITIAL, ATTENDING_PROVIDER_NUMBER, " +
"BILLING_NPI, BENE_ZIP_CODE, DRG, FINAL_ALLOWED_AMT, STUDY_ID, REFERRING_NPI) " +
"VALUES " +
"(SQ_CDCDATA.NEXTVAL, :CIDs, :PROVIDER_IDs, :PROVIDER_NAMEs, :REQUEST_TYPE_IDs, :REQUEST_METHOD_IDs, " +
":SERVICE_START_DTs, :SERVICE_END_DTs, :SERVICE_LOCATION_CITYs, :SERVICE_LOCATION_STATEs, " +
":BENEFICIARY_FIRST_NAMEs, :BENEFICIARY_LAST_NAMEs, :BENEFICIARY_DOBs, :HICNUMs, :CCNs, " +
":CLAIM_RECEIPT_DTs, :ADMISSION_DTs, :BILL_TYPEs, :LANGUAGE_IDs, :CONTRACTOR_IDs, :PRIORITY_IDs, " +
":UNIVERSE_DTs, :REQUEST_DTs, :BENEFICIARY_M_INITIALs, :ATTENDING_PROVIDER_NUMBERs, " +
":BILLING_NPIs, :BENE_ZIP_CODEs, :DRGs, :FINAL_ALLOWED_AMTs, :STUDY_IDs, :REFERRING_NPIs) " +
" RETURNING REQUEST_ID BULK COLLECT INTO :REQUEST_IDs";
int[] REQUEST_IDs = new int[range];
cmd.Parameters.Add(":REQUEST_IDs", OracleDbType.Int32, REQUEST_IDs, System.Data.ParameterDirection.Output);
However, when I run this query, it gives me a strange error ORA-00925: missing INTO keyword. I am not sure what that error means since I am not missing any INTOs
Please help me resolve this error or I would appreciate a different solution
Thank youIt seems you are not doing a bulk insert but rather an array bind.
(Which you will also find that it is problematic to do an INSERT with a bulk collect returning clause (while this works just fine for update/deletes) :
http://www.oracle-developer.net/display.php?id=413)
But you are using array bind, so you simply just need to use a
... Returning REQUEST_ID INTO :REQUEST_IDand that'll return you a Rquest_ID[]
see below for a working example (I used a procedure but the result is the same)
//Create Table Zzztab(Deptno Number, Deptname Varchar2(50) , Loc Varchar2(50) , State Varchar2(2) , Idno Number(10)) ;
//create sequence zzzseq ;
//CREATE OR REPLACE PROCEDURE ZZZ( P_DEPTNO IN ZZZTAB.DEPTNO%TYPE,
// P_DEPTNAME IN ZZZTAB.DEPTNAME%TYPE,
// P_LOC IN ZZZTAB.LOC%TYPE,
// P_State In Zzztab.State%Type ,
// p_idno out zzztab.idno%type
// IS
//Begin
// Insert Into Zzztab (Deptno, Deptname, Loc, State , Idno)
// Values (P_Deptno, P_Deptname, P_Loc, P_State, Zzzseq.Nextval)
// returning idno into p_idno;
//END ZZZ;
//Drop Procedure Zzz ;
//Drop Sequence Zzzseq ;
//drop Table Zzztab;
class ArrayBind
static void Main(string[] args)
// Connect
string connectStr = GetConnectionString();
// Setup the Tables for sample
Setup(connectStr);
// Initialize array of data
int[] myArrayDeptNo = new int[3]{1, 2, 3};
String[] myArrayDeptName = {"Dev", "QA", "Facility"};
String[] myArrayDeptLoc = {"New York", "Chicago", "Texas"};
String[] state = {"NY","IL","TX"} ;
OracleConnection connection = new OracleConnection(connectStr);
OracleCommand command = new OracleCommand (
"zzz", connection);
command.CommandType = CommandType.StoredProcedure;
// Set the Array Size to 3. This applied to all the parameter in
// associated with this command
command.ArrayBindCount = 3;
command.BindByName = true;
// deptno parameter
OracleParameter deptNoParam = new OracleParameter("p_deptno",OracleDbType.Int32);
deptNoParam.Direction = ParameterDirection.Input;
deptNoParam.Value = myArrayDeptNo;
command.Parameters.Add(deptNoParam);
// deptname parameter
OracleParameter deptNameParam = new OracleParameter("p_deptname", OracleDbType.Varchar2);
deptNameParam.Direction = ParameterDirection.Input;
deptNameParam.Value = myArrayDeptName;
command.Parameters.Add(deptNameParam);
// loc parameter
OracleParameter deptLocParam = new OracleParameter("p_loc", OracleDbType.Varchar2);
deptLocParam.Direction = ParameterDirection.Input;
deptLocParam.Value = myArrayDeptLoc;
command.Parameters.Add(deptLocParam);
//P_STATE -- -ARRAY
OracleParameter stateParam = new OracleParameter("P_STATE", OracleDbType.Varchar2);
stateParam.Direction = ParameterDirection.Input;
stateParam.Value = state;
command.Parameters.Add(stateParam);
//idParam-- ARRAY
OracleParameter idParam = new OracleParameter("p_idno", OracleDbType.Int64 );
idParam.Direction = ParameterDirection.Output ;
idParam.OracleDbTypeEx = OracleDbType.Int64;
command.Parameters.Add(idParam);
try
connection.Open();
command.ExecuteNonQuery ();
Console.WriteLine("{0} Rows Inserted", command.ArrayBindCount);
//now cycle through the output param array
foreach (Int64 i in (Int64[])idParam.Value)
Console.WriteLine(i);
catch (Exception e)
Console.WriteLine("Execution Failed:" + e.Message);
finally
// connection, command used server side resource, dispose them
// asap to conserve resource
connection.Close();
command.Dispose();
connection.Dispose();
Console.WriteLine("Press Enter to finish");
Console.ReadKey();
} -
Export specific records from all table? Please help me with my query
hi
there are around 200 tables, I want to take a export of all tables of xyz schema.
My requirement is just a few records of primary key and their relevant records from other tables to be exported by using exp or expdp utility.Hi Toni...
Thanks for your reply.
Could you please help me understand how to user this expdp query...
and what exactly should i mention in the parfile. I want all relevant records from all tables of primary key. please help me to write a query accordingly. -
Please help me constructing this query
please help me .
table a
===========
transactionid personname year dept
r001 person1 y1 d1
r002 person1 y2 d2
r005 person3 y1 d2
r004 person2 y2 d1
table b
===========
transactionid personname year
r005 person3 y2
r006 person4 y1
r001 person1 y1
outout should be like
======================
transactionid personname year dept
r001 person1 y1 d1 record present (combination of transactionid/personname/year)in table a from table b
r005 person3 y2 d2 (no data present in table a (transactionid/personname/year) from table b
so it will retrive previous dept records for this person for this year so here d2)
r006 person4 y1 unknown no data present for this person in table a so department will be unknown
table creation script
=====================
CREATE TABLE A
TRANSACTIONID VARCHAR2(30 BYTE),
PERSONNAME VARCHAR2(30 BYTE),
YEAR VARCHAR2(30 BYTE),
DEPT VARCHAR2(30 BYTE)
SET DEFINE OFF;
Insert into A
(TRANSACTIONID, PERSONNAME, YEAR, DEPT)
Values
('r001', 'person1', 'y1', 'd1');
Insert into A
(TRANSACTIONID, PERSONNAME, YEAR, DEPT)
Values
('r002', 'person1', 'y2', 'd2');
Insert into A
(TRANSACTIONID, PERSONNAME, YEAR, DEPT)
Values
('r004', 'person2', 'y2', 'd1');
Insert into A
(TRANSACTIONID, PERSONNAME, YEAR, DEPT)
Values
('r005', 'person3', 'y1', 'd2');
COMMIT;
CREATE TABLE B
TRANSACTIONID VARCHAR2(30 BYTE),
PERSONNAME VARCHAR2(30 BYTE),
YEAR VARCHAR2(30 BYTE)
SET DEFINE OFF;
Insert into B
(TRANSACTIONID, PERSONNAME, YEAR)
Values
('r001', 'person1', 'y1');
Insert into B
(TRANSACTIONID, PERSONNAME, YEAR)
Values
('r006', 'person4', 'y1');
Insert into B
(TRANSACTIONID, PERSONNAME, YEAR)
Values
('r005', 'person3', 'y2');
COMMIT;Anirudha Dhopate wrote:
Following query should work - Data magic:
SQL> SELECT *
2 FROM a
3 /
TRANSACTIONID PERSONNAME YEAR DEPT
r001 person1 2010 d1
r002 person1 2011 d2
r004 person2 2011 d1
r005 person3 2010 d2
r001 person1 2010 d2
SQL> SELECT *
2 FROM b
3 /
TRANSACTIONID PERSONNAME YEAR
r001 person1 2010
r006 person4 2010
r005 person3 2011
SQL> SELECT b.transactionid
2 ,b.personname
3 ,b.year
4 ,a.dept
5 FROM a
6 RIGHT OUTER JOIN b
7 ON ((a.transactionid = b.transactionid) AND
8 (a.personname = b.personname) AND
9 (a.year = b.year OR a.year = b.year - 1))
10 ORDER BY b.transactionid
11 /
TRANSACTIONID PERSONNAME YEAR DEPT
r001 person1 2010 d1
r001 person1 2010 d2
r005 person3 2011 d2
r006 person4 2010
SQL> select b.transactionid,
2 b.personname,
3 b.year,
4 max(a.dept) keep(dense_rank last order by a.year) dept
5 from b
6 left join
7 a
8 on (
9 b.transactionid = a.transactionid
10 and
11 b.personname = a.personname
12 and
13 b.year >= a.year
14 )
15 group by b.transactionid,
16 b.personname,
17 b.year
18 /
TRANSACTIONID PERSONNAME YEAR DEPT
r001 person1 2010 d2
r005 person3 2011 d2
r006 person4 2010
SQL> SY. -
Please help how to design query to implement this requirement.
Dear Expert,
Here is what I have and what the requirement is:
I have a InfoCube:
Dimensions:
1. Material
2. Currency
Key Figures:
1. Qty
2. Amount
We want to get the Qty and Amount by Material, but use Currency to be the filter.
It means for example, if the Currency have CNY for one material, we need to show all the Qty/Amount, not only Qty/Amount in CNY.
So please help give some idea about how to design the query to implement this requirement.
Thank you,
AndyHi Andy:
To accomplish your requirement you need to do 2 things:
1. Create a Variable for the Currency (to be used as the Target Currency not as a filter for the Characteristic itself).
2. Use the Standard Currency Conversion for the Amount Key Figure (Conversion Tab).
This way, while executing the report you can select any currency you want and all the amounts will be converted to that currency.
Take a look at this paper:
"How to... Use Variables for Currency Conversion"
http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/287bab90-0201-0010-f48e-cc55b0cd13d0?quicklink=index&overridelayout=true
A more detailed explanation can be found on this article provided by Ramakrishna Gattikoppula:
"Currency Conversion in BI 7.0"
http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/a0d5bf96-b19b-2c10-e3b6-e2f12a3de99a?quicklink=index&overridelayout=true
In summary, to work with the Standard Currency Conversion you need to define 4 things:
- Exchange Rate Type.
- Source Currency.
- Target Currency.
- Time Reference.
Regards,
Francisco Milán.
Edited by: Francisco Milan on May 31, 2010 11:19 AM -
Please help to write a query in this format
Sir,
I am having a table like following
Deptno job
10 aaa
11 bbb
12 ccc
10 ddd
11 eee
12 ffff
10 ggg
deptno-number
job- varchar
in the above table I want the out put like following in a single query ,is it possible.
10 aaa,ddd,ggg (concatenation of all jobs under that particular deptno)
11 bbb,eee
12 ccc,ffff
I tried with Connect by clause, but i am not able to successfully execute it.
select dept,substr(max(substr(sys_connect_by_path (job,', '),2)),1,100)
as job
from test
start with dept = 10
connect by job = prior job
and prior dept = dept
group by dept;
please help me.
regards
MathewHi Mathew,
One approach is to write a specific function to solve the problems. The get_job function listed below returns a list of employees for the specified department.
CREATE OR REPLACE FUNCTION get_job (p_deptno in emp.deptno%TYPE)
RETURN VARCHAR2
IS
l_text VARCHAR2(32767) := NULL;
BEGIN
FOR cur_rec IN (SELECT Job FROM test WHERE deptno = p_deptno) LOOP
l_text := l_text || ',' || cur_rec.ename;
END LOOP;
RETURN LTRIM(l_text, ',');
END;
SHOW ERRORS
The function can then be incorporated into a query as follows.
COLUMN employees FORMAT A50
SELECT deptno,
get_job(deptno) AS Job
FROM test
GROUP by deptno;
DEPTNO JOB
10 aaa,ddd,ggg
11 bbb,eee
12 ccc,ffff
Thanks,
Nagesh. -
Hi experts,
I have data like this in a table with 5000 records.
ID cid Name
1 10 Ram
1 20 Raj
2 10 Kiran
2 20 Kishor
2 30 Krishna
2 40 Karuna
2 50 Kamesh
2 50 Kumar
2 50 Kamal
2 60 Keerti
3 10 Syam
3 20 Suresh
3 30 Suman
3 40 Santosh
3 40 Sarat
3 50 Sirisha
3 60 Sumanth
4 10 Tarun
4 20 Tanish
4 30 Taman
4 40 Tomas
4 40 Teenu
5 10 Prakash
5 20 Pavan
5 30 Prasad
etc
I want the output like
ID CID NAME
1 10,20 Ram,Raj
2 10,20,30,40,50,50,50,60 Kiran,Kishor,Krishna,Karuna,Kamesh,Kamal,Keerti
3 10,20,30,40,40,50,60 Syam,Suresh,Suman,Santosh, Sarat,Sirisha,Sumanth
4 10,20,30,40,40 Tarun,Tanish,Taman,Tomas,Teenu
5 10,20,30 Prakash,Pavan,Prasad
Please help me to get the output like this
Thanks in advancewith t as (
select 1 id,10 cid,'Ram' name from dual union all
select 1,20,'Raj' from dual union all
select 2,10,'Kiran' from dual union all
select 2,20,'Kishor' from dual union all
select 2,30,'Krishna' from dual union all
select 2,40,'Karuna' from dual union all
select 2,50,'Kamesh' from dual union all
select 2,50,'Kumar' from dual union all
select 2,50,'Kamal' from dual union all
select 2,60,'Keerti' from dual union all
select 3,10,'Syam' from dual union all
select 3,20,'Suresh' from dual union all
select 3,30,'Suman' from dual union all
select 3,40,'Santosh' from dual union all
select 3,40,'Sarat' from dual union all
select 3,50,'Sirisha' from dual union all
select 3,60,'Sumanth' from dual union all
select 4,10,'Tarun' from dual union all
select 4,20,'Tanish' from dual union all
select 4,30,'Taman' from dual union all
select 4,40,'Tomas' from dual union all
select 4,40,'Teenu' from dual union all
select 5,10,'Prakash' from dual union all
select 5,20,'Pavan' from dual union all
select 5,30,'Prasad' from dual
-- end of on-the-fly data sample
select id,
rtrim(xmlagg(xmlelement(e,cid,',').extract('//text()') order by cid),',') cid,
rtrim(xmlagg(xmlelement(e,name,',').extract('//text()') order by cid),',') name
from t
group by id
order by id
ID CID NAME
1 10,20 Ram,Raj
2 10,20,30,40,50,50,50,60 Kiran,Kishor,Krishna,Karuna,Kamesh,Kamal,Kumar,Keerti
3 10,20,30,40,40,50,60 Syam,Suresh,Suman,Santosh,Sarat,Sirisha,Sumanth
4 10,20,30,40,40 Tarun,Tanish,Taman,Tomas,Teenu
5 10,20,30 Prakash,Pavan,Prasad
SQL> SY. -
Hi Everyone...Please help me with this query...!
Please Help me with this doubt as I am unable to understand the logic...behind this code. It's a begineer level code but I need to understand the logic so that I am able to grasp knowledge. Thank you all for being supportive. Please help me.
//Assume class Demo is inherited from class SuperDemo...in other words class Demo extends SuperDemo
//Volume is a method declared in SuperDemo which returns an integer value
//weight is an integer vairable declared in the subclass which is Demo
class Example
public static void main(String qw[])
Demo ob1=new Demo(3,5,7,9);
//Calling Constructor of Demo which takes in 4 int parameters
SuperDemo ob2=new SuperDemo();
int vol;
vol=ob1.volume();
System.out.println("Volume of ob1 is " + vol);
System.out.println("Weight of ob1 is " + ob1.weight);
System.out.println();
ob2=ob1;
}Can someone please make me understand --- how is this possible and why !
If the above statement is valid then why not this one "System.out.println(ob2.weight);"
Thanks Thanks Thanks!u see the line wherein I am referencing the objectof
a subclass to the superclass...right? then why we
can't do System.out.println(ob2.weight)?You need to distinguish two things:
- the type of the object, which determines with the
object can do
- the type of the reference to the object, which
determines what you see that you can do
Both don't necessarily have to match. When you use a
SuperDemo reference (obj2) to access a Demo instance
(obj1), for all you know, the instance behind obj2 is
of type SuperDemo. That it's in reality of type Demo
is unknown to you. And usually, you don't care -
that's what polymorphism is about.
So you have a reference obj2 of type SuperDemo.
SuperDemo objects don't have weight, so you don't see
it - even though it is there.So from ur explanation wat I understand is - Even though u reference a subclass object to a superclass, u will only be able to access the members which are declared in the superclass thru the same...right
? -
I have table a with columns ca1,ca2,ca3
and I have a table b with columns cb1, cb2,cb3
and a and b tables are related with a table's ca2 and b table's cb2
ca1 not null,ca2 can be null and cb2 is a not null column, cb3 not null
I want the output of ca1 and cb3
If ca2 is null then the output should contain ca1 value and null for cb3
If ca2 is not nulll comparing both it has to return cb3 value..
Could anybody help me in tis???
Thanks in advance..Hope I understood your requirement.
SELECT NVL(ca2,ca1) ca1, DECODE(ca2,NULL,ca2,cb3) cb3
FROM a, b
WHERE ca2=cb2 -
Please help me tune this query
Hi,
Could you please suggest how the below query can be tuned? At present the query takes an hour to execute for a single transaction.
===================================================================
/* Formatted on 2009/07/27 17:44 (Formatter Plus v4.8.8) */
SELECT 'x' x,
SUBSTR (cn.trx_number, 1, INSTR (cn.trx_number, 'CN') - 1) invoice_num,
DECODE (INSTR (cn.trx_number, 'CNT'),
0, '¿¿¿¿¿¿¿¿ (CREDIT NOTE)',
'¿¿¿¿¿¿¿¿ (CREDIT NOTE) / ¿¿¿¿¿¿¿¿¿¿¿'
) report_name,
INSTR (cn.trx_number, 'CNT') v_or_nv,
xxth_get_info.get_org_name (:org_id) head_office_name, lc.location_id,
lc.location_code, lc.attribute1 tax_regis_number,
lc.attribute2 tax_payer_id, lc.attribute14 branch_number,
lc.attribute15 name_of_place_of_business,
lc.address_line_1 || ' ' || lc.address_line_2 address_line1,
lc.address_line_3 || ' ' || lc.region_1 address_line2,
lc.region_2
|| ' '
|| lc.town_or_city
|| ' '
|| lc.postal_code
|| ' '
|| lc.country address_line3,
cn.type_cn, cn.rac_bill_to_customer_name, cn.address1,
cn.raa_bill_to_address3, cn.bill_to_site_use_id, cn.trx_date,
cn.trx_number, cn.rac_bill_to_customer_num, cn.description,
ABS (cn.extended_amount) extended_amount, ABS (cn.tax_amt) tax_amt,
rc.trx_rec_number, rc.apply_date, rc.cash_receipt_id
FROM ra_cust_trx_types cc,
hr_locations_v lc,
(SELECT b.cash_receipt_id, a.trx_number, b.trx_rec_number,
b.apply_date
FROM ar_payment_schedules a, ar_app_adj_v b,ar_cash_receipts c
WHERE b.payment_schedule_id = a.payment_schedule_id
AND c.cash_receipt_id=b.cash_receipt_id
AND c.status='APP'
AND b.CLASS = 'Payment'
group by b.cash_receipt_id, a.trx_number, b.trx_rec_number,b.apply_date) rc,
(SELECT 'B' type_cn, a.customer_trx_id, a.cust_trx_type_id,
a.rac_bill_to_customer_name,
a.raa_bill_to_address1
|| ' '
|| a.raa_bill_to_address2 address1,
a.raa_bill_to_address3, a.bill_to_site_use_id, a.trx_date,
a.trx_number,
( SUBSTR (a.trx_number, 1,
INSTR (a.trx_number, 'CN', -1) - 1)
|| SUBSTR (a.trx_number, INSTR (a.trx_number, 'CN', -1) + 2)
) trx_number_cmp,
a.rac_bill_to_customer_num,
ctl.description, -- b.description
sum(nvl(ctl.gross_extended_amount, ctl.extended_amount)) extended_amount, -- V2.0
-- SUM (c.extended_amount) tax_amt -- V2.0
select SUM (ctl_tax.extended_amount)
from ra_customer_trx_lines ctl_tax,
ra_customer_trx_lines ctl_line
WHERE ctl_tax.link_to_cust_trx_line_id = ctl_line.customer_trx_line_id
AND ctl_tax.line_type = 'TAX'
AND ctl_tax.customer_trx_id = a.customer_trx_id
) tax_amt
FROM ra_customer_trx_partial_v a,
ra_customer_trx_lines ctl,
ra_customer_trx ct,
ra_cust_trx_types ctt,
hz_cust_acct_sites radd,
hz_party_sites party_site,
hz_locations loc,
hz_cust_site_uses site
-- ra_customer_trx_lines_v b
-- ar_tax_summ_v c
WHERE a.ctt_class = 'CM'
AND ctl.line_type = 'LINE'
&P_CUSTOMER_NUM_CLAUSE
&P_CUST_TRX_NUM_CLAUSE
-- AND b.customer_trx_id = a.customer_trx_id
AND ctl.customer_trx_id = a.customer_trx_id
AND ctl.customer_trx_id = ct.customer_trx_id
AND ct.cust_trx_type_id = ctt.cust_trx_type_id
AND ctt.TYPE NOT IN ('DEP', 'GUAR', 'BR')
AND ct.bill_to_site_use_id = site.site_use_id
AND site.cust_acct_site_id = radd.cust_acct_site_id
AND radd.party_site_id = party_site.party_site_id
AND loc.location_id = party_site.location_id
-- AND c.customer_trx_id(+) = a.customer_trx_id
GROUP BY a.cust_trx_type_id,
a.rac_bill_to_customer_name,
a.raa_bill_to_address1,
a.raa_bill_to_address2,
a.raa_bill_to_address3,
a.bill_to_site_use_id,
a.trx_date,
a.trx_number,
a.rac_bill_to_customer_num,
a.customer_trx_id,
ctl.description,
(SUBSTR (a.trx_number, 1, INSTR (a.trx_number, 'CN') - 1)
)) cn
WHERE cc.cust_trx_type_id = cn.cust_trx_type_id
AND cc.global_attribute19 = lc.location_code(+)
AND rc.trx_number = cn.trx_number_cmp
=============================================================Post relevant all details as explained in this instruction:
HOW TO: Post a SQL statement tuning request - template posting
Maybe you are looking for
-
Unable to install SQL Server 2012 Developer
I have a problem with installing SQL Server 2012 (no matter which edition I choose). Installation usually runs well, but near the end shows up an error: TITLE: Microsoft SQL Server 2012 Service Pack 1 Setup The following error has occurred: Wait on t
-
How to connect korg triton workstation with GB?
I would like to connect my triton workstation with GB using MIDIMAN midi interface but it doesn't work for me. I have iMac with OS X 10.6.8. GB is version 5.1. Do I need to do additional setup?
-
I decided to compile myself a new kernel using a PKGBUILD from AUR, which contains Ingo Molnar's real time patch. I know that there are some entries int the wiki about this (Kernel Compilation with ABS, Custom Kernel Compilation with ABS, Kernel Patc
-
No History [Useless Radio Button]
Windows 7 -Skype Version 7.2.59.103 Tools/Options/Privacy Why is 'no history' even placed as an option? Been skyping for a few years and even NOW it's useless. I have to clear my history every time I log on. WHY????????????????????? Attachments: No H
-
Photoshop CS4 Video Card? - Need Display Port
You folks have been terrific in helping me with this project. For those that have not seen my previous messages, I am building a computer for a friend who uses Photoshop CS4 exclusively for 2D photo work. That's all he uses his computer for, so nothi