SQL Query: How to search on a dynamic set of patterns?
Hello,
I have a requirement where I need to search a table with dynamic set of patterns. Here is something I am looking for:
select * from T1 where C1 LIKE 'AA%' or C1 LIKE 'BB%' ...
That is, the number of patterns is unknown, it could be 0 or 1 or more. I cannot use the IN clause because this requires exact match.
Can you please help in letting me know how to do this?
Thanks a lot
Dear,
+In your last statement you mentioned "like C2||'%'".
I can't use this because C2 is the name of a column in table T2.+
Did you try this and you got an error or you are "concluding you can't" use this because C2 is name of a column?
Please try it. If you run into error, please post the error and you query.
Also...
1. When posting code, use BEFORE and AFTER the code, to format it nicely. It makes it easier to read.
2. In you posting questions include sample table,data expected output and your attempt in solving the problem. this will make it easier on everyone to help sooner and more effectively.
Best way to learn, SQL programming is to try it out.
So please try the sample and the suggestion and let us know if you get any error.
vr
Sudhakar B.
Similar Messages
-
SQL Query (updateable report) Region - Conditionally Hide and Set Values
SQL Query (updateable report) Region - Conditionally Hide and Set Values
Outline of requirement :-
Master / Detail page with Detail updated on same page using SQL Query (updateable report).
The detail region has the following source
SELECT item_id,
contract_id,
CASE WHEN hardware_id IS NOT NULL THEN
'HA'
WHEN backup_dev_id IS NOT NULL THEN
'BD'
WHEN hardware_os_id IS NOT NULL THEN
'HS'
END item_type,
hardware_id,
backup_dev_id,
hardware_os_id
FROM "#OWNER#".support_items
WHERE contract_id = :P26_CONTRACT_IDThe table support_items implements arced relationships and has the following columns
CREATE TABLE SUPPORT_ITEMS
ITEM_ID NUMBER NOT NULL,
CONTRACT_ID NUMBER NOT NULL,
HARDWARE_ID NUMBER,
BACKUP_DEV_ID NUMBER,
HARDWARE_OS_ID NUMBER
)A check type constaint on support_items ensures that only one of the fk's is present.
( hardware_id IS NOT NULL
AND backup_dev_id IS NULL
AND hardware_os_id IS NULL
OR ( hardware_id IS NULL
AND backup_dev_id IS NOT NULL
AND hardware_os_id IS NULL
OR ( hardware_id IS NULL
AND backup_dev_id IS NULL
AND hardware_os_id IS NOT NULL
) Hardware_Id is a FK to Hardware_Assets
Backup_dev_id is a FK to Backup_Devices
Hardware_os_id is a FK to Hardware_op_systems
The Tabular Form Element based on item_type column of SQL query is Displayed As Select List (based on LOV) referencing a named list of values which have the following properties
Display Value Return Value
Hardware Asset HA
Backup Device BD
Computer System HSThe Tabular Form Elements for the report attributes for hardware_id, backup_dev_id and hardware_os_id are all Displayed As Select List (Based on LOV).
What I want to do is only display the Select List for the FK depending on the value of the Select List on Item Type, e.g.
Item_Type is 'HA' then display Select List for hardware_id, do not display and set to NULL the Select Lists for backup_dev_id and hardware_os_id.
Item_Type is 'BB' then display Select List for backup_dev_id, do not display and set to NULL the Select Lists for hardware_id and hardware_os_id.
Item_Type is 'HS' then display Select List for hardware_os_id, do not display and set to NULL the Select Lists backup_dev_id and hardware_id.
There are properties on elements to conditionally display it but how do we reference the values of the SQL query Updateable region? they are not given a page item name?
Also on the Tabular For Elements there is an Edit tick against a report item - however when you go to the Column Attributes there is not a property with which you can control the Edit setting.
What's the best way of implementing this requirement in APEX 3.1?
Thanks.>
Welcome to the forum: please read the FAQ and forum sticky threads (if you haven't done so already), and update your profile with a real handle instead of "user13515136".
When you have a problem you'll get a faster, more effective response by including as much relevant information as possible upfront. This should include:
<li>Full APEX version
<li>Full DB/version/edition/host OS
<li>Web server architecture (EPG, OHS or APEX listener/host OS)
<li>Browser(s) and version(s) used
<li>Theme
<li>Template(s)
<li>Region/item type(s) (making particular distinction as to whether a "report" is a standard report, an interactive report, or in fact an "updateable report" (i.e. a tabular form)
With APEX we're also fortunate to have a great resource in apex.oracle.com where we can reproduce and share problems. Reproducing things there is the best way to troubleshoot most issues, especially those relating to layout and visual formatting. If you expect a detailed answer then it's appropriate for you to take on a significant part of the effort by getting as far as possible with an example of the problem on apex.oracle.com before asking for assistance with specific issues, which we can then see at first hand.
I have a multi-row region that displays values and allows entries in a number of fields.Provide exact details of how this has been implemented. (An example on apex.oracle.com is always a good way to do this.)
I should like the fields to be conditional in that they do not permit entry, but still display, if certain conditions apply (e.g. older rows greyed out). Can this be done? Almost anything can be done, often in multiple ways. Which are appropriate may be dependent on a particular implementation, the skills available to implement it, and the effort you're willing to expend on it. Hence it's necessary to provide full details of what you've done so far... -
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 -
SQL query - how to get parameters into a function within a SELECT statement
Hi,
I have SQL query roughly as follows
SELECT A, B, C, MAX(CASE...) AS "D_NAME", FunctionX(B, C, "D_NAME")
FROM...
WHERE...
How to get alias "D_NAME" as a valid parameter into FunctionX?Hi,
user8819407 wrote:
Hi,
I have SQL query roughly as follows
SELECT A, B, C, MAX(CASE...) AS "D_NAME", FunctionX(B, C, "D_NAME")
FROM...
WHERE...
How to get alias "D_NAME" as a valid parameter into FunctionX?Either
(1) repeat the calculation or
(2) compute it in a sub-query
Here's an example of (2)
WITH got_d_name AS
SELECT A, B, C, MAX(CASE...) AS "D_NAME"
FROM...
WHERE...
SELECT A, B, C, D_NAME, FunctionX (B, C, D_NAME)
FROM got_d_name
;A column alias (like d_name) can be referenced in the ORDER BY clause of the query where it was defined, but that's the only place in that query where it can be referenced. -
SQL query execution in DB02 hangs if record set is more than 50000
Hi,
We are facing issue in a report performance. The return is using native SQL query.
There are custom views created ar database level for pricing/maetrial and stock. The native sql query is written on these views. The report takes around 15 mins to run in background .
We are trying to analyse the native SQL query through DB02. I tried fetching records for one particular
custom view to make out if its indexing issue or something else.When i using TOP 35000 records with select query runs fine with this dataset or less than this . If i increase it to 40000 system doesn;t show anything in SQL ouptut. And above one lakh records system gives timeout.
The count in this view gives some 10 lakh records which I don't feel is v.v.huge that query that too native sql takes so much time.
Any help on this will be highly appreciated.
Regards
Madhuwhat do you expect from that poor information.
do you change data or onyl select.
If you use SAP and ABAP, then you should also use Open SQL.
Otherwise it is possible to run the SQL Trace with Native SQL, it is anyway only Native SQL, what the trace sees.
Use package size and it will probably work fine.
Siegfried -
Help with the SQL Query: How to use case.
Q:- I have written a query which will written the following output.
C1 C2 C3
a ---- b.1 ---- 1
a ---- b.1 ---- 1
a ---- b.1 ---- 2
a ---- b.1 ---- 3
a ---- b.1 ---- 3
a ---- b.2 ---- 1
a ---- b.2 ---- 2
a ---- b.2 ---- 2
a ---- b.3 ---- 1
ac---- b.1 ---- 1
ac---- b.1 ---- 2
ac---- b.2 ---- 1
ac---- b.2 ---- 2
ac---- b.2 ---- 3
ac---- b.2 ---- 3
ac---- b ---- 1
But i want the output to print in the following way. Please suggest.
C1 C2 C3
a ---- b.1 ---- 1
------------------2
------------------3
a ---- b.2 ---- 1
------------------2
a ---- b.3 ---- 1
ac---- b.1 ---- 1
------------------2
ac---- b.2 ---- 1
------------------2
ac---- b.2 ---- 3
ac---- b ---- 1
Edited by: user555994 on Jan 18, 2011 1:42 AM
Edited by: user555994 on Jan 18, 2011 1:43 AMOr may be
SQL> ed
Wrote file afiedt.buf
1 WITH sample_data AS
2 (SELECT 'a' C1,'b.1' C2, 1 C3 FROM dual UNION ALL
3 SELECT 'a' C1,'b.1' C2, 1 C3 FROM dual UNION ALL
4 SELECT 'a' C1,'b.1' C2, 2 C3 FROM dual UNION ALL
5 SELECT 'a' C1,'b.1' C2, 3 C3 FROM dual UNION ALL
6 SELECT 'a' C1,'b.1' C2, 3 C3 FROM dual UNION ALL
7 SELECT 'a' C1,'b.2' C2, 1 C3 FROM dual UNION ALL
8 SELECT 'a' C1,'b.2' C2, 2 C3 FROM dual UNION ALL
9 SELECT 'a' C1,'b.2' C2, 2 C3 FROM dual UNION ALL
10 SELECT 'a' C1,'b.3' C2, 1 C3 FROM dual UNION ALL
11 SELECT 'ac' C1,'b.1' C2, 1 C3 FROM dual UNION ALL
12 SELECT 'ac' C1,'b.1' C2, 2 C3 FROM dual UNION ALL
13 SELECT 'ac' C1,'b.2' C2, 1 C3 FROM dual UNION ALL
14 SELECT 'ac' C1,'b.2' C2, 2 C3 FROM dual UNION ALL
15 SELECT 'ac' C1,'b.2' C2, 3 C3 FROM dual UNION ALL
16 SELECT 'ac' C1,'b.2' C2, 3 C3 FROM dual UNION ALL
17 SELECT 'ac' C1,'b' C2, 1 C3 FROM dual
18 )
19 SELECT
20 NVL2(LAG(C1) OVER (PARTITION BY C1,C2 ORDER BY C1,C2,C3),NULL,C1) C1
21 ,NVL2(LAG(C2) OVER (PARTITION BY C1,C2 ORDER BY C1,C2,C3),NULL,C2) C2
22 ,C3
23* FROM (SELECT DISTINCT c1,c2,c3 FROM sample_data)
SQL> /
C1 C2 C3
a b.1 1
2
3
a b.2 1
2
a b.3 1
ac b 1
ac b.1 1
2
ac b.2 1
2
C1 C2 C3
3
12 rows selected.
SQL> -
SQL query for formatted search
Hi guys and expertise,
I have this one problem where i need to do the formatted search,below is my example query that i have done
declare @itemcode varchar (20)
set @itemcode = (select x.itemcode from OITM x where x.ItemCode=[%])
declare @itmgrp varchar(50)
set @itmgrp=(select y.itmsgrpnam from OITB y where y.ItmsGrpNam=[%1])
select
CASE
when @itemcode = 'Item Descriptions 1' then @itmgrp
else t0.ItmsGrpNam
end
from OITB t0 inner join
OITM t1 on t0.ItmsGrpCod=t1.ItmsGrpCod
where t1.itemcode=@itemcode
***correct me if i'm wrong
the condition is :-
whenever the user selection is 'Item Descriptions 1' user will have to select the product group name else
if the user selection is not equal to "Item Descriptions 1", automatically the product group name will be default according
to the item code itself.
i wonder if it's possible? if it is, then i suppose there should be a way,right?Hi Gordon...
Thanks a lot for the answer,
I did try some research and manage to find a way out for the query that I want, the query is as below:-
BEGIN
IF
$[$38.1.0]='Item Descriptions' or $[$38.1.0]='Item Descriptions 1' or $[$38.1.0]='Item Descriptions 2' or
$[$38.1.0]='Item Descriptions 3' or $[$38.1.0]='Item Descriptions 4'
SELECT T0.ItmsGrpNam FROM OITB T0 inner join OITM T1 ON T0.ItmsGrpCod=T1.ItmsGrpCod
Group By T0.ItmsGrpNam
ELSE
SELECT T0.ItmsGrpNam FROM OITB T0 inner join OITM T1
ON T0.ItmsGrpCod=T1.ItmsGrpCod where T1.ItemCode=$[$38.1.0]
END
regards,
Asyraf -
SQL Query: How to pass list of values to the IN operator
Hi,
I'm trying to pass a list of values to the WHERE <a> IN <list>
I dont want to use dynamic cursors (REF CURSOR). Is this possible using Oracle SQL?
Please let me know.
My program:
DECLARE
list_of_ids := '10, 20, 30';
SELECT MAX(sal) INTO max_sal FROM employee WHERE emp_id IN (list_of_ids);
END;
Thanks in Advance,
NikoYou do not want to pass a comma separated list. You want to pass a collection. So
CREATE TYPE num_tbl
AS
TABLE OF NUMBER;
DECLARE
l_list_of_ids num_tbl := num_tbl( 10, 20, 30 );
BEGIN
SELECT max(sal)
INTO max_sal
FROM employee
WHERE emp_id IN (SELECT * FROM TABLE( l_list_of_ids ));
END;
/Justin -
SQL query to build search form
I have a table Department, with primary key DeptId.
Table: Department
DeptId Text
1 xx
2 yy
3 zz
I have another table Person, with key (not primary, and not unique) PersonId, and foreign key DeptId
Table: Person
PersonId DeptId
10 1
11 1
11 2
12 2
I want to build a search form, with search fields PersonId and DeptId, so that in the resulting table, some rows from the Department table are returned. It should obey the following:
- If both PersonId and DeptId are selected, and there is a row in the table Person that matches the selection, the row from the Department table should be returned.
- If only PersonId is selected, any row in Department table that matches a DeptId corresponding to that PersonId should be returned.
- If only DeptId is selected, return that row from Department exactly once (even if that DeptId doesn't appear in Person table, like DeptId 3 in this example)
- If neither is selected, return all rows from Department
I'm using JDeveloper 11.1.2.2.0.
Thanks,
ZachHi Navaneeth,
Taking the example from your link:
SELECT org.org_id, org.name FROM organisations org WHERE EXISTS
(SELECT 1 FROM events evt WHERE evt.org_id = org.org_id
AND evt.contact_name = 'Eddie Harris')
Let's say I make evt.contact_name a dropdown list, and when I query it, I leave it unselected. Would it return org.org_id, org.name from a row that has no corresponding event row? -
Query: how to search for bp which has no activities
Hello experts,
I have a query here where I get all BP with activities.
But now I should get all BP which have NO activities.
How can I get them with a query ? Has anybody an idea ?
Thanks Gerdstill not answered but I close it now.
-
SQL Query how to to get this Matrix report.
Hi All,
My tables are
Petty_cash_voucher P :- voucher_date,terminal_id,currency_code,account_code, amount
Terminal_master T :-
terminal_id,terminal_station_code
Ledger_codes L :- account_code,account_description,accound_main_head_code
Account_main_heads :-
Account_main_head_code, Main_head_description
im looking for a MATRIX WITH GROUP REPORT should look like this
1st group : CURRENCY
2nd Group : Main_head_description
Row field is : account_description
Column field is : Terminal_town_code
Matrix CELL is : total_amount.
here i should see all my terminal_towns though the transactuons existed or not for that day. letssay there are 22 terminals, but today i have 2 terminals only transactions, but i need to see 22 as columns with NULL values. and for ledgers, main_heads what ever existed only. Ex: i have 100 ledgers with 20 Main heds, but there is 2 only transactions happend, i should see 2 group by main_head with 2 terminsla having values remiaing termils with null values.
i wrote the query like this , but it is not giving all terminal codes , giving only values existed.
SELECT
P.currency_code,
T.terminal_town_code,
P.account_code,
L.account_description,
MH.account_main_head_description,
SUM(P.amount) total_amount
FROM
terminal_master T,
petty_cash_voucher_master P,
ledger_accounts L,
account_main_heads MH
WHERE
T.terminal_id = P.account_to_terminal (+)
AND
L.account_code (+) = P.account_code
AND
MH.account_main_head_code (+) = L.account_main_head_code
AND
P.voucher_date (+) > = '16-jun-05'
AND
P.voucher_date (+) < = '16-jun-05'
GROUP BY
P.currency_code,
T.terminal_town_code,
P.account_code,
L.account_description,
SH.account_main_head_description.
Thanks in advance.Hi all,
Im reactivating this, still im looking for help, giving here sample data.
Account Main Heads
Account_main_head_code, Main_head_description
01 ADMINSTRATIVE
02 OPERATIONAL
Ledger_codes account_code,account_description,accound_main_head_code
01 SALARIES 01
02 PHONES 01
03 FUEL 02
Terminal_master
Terminal_id,terminal_station_code
1 HYD
2 VJA
3 NY
4 WDC
Petty_cash_voucher voucher_date,terminal_id,currency_code,account_code,amount
30-jun-05 1 GBP 01 100
30-jun-05 2 GBP 01 200
30-jun-05 3 GBP 02 300
30-jun-05 4 GBP 03 250
Im looking for the MATRIX layout as follows :
GBP (first group)
ADMINISTRATIVE (secind group)
.................HYD.....VJA....NY ....WDC
Salaries.........100.....200.....0......0
Phones............0.......0.....300.....0
OPERATIONAL
.................HYD.....VJA....NY....WDC
Fuel..............0.......0.....0.....250
(terminals as columns, ledger description as Rows).
main thing is i need to get all the terminal as it is in any group. i have used ...'s to maintain alignment.
Thanks again. -
SQL QUERY How to write a sql query with a complex where clause.
I would like to get a list of all my invoices from the past year plus any open invoices that are more than a year old.
I don't want any overlapping rows.
Debra has a questionDebra,
Sorry but you have posted to a forum that deals exclusively with questions/issues about customizing and programming Microsoft Project, a planning and scheduling application. I suggest you delete this post and find a more appropriate forum.
John -
How to search file in application server using pattern
Hi all,
I want to search file in application server.
Suppose there is file named abc20090808.dat.
Is there is any function module to search the file?
it should return back the file names starting with abc, if the import parameter is abc*
Regards,
Nikhilhello,
Have a look
You can use this function module /SAPDMC/LSM_F4_SERVER_FILE for F4 help for application server file and then you can use the function module TEXT_CONVERT_XLS_TO_SAP to read data into internal table.
access file from application server
regards,
shweta -
Bex Query - How to capture characteristic value and set it as filter value?
Dear Experts,
I would like to create a tricky report that listed sales quantity by companis. Companies consists of production plant as well as trading company.
Company / Sales Quantity / Sales Quantity 2 (which produced by Company itself)
A / 100 / 50 (50 was produced by company A)
B / 80 / 0 (this is a trading company)
C / 150 / 150 (All are produced by company C)
First I thought of using variable to capture Company value and then under Sales Quantity 2 I set producing company = this variable. But this only works if I filter company values. Any workaround idea that I can get the above with all the listing of companies?
Any assistance would be great! Thanks!
JLHi,
Have you tried elimination of Internal business Volume?
http://help.sap.com/saphelp_bw32/helpdata/en/d5/784d3c596f0b26e10000000a11402f/content.htm
Impliment this solution by adding another KF Sales qty2. with ref. to Sales qty.
In characteristic pair you can have Company and Production Company(navigational attribute).
By implimenting this solution the system will eliminate if the quantity is produced by the company it self. You can create CKF in query to get the result you need.
Jaya -
hi all,
i created a report that displays results based on this query initially.
select *
from EMP
where 1=1;
i'm using a SQL Query (PL/SQL Function Body Returning SQL Query).
i have search items in my page like empno, lastname, firstname, middle, email_address etc... when i place a value for lastname then in my query it should add AND LASTNAME = :P1_LASTNAME.
so the query returned should now have
select *
from EMP
where 1=1
and LASTNAME = :P1_LASTNAME;
is this possible?
i was thinking something like looping for all search items in the page (ie. text, popup lov, datetimepicker) then check whether the item is null or not... when not null then probably get the substring of the item name like (ie. substr(:P1_LASTNAME) and get only LASTNAME then add "=" then concat it with the item name. not sure if this is possible though.
thanks
allenhi denes,
thanks for the sample... i noticed that the sample hard codes additional conditions to be added to the sql query which is okay when the search criteria is less than 5-10... but i'm thinking if the search criteria will be like 15-30 fields or make all fields searchable, this might be uncomfortable.
what i was thinking is like loop thru all the items i.e.
declare
sql varchar2(4000) := 'select * from emp where 1=1';
begin
for i in (select * from all_items_in_apex) -- this is just an example.
loop
if i.value is not null then
sql := sql || ' and ' || i.column || '=' || i.value;
end if;
end loop;
end;
the only thing is that i don't know if there's a possible replacement for the clause (select * from all_items_in_apex).
sorry if i'm asking too much but this is how i normally do it in forms. the suggestion in the link you provided should be sufficient but i was just wondering if this idea is also possible.
thanks again.
allen
Maybe you are looking for
-
Hi I'm a recent convert. I have a spreadsheet that I made in excel and want to use it on my new Ipad 2. I think I could email it to myself and open it as an attachment but I'm hoping that maybe I could import it through the Itunes that is on my PC. T
-
Using time capsule to share internet connection with a pc via ethernet
Hi, I've recently acquired a time capsule and was wondering if i could use it to share a wireless internet connection via ethernet to my non-wireless (windows 7) pc? My current situation is that i have a wireless modem/router that shares my internet
-
I have just released an App which has terrible font corruption on iPad1, the articles are PDF, but everything is perfect on iPad2+ Has anyone else had an issue like this? I'm hoping that re-building the app with .png will resolve the issue, although
-
MS Analysis Services and SAP BW
Hello! I need to solve the following problem: The data for analysis is kept in MS Analysis Services. That data must be exported from it to BW. But the primary task is to create appropriate InfoCubes in BW. Can that Infocubes be created in BW automati
-
Hello, Quite new to Oracle here.. Oracle 9.2.0.6 on hp UX 11i. I have an .exp file containing users, schemas and everything. Its a normal exp. Here is what I do. 1- I create an empty database called VPMTEST 2- I set the Oracle_SID to VPMTEST I log on