Query to pick rows of matching columns of table B else table A
Hi All,
I have a urgent requirement which can be explained from below example.
Suppose I have two tables : A and B with same table schema as mentioned below:
A (Trading ID, Name, Phone Number, Mobile no, City)
B (Trading ID, Name, Phone Number, Mobile no, City)
Now I have to write a select query with the following conditions:
If the value of column "TradingID" in Table A exists in columns "TradingID" in table B then select the columns - (Name, Phone Number, Mobile no, City) from table B. Otherwise select the columns - (Name, Phone Number, Mobile no, City)
from table A.
I need a single select query with optimized solution.
Thanks in Advance.!!!
Please mark it as an answer/helpful if you find it as useful. Thanks, Satya Prakash Jugran
Please try this:
create table A (TradingID int, Name nvarchar(128), PhoneNumber int, Mobileno int, City nvarchar(128))
go
create table B (TradingID int, Name nvarchar(128), PhoneNumber int, Mobileno int, City nvarchar(128))
go
insert dbo.A (TradingID)
values ( 1 ), (2 )
insert dbo.B (TradingID, Name)
values ( 1, 'test01' ), ( 3, 'test02' )
go
with cte as
( select x.TradingID
from dbo.B as x
join dbo.A as y
on x.TradingID = y.TradingID )
select *
from B
where exists ( select *
from cte
where TradingID = B.TradingID )
union all
select *
from A
where exists ( select *
from cte
where TradingID <> A.TradingID )
Similar Messages
-
Displaying SQL Query results in rows instead of Columns
Hi,
I'm fairly new to Oracle so forgive me if this is a really stupid question.
I used Mysql for a while and if I wanted to display query results in rows instead of columns I could end the SQL command with '\G' instead of a semicolon.
This would give me output like...
Column_1: AAAA
Column_2: BBBB
Column_3: CCCC
Instead of the normal
Column_1 Column_2 Column_3
AAAAAA BBBBBBB CCCCCCC
Is there an equivalent in SQLPlus to the MySQL \G termination?
Thanks.
John> so forgive me if this is a really stupid question.
It is certainly not a stupid question, but pivoting is a very frequently asked and answered question:
[url http://forums.oracle.com/forums/search.jspa?threadID=&q=pivot&objID=f75&dateRange=all&userID=&numResults=15]http://forums.oracle.com/forums/search.jspa?threadID=&q=pivot&objID=f75&dateRange=all&userID=&numResults=15
In 11g you have special PIVOT and UNPIVOT functions.
Regards,
Rob. -
Query to get rows betwen x and y + table total row count
Hi,
I try get rows between e.g. 100 and 150 when I sort by some column
My query is now like this
SELECT *
FROM
(SELECT a.*,
row_number() OVER (ORDER BY OWNER ASC) rn,
COUNT(1) over() mrn
FROM (SELECT * FROM all_objects) a
WHERE ROWNUM BETWEEN least(100,mrn) AND 150It is not very fast if I run that kind select from big table
Any tips to optimize this query?
Regards,
JariHi,
I'm so bad with SQL :(
Here is sample where I need that kind query.
http://actionet.homelinux.net/htmldb/f?p=100:504
It looks standard Apex report but it is not.
It is just test to use query to output html using htp package
I send parameter start row, max rows, column I like order by.
Now I do query for cursor
/* Report query */
l_sql := '
SELECT * FROM(
SELECT a.*, row_number() OVER (ORDER BY '
|| l_sort_col
|| ' '
|| l_sort_ord
|| ') rn, COUNT(1) over() mrn
FROM(' || l_sql || ') a
) WHERE rn BETWEEN LEAST(' || l_start_row || ',mrn) AND ' || l_last_row
;Then I loop cursor and output html.
You can order report by click heading and there is that pagination
I did not know that I could find examples by "pagination query" =), thanks for that tip for both of you.
I know Apex have reports ,
but I need have features that Apex templates can not provide at least yet.
So I have study that generating html tables using custom package instead Apex report should be best approach to get layouts I need.
Regards,
Jari
Edited by: jarola on Jan 21, 2011 10:38 PM -
Highlight Rows and particular columns in table
Hi,
My requirement is that I should highlight n (can be any integer value) rows of a table and in each of these rows there are m (1,2,3 or 4 depending on the conditions) columns (All drop downs) that need to be highlighted.
What I did is as follows:
1. Made the table multi select and highlighted the rows by using
wdContext.nodeTable().setSelected(n,true);
This allowed me to highlight the row.
2. To highlight the column, I used :
wdContext.nodeTable().getTableElementAt(n).
setHdesign(WDTableCellDesign.GOODVALUE_MEDIUM);
This allows me to highlight the column .
The problem I am facing is that when both these lines of code are executed one after the other, the row is shown as selected but this selection overrides the color of the column. The column is then shown in the same color as the rest of the row.
Can someone suggest a way in which I can both highlight the row and also have the required column(s) of this row in an entirely different color.
i am using NWDS Version: 7.02.06
Thanks,
Himanshu
Edited by: Himanshu K on Aug 10, 2011 12:23 PMClosin as the requirement has changed
-
How to find a matching column in tables
Hello,
I have a need to find out a common column in all tables in database.
For e.g. There is a database column called machine_name
I need to know how many tables in database have this column name. Is there a straightforward way to achieve this without substantial coding?
This is on 9i EE
Thanks,
RTubby,
Since op asked for:
I have a need to find out a common column in all tables in database_*.it should be DBA_TAB_COLS. But what is more important, ALL_TAB_COLS holds not just table but also view and materialized view columns, so in general it should be:
select c.owner,
c.table_name
from dba_tab_cols c,
dba_objects o
where o.owner = c.owner
and o.object_name = c.table_name
and o.object_type = 'TABLE'
and c.column_name = 'MACHINE_NAME'
/SY. -
Select query for picking data in a dynamic internal table
Dear All,
Please help.
<u>The code is :</u>
p_table1 = itab_final-tabname1.
p_field1 = itab_final-fieldname1.
SELECT (p_field1) FROM (p_table1) INTO CORRESPONDING FIELDS OF TABLE <dyntable1>.
It is working fine when the domain is of CHAR
The piece of code is not working where domain is DATS, CURR, DEC, etc.
What shall I do so that it works for other domains also. Please its urgent......
<u>ERROR that came:</u>
An exception occurred. This exception will be dealt with in more detail
below. The exception, assigned to the class 'CX_SY_OPEN_SQL_DB', was not
caught, which
led to a runtime error. The reason for this exception is:
The data read during a SELECT access could not be inserted into the
target field.
Either conversion is not supported for the target field's type or the
target field is too short to accept the value or the data are not in a
form that the target field can acceptCheck below code
REPORT zpwtest .
*** Tables
DATA: lt_data TYPE REF TO data.
DATA: lt_fieldcatalog TYPE lvc_t_fcat.
data : p_field type string ,
p_table type string .
*** Structure
DATA: ls_fieldcatalog TYPE lvc_s_fcat.
*** Data References
DATA: new_line TYPE REF TO data.
*** Field Symbols
FIELD-SYMBOLS: <fs_data> TYPE REF TO data,
<fs_1> TYPE ANY TABLE,
<fs_2>,
<fs_3>.
ls_fieldcatalog-fieldname = 'MANDT'.
APPEND ls_fieldcatalog TO lt_fieldcatalog.
ls_fieldcatalog-fieldname = 'CARRID'. "Fieldname
ls_fieldcatalog-inttype = 'C'. "Internal Type C-> Character
APPEND ls_fieldcatalog TO lt_fieldcatalog.
ls_fieldcatalog-fieldname = 'CONNID'.
ls_fieldcatalog-inttype = 'N'.
APPEND ls_fieldcatalog TO lt_fieldcatalog.
ls_fieldcatalog-fieldname = 'FLDATE'.
ls_fieldcatalog-inttype = 'D'.
APPEND ls_fieldcatalog TO lt_fieldcatalog.
ls_fieldcatalog-fieldname = 'PRICE'.
ls_fieldcatalog-inttype = 'P'.
APPEND ls_fieldcatalog TO lt_fieldcatalog.
ls_fieldcatalog-fieldname = 'CURRENCY'.
ls_fieldcatalog-inttype = 'C'.
APPEND ls_fieldcatalog TO lt_fieldcatalog.
ASSIGN lt_data TO <fs_data>.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = lt_fieldcatalog
IMPORTING
ep_table = <fs_data>
EXCEPTIONS
generate_subpool_dir_full = 1
OTHERS = 2
IF sy-subrc <> 0.
ENDIF.
*** So <FS_1> now points to our dynamic internal table.
ASSIGN <fs_data>->* TO <fs_1>.
*** Next step is to create a work area for our dynamic internal table.
CREATE DATA new_line LIKE LINE OF <fs_1>.
*** A field-symbol to access that work area
ASSIGN new_line->* TO <fs_2>.
<b>
p_field = 'mandt carrid connid fldate price currency' .
p_table = 'sflight' .
*** And to put the data in the internal table
SELECT (p_field)
FROM (p_table)
INTO CORRESPONDING FIELDS OF TABLE <fs_1>.
</b>
*** Access contents of internal table
LOOP AT <fs_1> ASSIGNING <fs_2>.
ASSIGN COMPONENT 5 OF STRUCTURE <fs_2> TO <fs_3>.
WRITE: / <fs_3>.
ENDLOOP. -
Query to convert Row to column - Re-posting
Hi all,
i am re-posting the same requirement, please do the needful.
I need a query to convert row value into column delimited by ','
create table tb_row_2_col (id number,val varchar2(100));
insert into tb_row_2_col values (1,'col1');
insert into tb_row_2_col values (1,'col2');
insert into tb_row_2_col values (1,'col3');
insert into tb_row_2_col values (2,'col4');
insert into tb_row_2_col values (2,'col5');
commit;
SQL> select * from tb_row_2_col;
ID VAL
1 col1
1 col2
1 col3
2 col4
2 col5
SQL>
if i execute a query the output should be like this
ID VAL
1 col1,col2,col3
2 col4,col5
Thanks in advance
S. Sathish KumarMost repeated question in the forum..
SQL> select id,max(ltrim(sys_connect_by_path(val,','),',')) res
2 from (select id,val,
3 row_number() over(partition by id order by val) rn
4 from tb_row_2_col)
5 start with rn = 1
6 connect by prior rn = rn -1
7 and prior id = id
8 group by id;
ID RES
1 col1,col2,col3
2 col4,col5<br>
Message was edited by:
jeneesh
Check here for variations.. -
Query to convert Row to column
Hi all,
I need a query to convert row value into column delimited by ','
create table tb_row_2_col (id number,val varchar2(100));
insert into tb_row_2_col values (1,'col1');
insert into tb_row_2_col values (1,'col2');
insert into tb_row_2_col values (1,'col3');
insert into tb_row_2_col values (2,'col4');
insert into tb_row_2_col values (2,'col5');
commit;
SQL> select * from tb_row_2_col;
ID VAL
1 col1
1 col2
1 col3
2 col4
2 col5
SQL>
if i execute a query the output should be like this
ID VAL
1 col1,col2,col3
2 col4,col5
Thanks in advance
S. Sathish KumarOr look for aggregation techniques against the forum helping by the search feature (top-right of the current page).
Nicolas. -
Sql query to get union of matching rows
I want to write a sql query that shows union f all the [Type] for each [Key] if [Key] has atleast one [Type] in common and for non matched [Key]s it will return the row as it is.
For example In the sql table below [Key] '1' and '2' has [Type] 'B' in common and [Key] '1' and '4' has [Type] 'A' in common. In this case [Key] '1', '2' and '4' are related so result will be union of [Type]s in [Key]s '1', '2' and '4' which are 'A', 'B', 'C'
and 'E' for each [Key]. And [Key] '3' has no [Type] in common so it will return itself.
Input:
declare @categories table ([Key] int, [Type] Char(1))
insert into @categories ([Key], [Type]) values (1, 'A')
insert into @categories ([Key], [Type]) values (1, 'B')
insert into @categories ([Key], [Type]) values (2, 'B')
insert into @categories ([Key], [Type]) values (2, 'C')
insert into @categories ([Key], [Type]) values (3, 'D')
insert into @categories ([Key], [Type]) values (4, 'E')
insert into @categories ([Key], [Type]) values (4, 'A')
insert into @categories ([Key], [Type]) values (5, 'F')
insert into @categories ([Key], [Type]) values (5, 'G')
insert into @categories ([Key], [Type]) values (6, 'G')
insert into @categories ([Key], [Type]) values (6, 'H')
Desired output:
Key Type
1 A
1 B
1 C
1 E
2 A
2 B
2 C
3 D
4 A
4 B
4 E
5 F
5 G
5 H
6 F
6 G
6 H
The data element names are wrong. KEY is a reserved word; “Categories" and "type" are called attribute properties in ISO-11179 rules. Matthias Kläy is right; this is a graph problem in disguise, but you can do it with set theory to get what are called
equivalence classes.
An edge in a graph has two nodes. Some authors allow a single node to count as a edge, but a better way is to put the same node on both ends of the edge. Here is the graph in a table with all the needed constraints. This is why you should post DDL and not be
so rude.
DROP TABLE Graph;
CREATE TABLE Graph
(edge INTEGER NOT NULL,
node_1 CHAR(1) NOT NULL,
node_2 CHAR(1) NOT NULL,
CHECK (node_1 <= node_2),
PRIMARY KEY (node_1, node_2));
Here is your data in the correct format.
INSERT INTO Graph
VALUES
(1, 'A', 'B'),
(2, 'B', 'C'),
(3, 'D', 'D'), -- orphan node
(4, 'A', 'E'),
(5, 'F', 'G'),
(6, 'G', 'H');
Now Google Warshall's Algorithm. It uses three nested loops and an adjacency array. This is very clean and fast in a procedural language. Not so much in SQL. Let us do this in steps:
WITH X1 (edge, node1_1, node1_2, node2_1, node2_2 )
AS
(SELECT CASE WHEN G1.edge <> G2.edge
THEN G1.edge ELSE G2.edge END,
G1.node_1, G1.node_2,
G2.node_1, G2.node_2
FROM Graph AS G1, Graph AS G2
WHERE G1.node_1 IN (G2.node_1, G2.node_2)
AND G1.edge <> G2.edge),
X2 (edge, node_1, node_2)
AS
(SELECT edge,
CASE WHEN node1_1 IN (node2_1, node2_2) THEN node1_2 ELSE node1_1 END,
CASE WHEN node2_1 IN (node1_1, node1_2) THEN node2_2 ELSE node2_1 END
FROM X1)
SELECT DISTINCT edge,
CASE WHEN node_1 < node_2 THEN node_1 ELSE node_2 END,
CASE WHEN node_2 < node_1 THEN node_1 ELSE node_2 END
FROM X2;
The X1 subquery gets the paths of length two. The X2 subquery removes the middle node and creates a new sorted edge. Insert these new rows into Graphs, if they are not there. Repeat the process until no more rows are added.
DROP TABLE Graph;
CREATE TABLE Graph
(edge INTEGER NOT NULL,
node_1 CHAR(1) NOT NULL,
node_2 CHAR(1) NOT NULL,
CHECK (node_1 <= node_2),
PRIMARY KEY (node_1, node_2));
INSERT INTO Graph
VALUES
(1, 'A', 'B'),
(2, 'B', 'C'),
(3, 'D', 'D'), -- orphan node
(4, 'A', 'E'),
(5, 'F', 'G'),
(6, 'G', 'H');
Here is the monster rolled up into a single statement.
INSERT INTO Graph
SELECT DISTINCT edge,
CASE WHEN node_1 < node_2 THEN node_1 ELSE node_2 END,
CASE WHEN node_2 < node_1 THEN node_1 ELSE node_2 END
FROM (SELECT edge,
CASE WHEN node1_1 IN (node2_1, node2_2) THEN node1_2 ELSE node1_1 END,
CASE WHEN node2_1 IN (node1_1, node1_2) THEN node2_2 ELSE node2_1 END
FROM
(SELECT CASE WHEN G1.edge < G2.edge
THEN G1.edge ELSE G2.edge END,
G1.node_1, G1.node_2,
G2.node_1, G2.node_2
FROM Graph AS G1, Graph AS G2
WHERE G1.node_1 IN (G2.node_1, G2.node_2)
AND G1.edge <> G2.edge) AS X1(edge,node1_1, node1_2, node2_1, node2_2) )
AS X2(edge, node_1, node_2)
EXCEPT
SELECT * FROM Graph;
SELECT * FROM Graph ORDER BY edge, node_1, node_2;
1 A B
1 A C
1 B E
1 C E
2 B C
3 D D
4 A E
5 F G
5 F H
6 G H
--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
in Sets / Trees and Hierarchies in SQL -
Query to delete row where column value contains alphabets
Hi,
Could anyone please help me to get this query work.
Query to delete row where column value contains alphabets.
DELETE FROM BIN_ITEM WHERE order_nmb LIKE '%[A-Z]%' || LIKE '%[a-z]%'
Thanks and Regards,
Deekay.RaminHashimzadeh wrote:
SELECT order_nmb FROM BIN_ITEM WHERE regexp_count(order_nmb,'[0-9]') = 0
Ramin Hashimzade
But that won't reject strings like 'gfgG%dgh' which aren't pure alphabetic.
Try:
with test_data as (
select 'ghTYJYEhdfe' str from dual
union
select 'dfF5ssd' from dual
union
select 'rgth*dgheh' from dual
union
select 'ggf{' from dual
union
select 'rwhrhrh' from dual
select *
from test_data
where regexp_instr(str,'[^[:alpha:]]')=0; -
Cartesian of data from two tables with no matching columns
Hello,
I was wondering – what’s the best way to create a Cartesian of data from two tables with no matching columns in such a way, so that there will be only a single SQL query generated?
I am thinking about something like:
for $COUNTRY in ns0: COUNTRY ()
for $PROD in ns1:PROD()
return <Results>
<COUNTRY> {fn:data($COUNTRY/COUNTRY_NAME)} </COUNTRY>
<PROD> {fn:data($PROD/PROD_NAME)} </PROD>
</Results>
And the expected result is combination of all COUNTRY_NAMEs with all PROD_NAMEs.
What I’ve noticed when checking query plan is that DSP will execute two queries to have the results – one for COUNTRY_NAME and another one for PROD_NAME. Which in general results in not the best performance ;-)
What I’ve noticed also is that when I add something like:
where COUNTRY_NAME != PROD_NAME
everything is ok and there is only one query created (it's red in the Query plan, but still it's ok from my pov). Still it looks to me more like a workaround, not a real best approach. I may be wrong though...
So the question is – what’s the suggested approach for such queries?
Thanks,
Leszek
Edited by xnts at 11/19/2007 10:54 AMWhich in general results in not the best performanceI disagree. Only for two tables with very few rows, would a single sql statement give better performance.
Suppose there are 10,000 rows in each table - the cross-product will result in 100 million rows. Sounds like a bad idea. For this reason, DSP will not push a cross-product to a database. It will get the rows from each table in separate sql statements (retrieving only 20,000 rows) and then produce the cross-product itself.
If you want to execute sql with cross-products, you can create a sql-statement based dataservice. I recommend against doing so. -
WITH clause query:- Returns No Rows
Hi,
I am using the following query with, WITH clause, but some how it give "0 rows" returned,
The underlying query does returns row when run in stand alone mode,
With v_score_his_old
As
SELECT schs_run_date,schs_loc_shortcut_source,schs_lot_number,schs_facility_new,schs_facility_old, schs_operation_new,
schs_operation_old,schs_route_new,schs_route_old,schs_product_new,schs_product_old,schs_owner_old,schs_intransit,
schs_date,schs_transaction,schs_quantity_1_new,schs_quantity_1_old,/*0,*/schs_if_count_new,schs_if_count_old,
schs_preprocessed,schs_consumed_quantity,/*'Y',*/schs_if_id,schs_if_id_old,fif_fac_loc_id
FROM scm_score_his,full_item_facilities,location_params
WHERE schs_state = 0
AND fif_if_id = schs_if_id_old
AND lopo_param_value = to_char(fif_site_id_fm)
AND lopo_param_name IN ('SITE_FAB', 'SITE_SORT')
AND (schs_loc_shortcut_source = 'MP' OR schs_loc_shortcut_source = 'RE' OR schs_loc_shortcut_source = 'VI')
UNION ALL
SELECT schb_run_date,schb_loc_shortcut_source,schb_lot_number,schb_facility_new,schb_facility_old,schb_operation_new,
schb_operation_old,schb_route_new,schb_route_old,schb_product_new,schb_product_old,schb_owner_old,schb_intransit,
schb_date,schb_transaction,schb_quantity_1_new,schb_quantity_1_old,/*0,*/schb_if_count_new,schb_if_count_old,schb_preprocessed,
schb_consumed_quantity,/*'Y',*/schb_if_id,schb_if_id_old,fif_fac_loc_id
FROM scm_score_his_backups,full_item_facilities,location_params
WHERE schb_state = 0
AND fif_if_id = schb_if_id_old
AND lopo_param_value = to_char(fif_site_id_fm)
AND lopo_param_name IN ('SITE_FAB', 'SITE_SORT')
AND schb_date >= trunc(sysdate - 84)
AND (schb_loc_shortcut_source = 'MP' OR schb_loc_shortcut_source = 'RE' OR schb_loc_shortcut_source = 'VI')
Select schs_run_date,schs_loc_shortcut_source,schs_lot_number
From v_score_his_old
Where schs_loc_shortcut_source = 'MP';
Oracle version is Oracle9i Enterprise Edition Release 9.2.0.6.0
I am not able to get where I can going wrong.
Please help me to understand this issue,
Regards
Umesh..With v_score_his_old
As
SELECT
schs_run_date,schs_loc_shortcut_source,schs_lot_numbe
,schs_facility_new,schs_facility_old,
schs_operation_new,
chs_operation_old,schs_route_new,schs_route_old,schs_p
roduct_new,schs_product_old,schs_owner_old,schs_intran
sit,
chs_date,schs_transaction,schs_quantity_1_new,schs_qua
ntity_1_old,/*0,*/schs_if_count_new,schs_if_count_old,
chs_preprocessed,schs_consumed_quantity,/*'Y',*/schs_i
f_id,schs_if_id_old,fif_fac_loc_id
FROM
cm_score_his,full_item_facilities,location_params
WHERE schs_state = 0
AND fif_if_id = schs_if_id_old
AND lopo_param_value =
to_char(fif_site_id_fm)
AND lopo_param_name IN ('SITE_FAB',
'SITE_SORT')
AND (schs_loc_shortcut_source = 'MP' OR
schs_loc_shortcut_source = 'RE' OR
schs_loc_shortcut_source = 'VI')
UNION ALL
SELECT
schb_run_date,schb_loc_shortcut_source,schb_lot_number
,schb_facility_new,schb_facility_old,schb_operation_ne
w,
chb_operation_old,schb_route_new,schb_route_old,schb_p
roduct_new,schb_product_old,schb_owner_old,schb_intran
sit,
chb_date,schb_transaction,schb_quantity_1_new,schb_qua
ntity_1_old,/*0,*/schb_if_count_new,schb_if_count_old,
schb_preprocessed,
chb_consumed_quantity,/*'Y',*/schb_if_id,schb_if_id_ol
d,fif_fac_loc_id
FROM
cm_score_his_backups,full_item_facilities,location_par
ams
WHERE schb_state = 0
AND fif_if_id = schb_if_id_old
AND lopo_param_value =
to_char(fif_site_id_fm)
AND lopo_param_name IN ('SITE_FAB',
'SITE_SORT')
AND schb_date >= trunc(sysdate - 84)
AND (schb_loc_shortcut_source = 'MP' OR
schb_loc_shortcut_source = 'RE' OR
schb_loc_shortcut_source = 'VI')
ect
schs_run_date,schs_loc_shortcut_source,schs_lot_number
From v_score_his_old
Where schs_loc_shortcut_source = 'MP';
Hi!
I've a doubt. If u finally picking all the values which matched with field schs_loc_shortcut_source and which is 'MP' - then why r u using multiple condition in the WITH part? So, in that case, u don't have to write that additional filtering of the following lines in the outer query -
Where schs_loc_shortcut_source = 'MP';Regards.
Satyaki De. -
Listing foreign keys with non matching column definitions
Dear All,
I seen an entry in DBA weeky activities s that "Listing foreign keys with non matching column definitions" . What is meant by that?. How to pick up that?
ShijuI seen an entry in DBA weeky activities s that
"Listing foreign keys with non matching column
definitions" . What is meant by that?. How to pick up
that?Most probably find columns which are part of foreign keys, but their respective primary key column have different length (AFAIK data type cannot be different).
Data dictionary can help you in that, I'll give you hints where to look at:
user/all/dba_constraints - foreign and primary keys
user/all/dba_cons_columns - columns which are part of constraints
user/all/dba_tab_columns - column definitions of tables
However creating query from these data dictionary views could be a nice task for you :)
Gints Plivna
http://www.gplivna.eu -
Using a SQL Query in an Alert and Matching a String
I've created an alert in 12.0.4 using a SQL Query and the field that I'm trying to match is a string. Originally the query returned multiple rows but when the alert still didn't fire, I modified the query WHERE clause to return only one row:
NAME RESPONSE
Are area lights working? No
My expression in the metric is RESPONSE. In the Monitor I'm matching a string equal to No. (Do I need double quotes around the matchvalue? Single quotes? No quotes?) The metric is in the 15min scan group, the role is xMII Developers and I'm in that role. The monitor alert string is ' = '. Both metric and monitor are active and I've subscribed to the monitor. Other alerts in the 15min scan group (all based on tag queries) are firing off properly.
Why is nothing showing up in the Alert Log?
David MacindoeDavid,
Did you figure out the answer? If not, I will try to find someone to address your question.
Mike -
I have a problem with a query that includes 5 tables!
Equipment ec, (ec.cost, ec.workid)
Material mc, (mc.cost, mc.workid)
Labor lc, (lc.cost, lc.workid)
Work wo, (wo.workid)
Entity en
The primary key is the work id
The columns I need to extract are all the same - "cost"
The problem is that I need to extract the costs from all the tables (equipment/labor/material) where the work "id" is equal to the work "id".
The work table has a unique wo.workid but the other three tables can have
multiple nn.workid ('s).
This is the query I am working from at this time...
SELECT distinct wo.workid, wo.description, wo.supervisor, wo.acctnum,
wo.shop, wo.woaddress, wo.initiatedate,
TO_NUMBER (TO_CHAR (wo.initiatedate, 'MM')) AS mnth,
TO_NUMBER (TO_CHAR (wo.initiatedate, 'YYYY')) AS yr,
wo.actualfinishdate, wo.assetgroup, wo.unitsaccompdesc,
wo.unitsaccomplished,
sum(decode (lc.cost, 0, null, lc.cost)) labour_cost,
lc.laborname AS labour_name,
SUM (decode(mc.COST, 0, null, mc.cost)) AS material_cost,
mc.description AS mat_desc,
SUM (decode(ec.COST, 0, null, ec.cost)) AS equipment_cost,
ec.description AS equip_desc, en.module
FROM work wo,
equipment ec,
material mc,
labor lc,
entity en
WHERE (lc.COST <> 0 AND mc.COST <> 0 AND ec.COST <> 0)
AND wo.applytoentity = en.code
AND mc.workid = wo.workid
AND ec.workid = wo.workid
AND lc.workid = wo.workid
GROUP BY wo.workid,
wo.description,
wo.supervisor,
wo.acctnum,
wo.shop,
wo.woaddress,
wo.initiatedate,
wo.actualfinishdate,
wo.assetgroup,
wo.unitsaccompdesc,
wo.unitsaccomplished,
lc.COST,
lc.laborname,
mc.COST,
mc.description,
ec.COST,
ec.description,
en.module
any help would be appreciated!Hi John...
I am still getting duplicate values.
When the query grabs a value from the labour table it also grabs the values from the other tables and puts them in the same row... There are many rows in the three costs
tables and only one in the work table.
I have a dump of the rows but I cannot find a way to save it here.
Here is a cut down version of the data I am retrieving.
ID DESCRIPTION LAB MAT EQUIP
345 General Building Interior Maintenance Activities 136.60 59.89 133.60
345 General Building Interior Maintenance Activities 64.38 59.89 133.60
345 General Building Interior Maintenance Activities 42.92 59.89 133.60
345 General Building Interior Maintenance Activities 91.28 59.89 133.60
345 General Building Interior Maintenance Activities 374.24 59.89 133.60
345 General Building Interior Maintenance Activities 182.56 59.89 133.60
345 General Building Interior Maintenance Activities 175.68 59.89 133.60
345 General Building Interior Maintenance Activities 48.80 59.89 58.80
345 General Building Interior Maintenance Activities 89.48 59.89 58.80
345 General Building Interior Maintenance Activities 79.80 59.89 58.80
345 General Building Interior Maintenance Activities 294.88 59.89 58.80
345 General Building Interior Maintenance Activities 24.92 59.89 58.80
345 General Building Interior Maintenance Activities 147.44 59.89 58.80
345 General Building Interior Maintenance Activities 182.56 59.89 58.80
345 General Building Interior Maintenance Activities 98.59 59.89 58.80
345 General Building Interior Maintenance Activities 126.84 59.89 58.80
345 General Building Interior Maintenance Activities 55.00 59.89 6,656.00
345 General Building Interior Maintenance Activities 182.56 59.89 6,656.00
345 General Building Interior Maintenance Activities 98.59 59.89 6,656.00
345 General Building Interior Maintenance Activities 191.36 59.89 6,656.00
345 General Building Interior Maintenance Activities 136.60 59.89 66.96
345 General Building Interior Maintenance Activities 55.00 59.89 66.96
345 General Building Interior Maintenance Activities 491.04 59.89 66.96
345 General Building Interior Maintenance Activities 24.92 59.89 66.96
345 General Building Interior Maintenance Activities 182.56 59.89 66.96
345 General Building Interior Maintenance Activities 110.00 59.89 66.96
345 General Building Interior Maintenance Activities 162.80 59.89 66.96
345 General Building Interior Maintenance Activities 85.84 59.89 66.96
345 General Building Interior Maintenance Activities 65.44 59.89 66.96
345 General Building Interior Maintenance Activities 64.38 59.89 736.00
345 General Building Interior Maintenance Activities 79.80 59.89 736.00
Maybe you are looking for
-
I am trying to install software for iTwin Connect, but after downloading the dmg file and launching the program, I receive a message saying the file can't open and to check my internet connection. Any ideas?
-
My IPOD classic 6 will no longer stay in sleep mode. It's less than 2 years old
My IPOD classic 6th generation will no longer stay in sleep mode and it is less then 2 years old. It is running the battery down because of this. Does anybody know how to fix this issue? I have use the hold button when I put it in sleep mode. I have
-
who had applied to a dating website but was waiting for approval and not yet a member. When I asked him how he got my personal email account which was NOT on there, he said that his "detector" told him. When asked for details this was his reply... "I
-
I can't open or save file with Java Web Start
Hi, i can't open or save file with Java Web Start: import java.io.*; import java.util.*; public class MetaDataFileCreator { public String fileNameSpace = null; public String fileName = null; protected Properties file = null; public MetaDataFileCreato
-
Newbie to Oracle SQL Developer
Hi guys, cheers for taking the time to read this post..... Im running a few different scripts in Oracle SQL Developer, one called CreateLocalSchema.sql, another CreateLocalProcedures,sql and a third SystemSetup.sql When I press f5 to run the Systemse