Probably a simple SQL Query - Newbie
I want to select entries from a table that has 2 columns where the first column value is contained within the 2 column....Does that make sense?
The first is a varchar that contains a value for a customer. The second is a varchar that contains a a textual description of a problem the customer has. My problem is that I only want to select the entries in the table where the second column contains a description that includes the first column value.
eg. I want to select rows that have the following condition:
column1 has value of "customer1"
column2 has a value of "an error was reported by customer1 on service blah"
but not these
column1 has value of "customer1"
column2 has a value of "an error was reported by customer2 on service blah"
This is probably a simple question but I've spent time looking at how to do it and can't seem to manage...any help would be appreciated....Thanks
Hi Barbara,
I've never used the CONTAINS operator before. I compared the use in this situation to the other methods and found the others to be FAR less resource intensive, despite working on unindexed columns, as I demonstrate below.
It would seem that CONTAINS is unsuited to this type of simple query. Can you shed any light on this, from the perspective of somebody who has used it before? Is this type of performance penalty normal? If so, it could seem that CONTAINS is fairly useless next to LIKE.
[email protected]> desc test;
Name Null? Type
COLUMN1 VARCHAR2(20)
COLUMN2 VARCHAR2(100)
[email protected]> select count(*) from test;
COUNT(*)
10000
Elapsed: 00:00:00.00
[email protected]> select * from test where instr(column2, column1) > 0;
10000 rows selected.
Elapsed: 00:00:00.18
Execution Plan
0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=23 Card=8328 Bytes=532992)
1 0 TABLE ACCESS (FULL) OF 'TEST' (TABLE) (Cost=23 Card=8328 Bytes=532992)
Statistics
5 recursive calls
0 db block gets
821 consistent gets
0 physical reads
0 redo size
702263 bytes sent via SQL*Net to client
7838 bytes received via SQL*Net from client
668 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
10000 rows processed
[email protected]> select * from test where column2 like '%'||column1||'%';
10000 rows selected.
Elapsed: 00:00:00.18
Execution Plan
0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=23 Card=8328 Bytes=532992)
1 0 TABLE ACCESS (FULL) OF 'TEST' (TABLE) (Cost=23 Card=8328 Bytes=532992)
Statistics
5 recursive calls
0 db block gets
821 consistent gets
0 physical reads
0 redo size
702263 bytes sent via SQL*Net to client
7838 bytes received via SQL*Net from client
668 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
10000 rows processed
[email protected]> create index testidx on test(column2) indextype is ctxsys.context;
Index created.
[email protected]> select * from test where contains(column2, column1) > 0;
10000 rows selected.
Elapsed: 00:00:56.80
Execution Plan
0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=25008 Card=4 Bytes=284)
1 0 TABLE ACCESS (FULL) OF 'TEST' (TABLE) (Cost=25008 Card=4 Bytes=284)
Statistics
55201 recursive calls
0 db block gets
85857 consistent gets
0 physical reads
0 redo size
702263 bytes sent via SQL*Net to client
7838 bytes received via SQL*Net from client
668 SQL*Net roundtrips to/from client
204 sorts (memory)
0 sorts (disk)
10000 rows processedThanks in advance,
Anthony
Similar Messages
-
Simple SQL Query and Parameters and LOV
Newbie and trying to work thru building a simple sql query with a single table query and use a parameter and lov.
Can anyone point me to an example.
simple query:
select cust_id, name_desc, name_add1, name_add2, name_city
from customer_table
where cust_id = :cust_parm
This works in straight sql and in the query builder by prompting for the customer ID. When building a parameter using LOV or search, it doesn't seem to detect the variable.
Thanks..
DDIf you are using version 11g, then as soon as you save the query in the data model, it should notice the parameter and ask if you want to add the parameter to the data model. What version of BIP are you using?
What happens if you exclude the parameter from the query and simply hard-code the criteria? Can you generate XML data?
From your wording, it sounds like you're trying to create a parameter from the LOV dialog. LOVs and parameters are totally distinct. After each are created separately, then you configure the parameter to use the LOV. -
Simple SQL query statement is needed
I need a simple SQL query to fetch records which is existed in all the departments.
for example: i want to list the employees which are existed in each and every department.. not sure how should i get those.. will anyone help me please.. thanks in advanceI think it would be wise to go to the following training:
Oracle Database <version> : Introduction to SQL
You will get the information you are looking for in five days. You can go find a tutorial on ANSI SQL, as advised by this board for free, to fix your immediate problem with a simple query. But, I personally recommend a more formal class specific to Oracle, as you will also get information about PL/SQL, and you get the benefit with working with other DBA/programmers when you are learning. This will solve your immediate issue, and any future issues with the language.
You can find it in the Education section of the Oracle website. -
Simple SQL query SQL developer takes it, The wizzard of XE does not
Hello everybody
I wrote this simple query which SQL developer runs fine, but when I try to launch a Report based on this sql query it tells me invalid sql statement. That is true, it may be invalid because this IF clause in there..but SQL developer seems to be very tolerant or understands more...
the reason I wrote that is because obviously if there are no bosses, ie = 0 then i would get an error when dividing it by 0, so I put that 0 just to select the good ones
if count (bosses) >0
select company, postcode,
sum( bosses/staff)
from evaluation
group by company, postcode
Thank you very much
Alvarooh yes (blushed in shame as how dumb i looked like) i knew about the denominator 0 and infinite as as result i just didnt notice my zero was on the numerator :(
however, i run the query and i got this message in sql developer
Error starting at line 1 in command:
select company, postcode,
case when staff != 0 then sum( bosses/staff) end
from evaluation
group by company, postcode
Error at Command Line:2 Column:10
Error report:
SQL Error: ORA-00979: not a GROUP BY expression
00979. 00000 - "not a GROUP BY expression"
*Cause:
*Action: -
I have an interesting problem and wondering how I can get this result in a single SQL query:
Here is table emp has data with a row for every year since the employee joined with the salary paid that particular year with following columns:
emp (
id varchar2(10),
name varchar2(25),
interested_year date,
salarypaid number(10)
I would like to print the results as follows:
id name previousyear_salarypaid currentyear_salarypaid
x xxxxx xxxxxx xxxxx
Is this possible to do? I have tried to simplify my actual problem so I hope I have included all necessary details.Just to clarify, the columns mentioned in the results are
previousyear_salarypaid is nothing but
salarypaid where interested_year = '2007'
currentyear_salarypaid is nothing but
salarypaid where interested_year = '2006' -
Your estimated performance of a very simple SQL query
Hi there..
Sometimes it seems hard to find answers for the most simple questions so I hope you can help me and be overbearing ;)
I am going to have a table with a few million records in it, 30-40 columns of which 80% has data, indexes on maybe 10 columns (certainly the columns I am querying), less than ten thousand new records a day with a variety of different column values and using Oracle 10 or 11.
I am going to be running a single SQL SELECT statement quite regularily against these records to retrieve all records whose value of a single column is the same (and specified in my WHERE clause)
It will be a query like this; SELECT * FROM person where city = 'Amsterdam' AND
The column 'city' will have a simple index on it. 4-8 records will have the same value (e.g. there will only be up to 8 rows where city is 'Amsterdam' in the above example) which means that with 5 million records I will probably have between 625,000 and 1,250,000 "sets" that I am querying and retrieving per SQL. Thed atatype could be varchar or number - not sure yet.
I will retrieve the same data a lot but generally also access all the other data on a regular basis.
How should I expect this to perform? Always fast I imagine because will there will be any table scans do we think? I don't have to think about partitioning of too regular statistic calculation or anything? Anything to watch out for?
Any feedback would be greatly appreciated.
Thanks a lot in advance.
DanielIt's impossible to tell without seeing a true structure and indexes etc.
It sounds ok at a first read. High selectivity, low cardinality, low skewing. Obviously, ensuring stats are up to date on a reasonably regular basis is a good idea, especially with 10,000+ records added daily. I would expect it to perform ok. -
Execute simple SQL query on Java
Hello,
I am a newbie on ADF, I am a web developer used to work with EJBs, WebServices, Servlets and this stuff... But now I am on a project that uses ADF.
My opinion, I don´t like this kind of development, drag and drop, I prefer to code on :) but, I need to work.
I am developing a utility class that needs to run some SQL statements and send an email.
I tried to work with the conventional @Resource (name...) Datasource ds; and did not worked, because it does not injected the object.
I tried to create a java implementation of my application module, instanciate it and get a ViewObject that I created to do a select statement, and the ViewObject comes null...
I just wanna do a simple query... just it, using simple java for web I would have already done it... How is the best way to do it?
Thanks.ApplicationModuleImpl am = getApplicationModuleByName("AppModuleDataControl")
DBTransaction dbt = am.getDBTransaction();
CallableStatement cs = dbt.createCallableStatement(query, .......
You can get ApplicationModule by this code. In this case there should be some binding related to this AM in pageDef. Input parameter "name" should be datacontrol name;
public static ApplicationModuleImpl getApplicationModuleByName(String name) {
try {
BindingContext bc = (BindingContext)resolveExpression("#{data}");
DCDataControl dc = bc.findDataControl(name);
return (ApplicationModuleImpl)dc.getDataProvider();
} catch (Exception e) {
l.error(e);
return null;
public static Object resolveExpression(String expression) {
l.debug("expression: " + expression);
FacesContext fctx = FacesContext.getCurrentInstance();
ELContext elctx = fctx.getELContext();
ExpressionFactory exprFactory =
fctx.getApplication().getExpressionFactory();
ValueExpression ve =
exprFactory.createValueExpression(elctx, expression, Object.class);
Object value = ve.getValue(elctx);
return value;
} -
Simple SQL Query is not using Bitmap index
Hello to All,
We are having Oracle9i Database and using it for the datawarehouse purpose.
I have created the bitmap index on calledinfo column and I am running the following simple query which takes serveral hours to complete:
select * from ssp.ssp_2006_q4 where calledinfo='799992515f'
OR
select calledinfo from ssp.ssp_2006_q4 where calledinfo='799992515f'
I don't know why it is not using the bitmap index: Can anybody help me here?
Thanks in Advance
HashimI know why and everyone that has read Jonathan Lewis' book on the CBO knows why.
Why? Because the CBO thinks the cost of using your index will be higher than the cost of ignoring it.
To see what Oracle is thinking run an explain plan using DBMS_XPLAN for create the output and then rerun it with a hint forcing index usage.
It is a mistake to believe that an index will always make things better. Issues of cardinality, clustering factor, etc. are very important.
Post the explain plans if you have any questions about what they show:
http://www.psoug.org/reference/explain_plan.html -
Hi,
I would like to know how this type of query is processed internally in Oracle
SQL> select * from ( select 1 from dual, ( select 2 from dual ) g );
1
1
SQL> select * from ( select 1 from dual, select 2 from dual );
select * from ( select 1 from dual, select 2 from dual )
ERROR at line 1:
ORA-00903: invalid table nameWhy would 1 2 not be printed in result?
Thanksuser1980 wrote:
Hi,
I would like to know how this type of query is processed internally in Oracle
SQL> select * from ( select 1 from dual, ( select 2 from dual ) g );
1
1
SQL> select * from ( select 1 from dual, select 2 from dual );
select * from ( select 1 from dual, select 2 from dual )
ERROR at line 1:
ORA-00903: invalid table nameWhy would 1 2 not be printed in result?
ThanksJust look at what you are selecting from...
SQL> select 1 from dual, select 2 from dual;
select 1 from dual, select 2 from dual
ERROR at line 1:
ORA-00903: invalid table name
SQL>it's not valid syntax for an SQL select statement so you can't use it as an inline view.
If you are select from something, then that something has to be a valid view or table. -
Hi,
I'm trying create a simple query which tells me the occurance of a particular football match on a particular date. The table is as follows...
CREATE TABLE match
(matchId NUMBER(5)
CONSTRAINT match_matchId_nn NOT NULL,
matchDate DATE
CONSTRAINT match_date_nn NOT NULL,
stadiumId NUMBER(5)
CONSTRAINT match_stadiumId_nn NOT NULL,
CONSTRAINT matchId_pk PRIMARY KEY (matchId));
Bascially, i'm trying to create a trigger which will implement the constraint that 'only one match can be at one stadium on a particular date'.
Any ideas guys?
Cheers...ALTER TABLE match ADD CONSTRAINT match_date_uk UNIQUE
(stadiumId, matchDate)Bear in mind, though, that using dates in unique constraints can be problematic, because of the time element, which means there are 86400 unique values for each day. If your application enforces a rule that has only one match per stadium per day then all you need is a TRUNC() call in an insert/update trigger to make sure of that. If your application is going to allow more than one match per day the checking logic starts to get messy...
Cheers, APC
P.S. Oleg's solution is incorrect because it includes the primary key MatchId, which would thus permit duplicate combinations of stadium and date. -
Help Reqd - on simple sql query
Hi,
I have two tables back_temp_ord_hist, temp_ord_hist of similar structures
create table <table_name>
order_number varchar2(10),
item_number integer,
sched_line_number integer,
dlv_doc_id varchar2(10),
mtrl_mstr_key integer,
cust_key integer,
wrhse_key integer,
sls_ord_type varchar2(4)
Now I have inserted same data set in the two tables. (same following three rows in both the tables)
0009032022 160 2 0091383073 27219 1694 20 ZISO
0009032022 160 3 0091383073 27219 1694 20 ZISO
0009032022 160 4 0091383073 27219 1694 20 ZISO
Then I am trying to use a query like below :
select
fact.order_number
, fact.item_number
, fact.sched_line_number
, bk_fact.sched_line_number as old_sched_line_number
, fact.dlv_doc_id
,dbms_utility.get_hash_value(fact.order_number||fact.item_number||fact.sched_line_number||fact.dlv_doc_id,1,100) ord_hist_hash
,dbms_utility.get_hash_value(bk_fact.order_number||bk_fact.item_number||bk_fact.sched_line_number||bk_fact.dlv_doc_id,1,100) back_ord_hist_hash
, fact.mtrl_mstr_key
, bk_fact.mtrl_mstr_key as old_mtrl_mstr_key
, fact.cust_key
, bk_fact.cust_key as old_cust_key
, fact.wrhse_key
, bk_fact.wrhse_key as old_wrhse_key
, fact.sls_ord_type
, bk_fact.sls_ord_type as old_sls_ord_type
from
temp_ord_hist fact
join
back_temp_ord_hist bk_fact
on fact.order_number = bk_fact.order_number
and fact.item_number = bk_fact.item_number
and fact.sched_line_number <> bk_fact.sched_line_number
and fact.dlv_doc_id = bk_fact.dlv_doc_id
order by ord_hist_hash, back_ord_hist_hash
But it is actually it is showing 6 rows. But ideally I want no rows as temp_ord_hist.sched_line_number = back_temp_ord_hist.sched_line_number in all the cases over here.
Practically it can be different then I want those rows but when it is same why the output is showing 6 rows.
What I am doing wrong over here?
Regards,
KoushikNot sure how you are getting 6 rows as the output. I did exactly the same thing that you did and I am getting the only 3 rows as the output:
see below:
SQL> create table temp_ord_hist
2 (
3 order_number varchar2(10),
4 item_number integer,
5 sched_line_number integer,
6 dlv_doc_id varchar2(10),
7 mtrl_mstr_key integer,
8 cust_key integer,
9 wrhse_key integer,
10 sls_ord_type varchar2(4)
11 );
Table created.
SQL> create table back_temp_ord_hist
2 (
3 order_number varchar2(10),
4 item_number integer,
5 sched_line_number integer,
6 dlv_doc_id varchar2(10),
7 mtrl_mstr_key integer,
8 cust_key integer,
9 wrhse_key integer,
10 sls_ord_type varchar2(4)
11 );
Table created.
SQL> insert into temp_ord_hist values ('0009032022',160,2,'0091383073',27219,1694,20,'ZISO');
1 row created.
SQL> insert into temp_ord_hist values ('0009032022',160,3,'0091383073',27219,1694,20,'ZISO');
1 row created.
SQL>
SQL> insert into temp_ord_hist values ('0009032022',160,4,'0091383073',27219,1694,20,'ZISO');
1 row created.
SQL> insert into back_temp_ord_hist values ('0009032022',160,2,'0091383073',27219,1694,20,'ZISO');
1 row created.
SQL> insert into back_temp_ord_hist values ('0009032022',160,3,'0091383073',27219,1694,20,'ZISO');
1 row created.
SQL> insert into back_temp_ord_hist values ('0009032022',160,4,'0091383073',27219,1694,20,'ZISO');
1 row created.
SQL> select
2 fact.order_number
3 , fact.item_number
4 , fact.sched_line_number
5 , bk_fact.sched_line_number as old_sched_line_number
6 , fact.dlv_doc_id
7 ,dbms_utility.get_hash_value(fact.order_number||fact.item_number||fact.sched_line_number||fact.dlv_doc_id,1,100) ord_hist_hash
8 ,dbms_utility.get_hash_value(bk_fact.order_number||bk_fact.item_number||bk_fact.sched_line_number||bk_fact.dlv_doc_id,1,100) back_ord_hist_hash
9 , fact.mtrl_mstr_key
10 , bk_fact.mtrl_mstr_key as old_mtrl_mstr_key
11 , fact.cust_key
12 , bk_fact.cust_key as old_cust_key
13 , fact.wrhse_key
14 , bk_fact.wrhse_key as old_wrhse_key
15 , fact.sls_ord_type
16 , bk_fact.sls_ord_type as old_sls_ord_type
17 from
18 temp_ord_hist fact
19 join
20 back_temp_ord_hist bk_fact
21 on fact.order_number = bk_fact.order_number
22 and fact.item_number = bk_fact.item_number
23 and fact.sched_line_number = bk_fact.sched_line_number
24 and fact.dlv_doc_id = bk_fact.dlv_doc_id
25 order by ord_hist_hash, back_ord_hist_hash
26
SQL> /
0009032022 160 3 3 0091383073 4 4 27219 27219 1694 1694 20 20 ZISO ZISO
0009032022 160 4 4 0091383073 55 55 27219 27219 1694 1694 20 20 ZISO ZISO
0009032022 160 2 2 0091383073 100 100 27219 27219 1694 1694 20 20 ZISO ZISO
SQL> -
HI all,
with the below query i want to update status of outer table jo_orders to FF ...
where select query returns status as UF(all 284 rows it returns with status UF)
i want all the matching as FF in outer jo_orders status to FF
Kindly help
update jo_orders set
status='FF' where (select jii.status from jo_orders jii, picking_lists pil where jii.jo_id=pil.ext_sys_ref_no
and pil.status='FF'and jii.status in('UF') and Jii.created_on
between to_date('21-MAY-2006') and to_date('30-MAY-2006')) ='UF';
ERR--i get is ----single row subquery return more than one row..Hi,
Don't you need to join your subquery with the main updating table ?
I would try this :
update jo_orders jii
set jii.status='FF'
where jii.status = 'UF'
and Jii.created_on between to_date('21-MAY-2006')and to_date('30-MAY-2006')
and exists (select 1
from picking_lists pil
where jii.jo_id=pil.ext_sys_ref_no
and pil.status='FF')Nicolas. -
Table1:
ID EMPNAME COUNTRY
101 XYZ USA
102 ABC UK
103 XYZ USA
104 ABC UK
Required output:
ID EMPNAME COUNTRY CALCULATED_VALUE
101 XYZ USA 1
102 ABC UK 1
103 XYZ USA 0
104 ABC UK 0
Every 1st record of (EMPNAME, COUNTRY) combination should have CALCULATED_VALUE =1 and all succeeding records of same (EMPNAME, COUNTRY) combination should have CALCULATED_VALUE =0Try this ->
scott>
scott>select * from v$version;
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
PL/SQL Release 10.2.0.1.0 - Production
CORE 10.2.0.1.0 Production
TNS for Linux: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production
Elapsed: 00:00:00.02
scott>
scott>
scott>with t
2 as
3 (
4 select 101 ID, 'XYZ' EMPNAME, 'USA' COUNTRY from dual
5 union all
6 select 102, 'ABC', 'UK' from dual
7 union all
8 select 103, 'XYZ', 'USA' from dual
9 union all
10 select 104, 'ABC', 'UK' from dual
11 )
12 select ID,
13 EMPNAME,
14 COUNTRY,
15 case
16 when rn = 1 then
17 1
18 else
19 0
20 end CALCULATED_VALUE
21 from (
22 select ID,
23 EMPNAME,
24 COUNTRY,
25 row_number() over(partition by COUNTRY order by ID) rn
26 from t
27 )
28 order by ID;
ID EMP COU CALCULATED_VALUE
101 XYZ USA 1
102 ABC UK 1
103 XYZ USA 0
104 ABC UK 0
Elapsed: 00:00:00.00
scott>Regards.
Satyaki De. -
hi,
I have two tables.
tbl1
col1 col2
a 2
a 3
b 4
tbl1
col1 col2
a 3
b 5
i need to update table1 records with the value present in table. means after updation table1 record should be
tbl1
col1 col2
a 3
a 3
b 5
its pretty simple but i am not getting the answer. Thnks in advance for help.
AshishA quick, yet dirty solution:
Update
tbl1 t1
Set
t1.col2 =
case
when (select t2.col2 from tbl2 t2 where t1.col1=t2.col1) is null
then (select max(t3.col2) from tbl1 t3 where t1.col1=t3.col1)
else (select t2.col2 from tbl2 t2 where t1.col1=t2.col1)
end; -
Simple SQL Query required....
Hi All,
I have 2 tables like the below.
Table "T1". This has c1,c2,c3 columns
Table "T2". This has c1,c2,c3 columns as T1 with same datatypes.
now i want a query which fetch the data like t1.c1,t1.c2,t1.c3,t2.c1,t2.c2,t2.c3
Eg:
T1 has the below data:
c1 c2 c3
1 200 300
2 200 300
1 100 300
2 400 400
T2 has the below data:
c1 c2 c3
1 200 300
2 200 300
2 400 400
now i want the output like the below
c1 c2 c3 c1 c2 c3
1 200 300 1 200 300
2 200 300 2 200 300
1 100 300
2 400 400 2 400 400
Regards
Bond..Hi
you can use this
Select t1.c1,t1.c2,t1.c3,t2.c1,t2.c2,t2.c3
from table1 t1,table2 t2
where t1.c1 = t2.c1(+)
AND t1.c2 = t2.c2(+)
AND t1.c3 = t2.c3(+)
order by t1.c1,t2.c1
Regards
Ankur
Edited by: Garg on Dec 4, 2008 2:16 PM
Edited by: Garg on Dec 4, 2008 2:20 PM
Maybe you are looking for
-
IMovie '09 Won't Import HD Content from Sony HDR-SR11 Camcorder
Hi, iMovie stopped importing HD content from Sony HDR-SR11 camcorder. It only recognizes the standard definition content in the preview thumbnails. Previously this used to work with both a FireWire cable and a Mini USB. All of a sudden it doesn't imp
-
SEVERE: DB Error during import of BC_SL_ACTIVE_PARTS
Hello all, We are trying to perform the system refresh using sapinst (load based) on AIX/DB2 UDB environment. During the "Import Java Dump" phase, we are getting the below error; SEVERE: DB Error during import of BC_SL_ACTIVE_PARTS SEVERE: Message: T
-
Page Footer in subreport.
I need to have Page Footer in subreport. Now I have only Report Header, Detail and Report Footer in my subreport. How I can add Page Footer in subreport?
-
VL06P : BAPI/Function Module for PGI
Hi All, Anybody have the information about the BAPI/FM for doing PGI with VL06P for delivery. Thanks
-
Friends, Need your advise urgently.Please help us with ur suggestions. We have installed SAP Netweaver 2004s in Dev server. Currently we are planning to create three clients in that server and do the client copy. client 222 for Dev client 333 for San