SQL Query in mapping to load warehouse table
Hi experts,
I hope you can help me to solve my problem. I already searched here in forum how we can add a query in a mapping but still not found an answer.
In my warehouse I have a time dimension table which has a unique dimension key and all date information. In my source database I have a table for sales information. In that sales table I have a field called date. This date will be in format dd.mm.yyyy.
I also have a sales table in my warehouse what is nearly a copy of the source sales table. I have only one more field in this warehouse sales table called "time_dim_key". That field should get the dimension key of the warehouse time dimension table depending to the date out of the sales table from source.
To do that I'm thinking about a mapping what includes:
- the source sales table
- the warehouse dimension time table
- the warehouse sales table
The normal fields I can directly map from source sales table to warehouse sales table.
But the "time_dim_key" field of warehouse sales table should get filled like:
select dimension_key from warehouse_time_dim_table where day_date = source_sales_table.date
Unfortunately I don't know how I include a query to get the correct date out of that source sales table in the mapping to fill the warehouse sales table.
I hope somebody can help me to solve that issue.
Thanks a lot!
Regards,
David
take joiner from the pallete
and create two groups
1.warehouse_time_dim_table
2.source_sales_table
then in join condition write
warehouse_time_dim_table.day_date = source_sales_table.date
That will solve the purpose.
Cheers
Nawneet
Similar Messages
-
SQL Query for mapping a set of batches to a class rooms group
Hi All,
I am using Oracle 11g Release 2 database.
I have the following data set:
ClassRooms
ClassId ClassName Capacity Group
1 Babbage/Software Engg Lab 24 1
2 Basement - PG Block 63 1
3 Classroom 1 56 1
4 Classroom 10 24 1
5 Classroom 11 24 1
6 Classroom 12 35 1
7 Classroom 13 42 1
8 Classroom 14 42 1
9 Classroom 15 42 1
10 Classroom 2 35 1
11 Classroom 3 35 1
12 Classroom 4 35 1
13 Classroom 5 35 1
14 Classroom 6 25 1
15 Classroom 7 25 1
16 Classroom 8 24 1
17 Classroom 9 24 1
18 Control Sys Lab 24 1
19 Dig & Embd Sys Lab 20 1
20 DSP & Comm Lab 20 1
21 Electromechanical System Lab 28 1
22 Farabi/Web Tech Lab 36 1
23 Gen Purpose Lab 40 1
24 Shirazi/DB Tech Lab 36 1
25 Adv Elect Lab 30 2
26 Classroom 16 42 2
27 Classroom 17 49 2
28 Classroom 18 56 2
29 Classroom 19 42 2
30 Classroom 20 49 2
31 Classroom 21 35 3
32 Classroom 22 35 3
33 MDA Lab 20 3
DegreeBatches
BatchId BatchName Strength
1 BIT-11 79
2 BIT-12 28
3 BS(CS)-1 35
4 BS(CS)-2 78
5 BE(SE)-1 69
6 BE(SE)-2 84
7 BE(SE)-3 64
8 BICSE-7 84
9 BICSE-8 43
10 BEE-1 112
11 BEE-2 151
12 BEE-3 157
13 BEE-4 157
I want to map a degree batch combination to a class rooms group in such away that they fully utilize maximum capacity of the class rooms within a group (Ideal case) or as close to it as possible. Can it be done with a SQL query?
Any response will be highly appreciated.
SQL Scripts to generate the required tables and populate data is below:
CREATE TABLE ClassRooms (ClassId NUMBER, ClassName VARCHAR2(50), Capacity NUMBER, Group NUMBER);
INSERT INTO ClassRooms VALUES(1,'Babbage/Software Engg Lab',24,1);
INSERT INTO ClassRooms VALUES(2,'Basement - PG Block',63,1);
INSERT INTO ClassRooms VALUES(3,'Classroom 1',56,1);
INSERT INTO ClassRooms VALUES(4,'Classroom 10',24,1);
INSERT INTO ClassRooms VALUES(5,'Classroom 11',24,1);
INSERT INTO ClassRooms VALUES(6,'Classroom 12',35,1);
INSERT INTO ClassRooms VALUES(7,'Classroom 13',42,1);
INSERT INTO ClassRooms VALUES(8,'Classroom 14',42,1);
INSERT INTO ClassRooms VALUES(9,'Classroom 15',42,1);
INSERT INTO ClassRooms VALUES(10,'Classroom 2',35,1);
INSERT INTO ClassRooms VALUES(11,'Classroom 3',35,1);
INSERT INTO ClassRooms VALUES(12,'Classroom 4',35,1);
INSERT INTO ClassRooms VALUES(13,'Classroom 5',35,1);
INSERT INTO ClassRooms VALUES(14,'Classroom 6',25,1);
INSERT INTO ClassRooms VALUES(15,'Classroom 7',25,1);
INSERT INTO ClassRooms VALUES(16,'Classroom 8',24,1);
INSERT INTO ClassRooms VALUES(17,'Classroom 9',24,1);
INSERT INTO ClassRooms VALUES(18,'Control Sys Lab',24,1);
INSERT INTO ClassRooms VALUES(19,'Dig & Embd Sys Lab',20,1);
INSERT INTO ClassRooms VALUES(20,'DSP & Comm Lab',20,1);
INSERT INTO ClassRooms VALUES(21,'Electromechanical System Lab',28,1);
INSERT INTO ClassRooms VALUES(22,'Farabi/Web Tech Lab',36,1);
INSERT INTO ClassRooms VALUES(23,'Gen Purpose Lab',40,1);
INSERT INTO ClassRooms VALUES(24,'Shirazi/DB Tech Lab',36,1);
INSERT INTO ClassRooms VALUES(25,'Adv Elect Lab',30,2);
INSERT INTO ClassRooms VALUES(26,'Classroom 16',42,2);
INSERT INTO ClassRooms VALUES(27,'Classroom 17',49,2);
INSERT INTO ClassRooms VALUES(28,'Classroom 18',56,2);
INSERT INTO ClassRooms VALUES(29,'Classroom 19',42,2);
INSERT INTO ClassRooms VALUES(30,'Classroom 20',49,2);
INSERT INTO ClassRooms VALUES(31,'Classroom 21',35,3);
INSERT INTO ClassRooms VALUES(32,'Classroom 22',35,3);
INSERT INTO ClassRooms VALUES(33,'MDA Lab',20,3);
CREATE TABLE DegreeBatches (BatchId NUMBER, BatchName VARCHAR2(50), Strength NUMBER);
INSERT INTO DegreeBatches VALUES(1,'BIT-11',79);
INSERT INTO DegreeBatches VALUES(2,'BIT-12',28);
INSERT INTO DegreeBatches VALUES(3,'BS(CS)-1',35);
INSERT INTO DegreeBatches VALUES(4,'BS(CS)-2',78);
INSERT INTO DegreeBatches VALUES(5,'BE(SE)-1',69);
INSERT INTO DegreeBatches VALUES(6,'BE(SE)-2',84);
INSERT INTO DegreeBatches VALUES(7,'BE(SE)-3',64);
INSERT INTO DegreeBatches VALUES(8,'BICSE-7',84);
INSERT INTO DegreeBatches VALUES(9,'BICSE-8',43);
INSERT INTO DegreeBatches VALUES(10,'BEE-1',112);
INSERT INTO DegreeBatches VALUES(11,'BEE-2',151);
INSERT INTO DegreeBatches VALUES(12,'BEE-3',157);
INSERT INTO DegreeBatches VALUES(13,'BEE-4',157);
Best Regards
Bilal
Edited by: Bilal on 27-Dec-2012 09:52
Edited by: Bilal on 27-Dec-2012 10:07Bilal, thanks for the nice problem! Another possibility for duplicate checking is to write a small PL/SQL function returning 1 if a duplicate id is found, then equate it to 0: 'Duplicate_Token_Found (p_str_main VARCHAR2, p_str_trial VARCHAR2) RETURN NUMBER'. This would parse the second string and might use p_str_main LIKE '%,' || l_id || ',%' for each id. Anyway the full query (without that) is given below:
Solution with names
SQL> WITH rsf_itm (con_id, max_weight, nxt_id, lev, tot_weight, tot_profit, path, root_id, lev_1_id) AS (
2 SELECT c.id,
3 c.max_weight,
4 i.id,
5 0,
6 i.item_weight,
7 i.item_profit,
8 ',' || i.id || ',',
9 i.id,
10 0
11 FROM items i
12 CROSS JOIN containers c
13 UNION ALL
14 SELECT r.con_id,
15 r.max_weight,
16 i.id,
17 r.lev + 1,
18 r.tot_weight + i.item_weight,
19 r.tot_profit + i.item_profit,
20 r.path || i.id || ',',
21 r.root_id,
22 CASE WHEN r.lev = 0 THEN i.id ELSE r.nxt_id END
23 FROM rsf_itm r
24 JOIN items i
25 ON i.id > r.nxt_id
26 AND r.tot_weight + i.item_weight <= r.max_weight
27 ORDER BY 1, 2
28 ) SEARCH DEPTH FIRST BY nxt_id SET line_no
29 , rsf_con (nxt_con_id, nxt_line_no, con_path, itm_path, tot_weight, tot_profit, lev) AS (
30 SELECT con_id,
31 line_no,
32 To_Char(con_id),
33 ':' || con_id || '-' || (lev + 1) || ':' || path,
34 tot_weight,
35 tot_profit,
36 0
37 FROM rsf_itm
38 UNION ALL
39 SELECT r_i.con_id,
40 r_i.line_no,
41 r_c.con_path || ',' || r_i.con_id,
42 r_c.itm_path || ':' || r_i.con_id || '-' || (r_i.lev + 1) || ':' || r_i.path,
43 r_c.tot_weight + r_i.tot_weight,
44 r_c.tot_profit + r_i.tot_profit,
45 r_c.lev + 1
46 FROM rsf_con r_c
47 JOIN rsf_itm r_i
48 ON r_i.con_id > r_c.nxt_con_id
49 WHERE r_c.itm_path NOT LIKE '%,' || r_i.root_id || ',%'
50 AND r_c.itm_path NOT LIKE '%,' || r_i.lev_1_id || ',%'
51 AND r_c.itm_path NOT LIKE '%,' || r_i.nxt_id || ',%'
52 )
53 , paths_ranked AS (
54 SELECT itm_path || ':' itm_path, tot_weight, tot_profit, lev + 1 n_cons,
55 Rank () OVER (ORDER BY tot_profit DESC) rnk,
56 Row_Number () OVER (ORDER BY tot_profit DESC) sol_id
57 FROM rsf_con
58 ), best_paths AS (
59 SELECT itm_path, tot_weight, tot_profit, n_cons, sol_id
60 FROM paths_ranked
61 WHERE rnk = 1
62 ), row_gen AS (
63 SELECT LEVEL lev
64 FROM DUAL
65 CONNECT BY LEVEL <= (SELECT Count(*) FROM items)
66 ), con_v AS (
67 SELECT b.itm_path, r.lev con_ind, b.sol_id, b.tot_weight, b.tot_profit,
68 Substr (b.itm_path, Instr (b.itm_path, ':', 1, 2*r.lev - 1) + 1,
69 Instr (b.itm_path, ':', 1, 2*r.lev) - Instr (b.itm_path, ':', 1, 2*r.lev - 1) - 1)
70 con_nit_id,
71 Substr (b.itm_path, Instr (b.itm_path, ':', 1, 2*r.lev) + 1,
72 Instr (b.itm_path, ':', 1, 2*r.lev + 1) - Instr (b.itm_path, ':', 1, 2*r.lev) - 1)
73 itm_str
74 FROM best_paths b
75 JOIN row_gen r
76 ON r.lev <= b.n_cons
77 ), con_split AS (
78 SELECT itm_path, con_ind, sol_id, tot_weight, tot_profit,
79 Substr (con_nit_id, 1, Instr (con_nit_id, '-', 1) - 1) con_id,
80 Substr (con_nit_id, Instr (con_nit_id, '-', 1) + 1) n_items,
81 itm_str
82 FROM con_v
83 ), itm_v AS (
84 SELECT c.itm_path, c.con_ind, c.sol_id, c.con_id, c.tot_weight, c.tot_profit,
85 Substr (c.itm_str, Instr (c.itm_str, ',', 1, r.lev) + 1,
86 Instr (c.itm_str, ',', 1, r.lev + 1) - Instr (c.itm_str, ',', 1, r.lev) - 1)
87 itm_id
88 FROM con_split c
89 JOIN row_gen r
90 ON r.lev <= c.n_items
91 )
92 SELECT v.sol_id,
93 v.tot_weight s_wt, v.tot_profit s_pr, c.id c_id, c.name c_name, c.max_weight m_wt,
94 Sum (i.item_weight) OVER (PARTITION BY v.sol_id, c.id) c_wt,
95 i.id i_id, i.name i_name, i.item_weight i_wt, i.item_profit i_pr
96 FROM itm_v v
97 JOIN containers c
98 ON c.id = To_Number (v.con_id)
99 JOIN items i
100 ON i.id = To_Number (v.itm_id)
101 ORDER BY sol_id, con_id, itm_id
102 /
SOL_ID S_WT S_PR C_ID C_NAME M_WT C_WT I_ID I_NAME I_WT I_PR
1 255 255 1 SEECS UG Block 100 100 1 BIT-10 35 35
2 BIT-11 40 40
6 BICSE-7 25 25
2 IAEC Building 70 70 4 BSCS-3 40 40
7 BESE-3 30 30
3 RIMMS Building 90 85 3 BSCS-2 35 35
5 BEE-4 50 50
2 255 255 1 SEECS UG Block 100 95 4 BSCS-3 40 40
6 BICSE-7 25 25
7 BESE-3 30 30
2 IAEC Building 70 70 1 BIT-10 35 35
3 BSCS-2 35 35
3 RIMMS Building 90 90 2 BIT-11 40 40
5 BEE-4 50 50
3 255 255 1 SEECS UG Block 100 100 3 BSCS-2 35 35
4 BSCS-3 40 40
6 BICSE-7 25 25
2 IAEC Building 70 65 1 BIT-10 35 35
7 BESE-3 30 30
3 RIMMS Building 90 90 2 BIT-11 40 40
5 BEE-4 50 50
4 255 255 1 SEECS UG Block 100 100 3 BSCS-2 35 35
4 BSCS-3 40 40
6 BICSE-7 25 25
2 IAEC Building 70 70 2 BIT-11 40 40
7 BESE-3 30 30
3 RIMMS Building 90 85 1 BIT-10 35 35
5 BEE-4 50 50
5 255 255 1 SEECS UG Block 100 95 2 BIT-11 40 40
6 BICSE-7 25 25
7 BESE-3 30 30
2 IAEC Building 70 70 1 BIT-10 35 35
3 BSCS-2 35 35
3 RIMMS Building 90 90 4 BSCS-3 40 40
5 BEE-4 50 50
6 255 255 1 SEECS UG Block 100 100 2 BIT-11 40 40
3 BSCS-2 35 35
6 BICSE-7 25 25
2 IAEC Building 70 65 1 BIT-10 35 35
7 BESE-3 30 30
3 RIMMS Building 90 90 4 BSCS-3 40 40
5 BEE-4 50 50
7 255 255 1 SEECS UG Block 100 100 2 BIT-11 40 40
3 BSCS-2 35 35
6 BICSE-7 25 25
2 IAEC Building 70 70 4 BSCS-3 40 40
7 BESE-3 30 30
3 RIMMS Building 90 85 1 BIT-10 35 35
5 BEE-4 50 50
8 255 255 1 SEECS UG Block 100 100 1 BIT-10 35 35
4 BSCS-3 40 40
6 BICSE-7 25 25
2 IAEC Building 70 70 2 BIT-11 40 40
7 BESE-3 30 30
3 RIMMS Building 90 85 3 BSCS-2 35 35
5 BEE-4 50 50
9 255 255 1 SEECS UG Block 100 100 1 BIT-10 35 35
4 BSCS-3 40 40
6 BICSE-7 25 25
2 IAEC Building 70 65 3 BSCS-2 35 35
7 BESE-3 30 30
3 RIMMS Building 90 90 2 BIT-11 40 40
5 BEE-4 50 50
10 255 255 1 SEECS UG Block 100 100 1 BIT-10 35 35
3 BSCS-2 35 35
7 BESE-3 30 30
2 IAEC Building 70 65 2 BIT-11 40 40
6 BICSE-7 25 25
3 RIMMS Building 90 90 4 BSCS-3 40 40
5 BEE-4 50 50
11 255 255 1 SEECS UG Block 100 100 1 BIT-10 35 35
3 BSCS-2 35 35
7 BESE-3 30 30
2 IAEC Building 70 65 4 BSCS-3 40 40
6 BICSE-7 25 25
3 RIMMS Building 90 90 2 BIT-11 40 40
5 BEE-4 50 50
12 255 255 1 SEECS UG Block 100 95 1 BIT-10 35 35
3 BSCS-2 35 35
6 BICSE-7 25 25
2 IAEC Building 70 70 2 BIT-11 40 40
7 BESE-3 30 30
3 RIMMS Building 90 90 4 BSCS-3 40 40
5 BEE-4 50 50
13 255 255 1 SEECS UG Block 100 95 1 BIT-10 35 35
3 BSCS-2 35 35
6 BICSE-7 25 25
2 IAEC Building 70 70 4 BSCS-3 40 40
7 BESE-3 30 30
3 RIMMS Building 90 90 2 BIT-11 40 40
5 BEE-4 50 50
14 255 255 1 SEECS UG Block 100 100 1 BIT-10 35 35
2 BIT-11 40 40
6 BICSE-7 25 25
2 IAEC Building 70 65 3 BSCS-2 35 35
7 BESE-3 30 30
3 RIMMS Building 90 90 4 BSCS-3 40 40
5 BEE-4 50 50
98 rows selected.
Elapsed: 00:00:01.42Edited by: BrendanP on 20-Jan-2013 11:25
I found the regex needed to deduplicate:
AND RegExp_Instr (r_c.itm_path || r_i.path, ',(\d+),.*?,\1,') = 0 -
Need help in SQL Query: Update a row in a table & insert the same row into another table
I want to update a row in a table say Table A and the updated row should be inserted into another table say Table B. I need to do it in a single SQL query and i don't want to do it in PL/SQL with triggers. And i tried with MERGE statement but its working with this scenario. (Note: I'm using Oracle Database 10g Enterprise Edition Release 10.2.0.1.0).
Thanks in Advance.Using Sven's code as an example, you could save the updated row in a sql plus variable. (also untested):
SQL> var v_id number
update tableA
set colB='ABC'
where colC='XYZ'
returning id into :v_id;
insert into table A_History (ID, colA, colB, ColC)
select id, ColA, ColB, ColC
from tableA
where id = :v_id; -
Dynamic SQL Query to Find Special Characters in Table columns
Hi,
I am new to OTN FORUMS.
I am trying to find the columnsi of a table which have special characters in them.
I am planning on using this query
select ' select INSTR('||column_name||', chr(0))
from '||table_name||'where INSTR('||column_name||', chr(0)) >0' from user_tab_columns
where table_name='Account'
and spool the output to run as a script.
Is this the right way or do u suggest any modifications to the query?
Thanks in advance.Hi,
I think your basic approach is right. Since you can't hard-code the table- or column names into the query, you'll need dynamic SQL.
Instead SQL-from-SQL (that is, writing a pure SQL query, whose output is SQL code), you could do the whole job in PL/SQL, but I don't see any huge advantage either way.
When you say "Special character<b>s</b>", do you really mean "one given special character" (in this case, CHR(0))?
Will you ever want to search for multiple special characters at once?
What if table foo has a column bar, and in 1000 rows of foo, bar contains CHR (0). Do you want 1000 rows of output, each showing the exact position of the first CHR(0)? If the purpose is to look at theese rows later, shouldn't you include the primary key in the output? What if CHR(0) occurs 2 or more times in the same string?
If you'd rather have one row of output, that simply says that the column foo.bar sometimes contains a CHR(0), then you could do something like this:
SELECT 'foo', 'bar'
FROM dual
WHERE EXISTS (
SELECT NULL
FROM foo
WHERE INSTR ( bar
, CHR (0)
) > 0
); -
SQL Query constructing for searching values in Tables single Column
I have Table USER_SERVICES with 2 Columns USER_NAME, Services. Please find below sample data on USER_SERVICES Table.
A user can be assigned with multiple services(service1, service2 etc.,). So we store data as below :
USER_NAME Services
user1 service1
user1 service2
user1 service3
user2 service1
user2 service2
user3 service3
user4 service4
I need to frame a SQL Query to 'select users assigned with Service A and Service B and Service n'.
Note: 'And' condition is used when Searching for multiple services.
Example: The SQL Query has to dynamically handle condition if i give Single Service, multiple Services(service1 and service2 e.t.c,)
If i say select users assigned with service1 and service2, from the above Table, result should be user1 and user2
If i say select users assigned with service1 and service2 and service3, from the above Table, result should be user1
If i say select users assigned with service4 from the above table, result should be user4
If i say select users assigned with service1 from the above table, result should be user2,user1
If i say select users assigned with service1 and service2 from the above table, result should be user2,user1
How do i construct the SQL Query. Any help will be appreciated.
Thanks,
Sathish
Alternate email: [email protected]How it will be stored? In a string or a table or a collection type?
If you have it in a table you can do like this.
with t
as
select 'user1' user_name, 'service1' services from dual union all
select 'user1', 'service2' from dual union all
select 'user1', 'service3' from dual union all
select 'user2', 'service1' from dual union all
select 'user2', 'service2' from dual union all
select 'user3', 'service3' from dual union all
select 'user4', 'service4' from dual
t1 as
select 'service1' services from dual union all
select 'service2' from dual
select distinct user_name
from (
select t.user_name, t.services, t1.services, count(t1.services) over(partition by t.user_name) cnt, t1.cnt cnt_1
from t
left join (select t1.*, count(*) over() cnt from t1) t1 on t1.services = t.services
where cnt = cnt_1 -
How to write sql query for counting pairs from below table??
Below is my SQL table structure.
user_id | Name | join_side | left_leg | right_leg | Parent_id
100001 Tinku Left 100002 100003 0
100002 Harish Left 100004 100005 100001
100003 Gorav Right 100006 100007 100001
100004 Prince Left 100008 NULL 100002
100005 Ajay Right NULL NULL 100002
100006 Simran Left NULL NULL 100003
100007 Raman Right NULL NULL 100003
100008 Vijay Left NULL NULL 100004
It is a binary table structure.. Every user has to add two per id under him, one is left_leg and second is right_leg... Parent_id is under which user current user is added.. Hope you will be understand..
I have to write sql query for counting pairs under id "100001". i know there will be important role of parent_id for counting pairs. * what is pair( suppose if any user contains both left_leg and right_leg id, then it is called pair.)
I know there are three pairs under id "100001" :-
1. 100002 and 100003
2. 100004 and 100005
3. 100006 and 100007
100008 will not be counted as pair because it does not have right leg..
But i dont know how to write sql query for this... Any help will be appreciated... This is my college project... And tommorow is the last date of submission.... Hope anyone will help me...
Suppose i have to count pair for id '100002'. Then there is only one pair under id '100002'. i.e 100004 and 100005Sounds like this to me
DECLARE @ID int
SET @ID = 100001--your passed value
SELECT left_leg,right_leg
FROM table
WHERE (user_id = @ID
OR parent_id = @ID)
AND left_leg IS NOT NULL
AND right_leg IS NOT NULL
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs -
Inserting field text into sql query and comparing values to another table
I have an issue in Visual Web Developer 2010 that I need help with.
The code below is a Gridview Sql query where I'm extracting PART_NUMBER from various tables. I would like to add the table name in a separate field named Table. The end result should appear as follows:
PART_NUMBER Table
010-0075-06 Resistors (or Capacitors, etc.)
Sql query:
SELECT PART_NUMBER
FROM Capacitors
EXCEPT
SELECT PART_NUMBER
FROM [CIS Manufacturer Parts]
UNION
SELECT PART_NUMBER
FROM Connectors
EXCEPT
SELECT PART_NUMBER
FROM [CIS Manufacturer Parts]
UNION
SELECT PART_NUMBER
FROM Diodes
EXCEPT
SELECT PART_NUMBER
FROM [CIS Manufacturer Parts]
UNION
SELECT PART_NUMBER
FROM ICs
EXCEPT
SELECT PART_NUMBER
FROM [CIS Manufacturer Parts]
UNION
SELECT PART_NUMBER
FROM Inductors
EXCEPT
SELECT PART_NUMBER
FROM [CIS Manufacturer Parts]
UNION
SELECT PART_NUMBER
FROM Misc
EXCEPT
SELECT PART_NUMBER
FROM [CIS Manufacturer Parts]
UNION
SELECT PART_NUMBER
FROM Relays
EXCEPT
SELECT PART_NUMBER
FROM [CIS Manufacturer Parts]
UNION
SELECT PART_NUMBER
FROM Resistors
EXCEPT
SELECT PART_NUMBER
FROM [CIS Manufacturer Parts]
UNION
SELECT PART_NUMBER
FROM Switches
EXCEPT
SELECT PART_NUMBER
FROM [CIS Manufacturer Parts]
UNION
SELECT PART_NUMBER
FROM Transformers
EXCEPT
SELECT PART_NUMBER
FROM [CIS Manufacturer Parts]
UNION
SELECT PART_NUMBER
FROM Transistors
EXCEPT
SELECT PART_NUMBER
FROM [CIS Manufacturer Parts]
UNION
SELECT PART_NUMBER
FROM [Crystals and Oscillators]
EXCEPT
SELECT PART_NUMBER
FROM [CIS Manufacturer Parts]
ORDER BY PART_NUMBER
I have a separate table (CIS Manufacturer Parts) that contains manufacturer data for the above parts. Multiple manufacturer rows can exist. The connection between tables in the PART_NUMBER field. What I would like to do is make this query
add the table name to the gridview output listing only parts without manufacturer data and the table they can be found in.
This is a lot for a newbie so I will appreciate any help, thanks!Hello Bulldog248,
Thank you for your post.
Your issue is out of support range of VS General Question forum which mainly discusses the usage issue of Visual Studio IDE such as
WPF & SL designer, Visual Studio Guidance Automation Toolkit, Developer Documentation and Help System
and Visual Studio Editor.
I am moving your question to the moderator forum ("Where is the forum for..?"). The owner of the forum will direct you to a right forum.
Best regards,
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey. -
SQL Query of VO joining to 2 tables assigining to one EO
R12.0.6
Hello,
there is a VO which has a SQL joining 2 Tables. This is being used for a Query Bean (Search Page)
This VO i want to assign an EO to modifiy Values in DB (Update Icon in every Row).
Does this make sense? ( If doing the transaction will not be done in DB: In Console window i get the Warning "EntityCache:add WARNING - ignoring row")
Or is it better to leave the Search VO and create another one which has direct mapping the EO.
Any Suggestion on that?`
Which would be the best preactise?
Thank You in advice!Hi Again,
Hopefully the Part 1 of your problem is solved. If so please do close that thread.
SELECT &P_COLUMN_1 COLUMN_1,
&P_COLUMN_2 COLUMN_2,
&P_COLUMN_3 COLUMN_3,
&P_COLUMN_4 COLUMN_4
FROM &table_name
Note you need to create the User parameters before creating the Query and also all the parameter for column and table name should have valid default value.
Please do close your threads and also give the points if you get a solution.
Best Regards
Arif Khadas -
Date Validation-SQL Query or Mapping
Dear Friends,
I'm using sender JDBC adapter and fetching data.
Let say the table structure is Name,ID,Datetime.
I want to select the query and the resultset must be in the following fomat
I want to check the validation that if Datetime value is 2 weeks greater than current date return YES, else return NO
Is the above condition possible while selecting from the database itself?
If we can't achieve it using query, then I've to go for Mapping. Can you guys tell me the logic to implement the same.
<Rows>
<Name>J</Name>
<ID>126376</ID>
<DateTime>YES</DateTime>
</Rows>
<Rows>
<Name>P</Name>
<ID>126372</ID>
<DateTime>YES</DateTime>
</Rows>
<Rows>
<Name>S</Name>
<ID>126334</ID>
<DateTime>NO</DateTime>
</Rows>
If the above requirement is not clear, please let me know.
Thanks for all of your valuable time!!!
Best regards,
raj.Satish & Matias,
Thanks a lot for ur valuable time and help.
@Matias I tried to query with the SQL , but I failed since its throwing exception always.
@Satish: I wrote UDF and achieved the same.
<b>Code:</b>
//Sample input date: 2005-06-16 14:33:21.0
int year=Integer.parseInt(time.substring(0,4));
int month=Integer.parseInt(time.substring(5,7))-1 ;
int date=Integer.parseInt(time.substring(8,10));
int hour=Integer.parseInt(time.substring(11,13));
int min=Integer.parseInt(time.substring(14,16));
int sec=Integer.parseInt(time.substring(17,19));
Calendar c1 = Calendar.getInstance();
Calendar c2 = Calendar.getInstance();
c1.set(year,month,date,hour,min,sec);
c1.add(Calendar.DAY_OF_MONTH,14);
if(c2.before(c1))
return "NO";
else
return "YES";
Thanks friends!!!
Best regards,
raj. -
Sql query with multiple joins to same table
I have to write a query for a client to display business officers' names and title along with the business name
The table looks like this
AcctNumber
OfficerTitle
OfficerName
RecKey
90% of the businesses have exactly 4 officer records, although some have less and some have more.
There is a separate table that has the AcctNumber, BusinessName about 30 other fields that I don’t need
An individual account can have 30 or 40 records on the other table.
The client wants to display 1 record per account.
Initially I wrote a query to join the table to itself:
Select A.OfficerTtitle, A.OfficerName, B.OfficerTitle, B.OfficerName, C.OfficerTtitle, C.OfficerName, D.OfficerTitle, D.OfficerName where A.AcctNumber = B.AcctNumber and A.AcctNumber = C.AcctNumber and A.AcctNumber = D.AcctNumber
This returned tons of duplicate rows for each account ( number of records * number of records, I think)
So added
And A.RecKey > B.RecKey and B.RecKey > C. RecKey and C.RecKey . D.RecKey
This works when there are exactly 4 records per account. If there are less than 4 records on the account it skips the account and if there are more than 4 records, it returns multiple rows.
But when I try to l join this to the other table to get the business name, I get a row for every record on the other table
I tried select distinct on the other table and the query runs for ever and never returns anything
I tried outer joins and subqueries, but no luck so far. I was thinking maybe a subquery - if exists - because I don't know how many records there are on an account, but don't know how to structure that
Any suggestions would be appreciatedWelcome to the forum!
user13319842 wrote:
I have to write a query for a client to display business officers' names and title along with the business name
The table looks like this
AcctNumber
OfficerTitle
OfficerName
RecKey
90% of the businesses have exactly 4 officer records, although some have less and some have more.
There is a separate table that has the AcctNumber, BusinessName about 30 other fields that I don’t need
An individual account can have 30 or 40 records on the other table.
The client wants to display 1 record per account.As someone has already mentioned, you should post CREATE TABLE and INSERT statements for both tables (relevant columns only). You don't have to post a lot of sample data. For example, you need to pick 1 out of 30 or 40 rows (max) for the same account, but it's almost certainly enough if you post only 3 or 4 rows (max) for an account.
Also, post the results you want from the sample data that you post, and explain how you get those resutls from that data.
Always say which version of Oracle you're using. This sounds like a PIVOT problem, and a new SELECT .... PIVOT feature was introduced in Oracle 11.1. If you're using Oracle 11, you don't want to have to learn the old way to do pivots. On the other hand, if you have Oracle 10, a solution that uses a new feature that you don't have won't help you.
Whenever you have a question, please post CREATE TABLE and INSERT statements for some sample data, the results you want from that data, an explanation, and your Oracle version.
Initially I wrote a query to join the table to itself:
Select A.OfficerTtitle, A.OfficerName, B.OfficerTitle, B.OfficerName, C.OfficerTtitle, C.OfficerName, D.OfficerTitle, D.OfficerName where A.AcctNumber = B.AcctNumber and A.AcctNumber = C.AcctNumber and A.AcctNumber = D.AcctNumber Be careful, and post the exact code that you're running. The statement above can't be what you ran, because it doesn't have a FROM clause.
This returned tons of duplicate rows for each account ( number of records * number of records, I think)
So added
And A.RecKey > B.RecKey and B.RecKey > C. RecKey and C.RecKey . D.RecKey
This works when there are exactly 4 records per account. If there are less than 4 records on the account it skips the account and if there are more than 4 records, it returns multiple rows.
But when I try to l join this to the other table to get the business name, I get a row for every record on the other table
I tried select distinct on the other table and the query runs for ever and never returns anything
I tried outer joins and subqueries, but no luck so far. I was thinking maybe a subquery - if exists - because I don't know how many records there are on an account, but don't know how to structure that
Any suggestions would be appreciatedDisplaying 1 column from n rows as n columns on 1 row is called Pivoting . See the following link fro several ways to do pivots:
SQL and PL/SQL FAQ
Pivoting requires that you know exactly how many columns will be in the result set. If that number depends on the data in the table, then you might prefer to use String Aggregation , where the output consists of a huge string column, that contains the concatenation of the data from n rows. This big string can be formatted so that it looks like multiple columns. For different string aggregation techniques, see:
http://www.oracle-base.com/articles/10g/StringAggregationTechniques.php
The following thread discusses some options for pivoting a variable number of columns:
Re: Report count and sum from many rows into many columns -
SQL query very slow on Data warehouse
Guys,
Is there any soul who is an expert on SQL ? I do run this query agaist a 2 table and a view which has 30 million rows. Unfortunately the table is partitioned but not the Unique index.
This query takes about 3 hours to run. Is there anyway of writing this in a better way ??
select
a.xcm_consumer_pk,
b.p_vin_prtn_c,
b.vin_type_c,
b.vin_id_c,
b.cveh_owner_cycle_r,
b.veh_reg_no_c,
b.veh_make_c,
b.veh_model_c,
b.veh_deriv_c,
b.veh_reg_y,
b.cveh_link_start_y,
b.cveh_prd_rpl_y,
b.cveh_sl_dlr_c,
c.cu26_address_x
from
xcm_cu01_customer a, xcm_cv01_cons_veh b,
xcm_view_cons_latest_e_mail c
where
a.country_iso3_c = 'GBR'
and (a.cust_brand_c in ('F','Y'))
and a.xcm_consumer_pk = b.xcm_consumer_pk(+)
and b.cveh_owner_cycle_r(+) = 1
and b.cveh_link_end_y(+) between SYSDATE and '31-Dec-9999'
and a.xcm_consumer_pk = c.xcm_consumer_pk(+)
The definition of the view xcm_view_cons_latest_e_mail is as below.
SELECT
A.xcm_consumer_pk,
A.cu26_type_c,
A.p_update_s,
A.cu26_address_x
FROM XCM_CU26_E_MAIL A
WHERE TO_CHAR(NVL(A.p_update_s, '01-Jan-0001'), 'YYYYMMDD') || NVL(A.cu26_type_c, ' ') =
(SELECT MAX(TO_CHAR(NVL(b.p_update_s, '01-Jan-0001'), 'YYYYMMDD') || NVL(b.cu26_type_c, ' '))
FROM XCM_CU26_E_MAIL b
WHERE A.xcm_consumer_pk = b.xcm_consumer_pk);
Most of our query uses the same format and ver 9.2.0.2 has totally screwed up our job times.. Any idea please ??In addition to Maurice's questions:
Are you sure you really need the outer joins?
From your statement "... and ver 9.2.0.2 has totally screwed up our job times" I assume that you have recently upgraded. So:
Are you sure that all relevant indexes exist on the new version?
Have you analyzed all the tables involved since the upgrade?
Are you sure that the init parameters are set appropriately? Note that depending on what version you upgraded from, you may need to make substantial changes to various parameters to get optimal performance.
John -
SQL Query : Order By issue with HUGE Table
Hello friends,
I have been through a terrible issue with order by. I would appreciate your help. Please let me know, your input for my case:
=> if i run select query it returns result quick in some milliseconds. (sql dev. fetches 50 rows at a time)
=> if i run select query with where condition and column (say A) in where condition is even indexed and i have order by and that order by column (say B) is also indexed.
Now, here is the issue:
1. if no. of rows with that where condition can filter yielding small result set then order by works fine .. 1-5 sec which is good.
2.*if no. of rows with that where condition can filter yielding Large result set, say more than 50,000 then with order by then the wait time is exponential.... i have even waited 10+ mins to get the result back for 120,000 records.*
Is order by takes that long for 100K records ... i think something else if wrong... your pointer will really be helpful... i am very new to sql and even newer for large table case.
I am using SQL Developer Version 2.1.1.64
and Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
Thank you so much.
Edited by: 896719 on Jan 11, 2013 8:38 AMYes you are correct, but my concentration was on order by thing, so it will do full scan of table so i was putting that ... and was also wondering if millions of record in table should not be a issue...???
Any way for the explain plan , when just a value in the where changes there is the huge difference i want to point out too as below:
SELECT
FROM
EES_EVT EES_EVT where APLC_EVT_CD= 'ABC' ORDER BY CRE_DTTM DESC
execution time : 0.047 sec
Plan hash value: 290548126
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 27 | 14688 | 25 (4)| 00:00:01 |
| 1 | SORT ORDER BY | | 27 | 14688 | 25 (4)| 00:00:01 |
| 2 | TABLE ACCESS BY INDEX ROWID| EES_EVT | 27 | 14688 | 24 (0)| 00:00:01 |
|* 3 | INDEX RANGE SCAN | XIE1EES_EVT | 27 | | 4 (0)| 00:00:01 |
Predicate Information (identified by operation id):
3 - access("APLC_EVT_CD"='ABC')
Note
- SQL plan baseline "SYS_SQL_PLAN_6d41e6b91925c463" used for this statement
=============================================================================================
SELECT
FROM
EES_EVT EES_EVT where APLC_EVT_CD= 'XYZ' ORDER BY CRE_DTTM DESC
execution : 898.672 sec.
Plan hash value: 290548126
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 121K| 62M| | 102K (1)| 00:11:02 |
| 1 | SORT ORDER BY | | 121K| 62M| 72M| 102K (1)| 00:11:02 |
| 2 | TABLE ACCESS BY INDEX ROWID| EES_EVT | 121K| 62M| | 88028 (1)| 00:09:27 |
|* 3 | INDEX RANGE SCAN | XIE1EES_EVT | 121K| | | 689 (1)| 00:00:05 |
Predicate Information (identified by operation id):
3 - access("APLC_EVT_CD"='XYZ')
Note
- SQL plan baseline "SYS_SQL_PLAN_ef5709641925c463" used for this statementAlso Note this table contains 74328 MB data in it.
Thanks -
SQL Query to get match string from table
Hi Experts,
BANNER
Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - Production
PL/SQL Release 11.1.0.7.0 - Production
CORE 11.1.0.7.0 Production
TNS for 32-bit Windows: Version 11.1.0.7.0 - Production
NLSRTL Version 11.1.0.7.0 - Production
5 rows selected.
WITH T AS
SELECT 'JOHN' FIRSTNAME,'PLAYER' LASTNAME FROM DUAL UNION ALL
SELECT 'MICHEAL','SMITH' LASTNAME FROM DUAL UNION ALL
SELECT 'SCOTT','MANAGER' LASTNAME FROM DUAL UNION ALL
SELECT 'FIRST NAME','LAST NAME' LASTNAME FROM DUAL
)SELECT * FROM T;
Input String to my Query will be "JOHN NAME SMITH"
I need to match the input string to provide result based on Firstname OR Lastname from table.
How can i acheive this?
Thanks,what the problem in constructing??
you can use something like this....
declare
vStrng varchar2(100) := 'JOHN NAME SMITH';
v_temp varchar2(1000):= 'SELECT DISTINCT firstname,lastname FROM employees,
(SELECT regexp_substr('''||vStrng||''',''[[:alpha:]]+'',1,level) parsedstr
FROM dual
CONNECT BY level<=LENGTH(regexp_replace('''||vStrng||''',''[[:alpha:]]'',''''))+1
) WHERE instr(firstname,parsedstr)>0 OR instr(lastname,parsedstr) >0';
vSQL varchar2(1000):= 'SELECT ENAME,EMPNO,DEPT.DEPTNO FROM EMP,DEPT WHERE EMP.DEPTNO=DEPT.DEPTNO AND (firstname,lastname) in ('||v_temp||')';
begin
--rest of your code....
end;edit: In the same way...you can use any of the above mentioned solutions..
Ravi Kumar
Edited by: ravikumar.sv on Apr 6, 2010 4:12 PM -
hi ,
can any one tell how to convert this query into owb mapping
INSERT INTO SMSTG.CST_PROF_ADDRESS
(IMS_ID,
PROF_ADDRESS_ID
ADDRESS_LINE_1,
CITY,
STATE_CODE,
POSTAL_CODE,
COUNTRY_CODE,
SOURCE_PROF_ID,
SOURCE_ADDRESS_ID,
ADDRESS_SOURCE,
ADDRESS_SOURCE_DATE,
INACTIVE_DATE,
INACTIVE_SOURCE,
INACTIVE_PROF_ID,
INACTIVE_ADDRESS_ID,
LOAD_DATE)
SELECT
B.REF_PROF_X,
B.REF_PROF_X||'|'||SUBSTR(A.ADDRESS_LINE_1,1,5)||'|'||SUBSTR(A.POSTAL_CODE,1,5) PROF_ADDRESS_ID,
A.ADDRESS_LINE_1,
A.CITY,
A.STATE_CODE,
A.POSTAL_CODE,
A.COUNTRY_CODE,
A.SFA_PROF_ID,
A.SFA_ADDRESS_ID,
A.ADDRESS_SOURCE,
A.ADDRESS_SOURCE_DATE,
NULL INACTIVE_DATE,
NULL INACTIVE_SOURCE,
NULL INACTIVE_PROF_ID,
NULL INACTIVE_ADDRESS_ID,
SYSDATE LOAD_DATE
FROM SMSTG.CST_PROF_SFA A
WHSUSR.MDT_SFA_PROF B
WHERE B.SFA_PROF_ADDRESS_ID = A.SFA_PROF_ADDRESS_ID
AND B.PUBLICATION_STATUS = 'C' AND B.END_DATE > SYSDATE
(SELECT ''
FROM WHSUSR.MDT_MASTER_PROF_ADDRESS D
WHERE D.PROF_ADDRESS_ID = B.REF_PROF_X||'|'||SUBSTR(A.ADDRESS_LINE_1,1,5)||'|'||SUBSTR(A.POSTAL_CODE,1,5)
AND D.ADDRESS_SOURCE_DATE =< A.ADDRESS_SOURCE_DATE
AND D.PUBLICATION_STATUS = 'C' AND D.END_DATE > SYSDATE)
OR NOT EXISTS
(SELECT ''
FROM WHSUSR.MDT_MASTER_PROF_ADDRESS E
WHERE E.PROF_ADDRESS_ID = B.REF_PROF_X||'|'||SUBSTR(A.ADDRESS_LINE_1,1,5)||'|'||SUBSTR(A.POSTAL_CODE,1,5)
AND E.PUBLICATION_STATUS = 'C' AND E.END_DATE > SYSDATE))
AND ( EXISTS
(SELECT ''
FROM SMSTG.CST_PROF_HCPS_ADDRESS F
WHERE F.PROF_ADDRESS_ID = B.REF_PROF_X||'|'||SUBSTR(A.ADDRESS_LINE_1,1,5)||'|'||SUBSTR(A.POSTAL_CODE,1,5)
AND F.ADDRESS_SOURCE_DATE =< A.ADDRESS_SOURCE_DATE)
OR NOT EXISTS
(SELECT ''
FROM SMSTG.CST_PROF_HCPS_ADDRESS G
WHERE G.PROF_ADDRESS_ID = B.REF_PROF_X||'|'||SUBSTR(A.ADDRESS_LINE_1,1,5)||'|'||SUBSTR(A.POSTAL_CODE,1,5)))
AND (EXISTS
(SELECT ''
FROM SMSTG.CST_PROF_IMS_RETURN H
WHERE H.PROF_ADDRESS_ID = B.REF_PROF_X||'|'||SUBSTR(A.ADDRESS_LINE_1,1,5)||'|'||SUBSTR(A.POSTAL_CODE,1,5)
AND H.ADDRESS_SOURCE_DATE =< A.ADDRESS_SOURCE_DATE)
OR NOT EXISTS
(SELECT ''
FROM SMSTG.CST_PROF_IMS_RETURN I
WHERE PROF_ADDRESS_ID = B.REF_PROF_X||'|'||SUBSTR(A.ADDRESS_LINE_1,1,5)||'|'||SUBSTR(A.POSTAL_CODE,1,5))) ;Hi,
you can create mapping [use constant, expressions, join, filter, tables...], but not "convert this query into owb mapping".
Best regards.
IM -
Sql query to find dependencies for a table
Hi All,
I am having a table (REPT_ALL) with dependent objects on it ( child tables, indexes, constraints, views, synonyms, sequences , packages,procedures,functions,triggers).
I want the query to find out all the above dependencies for the above table(REP_ALL).
I m looking for the query to find dependencies inorder to find out the risks before dropping the above table(drop table REP_ALL cascade constraints)?
ThnxTo find foreign key constraints for a table you cannot use DBA_DEPENDENCIES but you have to use DBA_CONSTRAINTS.
Example Re: Find out foreign key column
Maybe you are looking for
-
How to make gmail the main post?
How to make gmail the main post?
-
Can I have my I tunes library on my iMac and my new MacBook Pro
I have just purchased a new MacBook pro retina display however my iTunes library is on my desktop IMac. Is its possible for me to see the same library on the 2 devices and if so how can I do this? Thanks
-
Hi, I'm unable to connect to VPN. The error I'm getting is - "The VPN server did not respond. Verify the server address and try reconnecting." I'm sure I am using the correct server address because I tried it on my non-mac laptop and worked fine.
-
Hi how can i set up AWT framework for Mobile applications in mobile device(Win 32).? I have tried to set up AWT framework using the help for Developer Studio's F&Q. but its not working.. After following that help, when i tried to logon to homepage i
-
The built in iSight camera on my MBA will not function. In PhotoBooth, the green light turns on, but a black screen appears and no photo images or video can be be recorded. The camera also does not work with Adobe Connect Pro webinar sofware. Any ins