Compound Where Clause creating an OR -- POWERSHELL
What am I doing wrong here??
where {$_.'Number of Failures' -ge 1 -AND $_.showrepl_columns -ne 'showrepl_INFO'}
I need the above to be an OR not an AND statement. How do you do OR's in a compound where statement???
That is great but it is not working but maybe the issue is somewhere else. I could not find any reference to -OR so I figured that was wrong and the reason for the failure. If I just do where {$_.'Number of Failures' -ge 1} it works. Trying
to add in a second command and I think I just found my problem.
Later I have $results = $results | where {$_.'Number of Failures' -gt 1 }
I need to build upon that also!
What are your trying to OR. Say it in a plain english sentence using OR in the sentence. I suspoect you are ahving a logic crisis which comes from not understanding what logical operators are. Start with Bill's suggestion and then write
a sentence.
By the way. It is either greater then 1, equal to 1 OR less than 1. It cannot be any two of those things at the same time.
($x -ge 1 -OR $x -gt 1) makes very little sense. It is the same as the first clause so the second clause menas nothing and will never be used.
¯\_(ツ)_/¯
Similar Messages
-
WHERE clause creating a join for two or more tables
The CS3 Dreamweaver book says that the WHERE clause can
create a join for two or more tables. The join was created, but the
data is repeating. I have searched the web and this forum and have
not found the answer.
My Master page filters the recordset by Style No and when a
customer clicks on a particular style, it sends him to the Detail
page. All the records are showing from all tables on the detail
page from the Dynamic List, except they are showing multiple times
(ex. Size table has 4 sizes and Color table has 2 colors - my Size
Drop Down list is showing 8 options and my Color Drop Down List is
showing 8 options) I have a Master Page with a recordset pointing
to a Detail Page using the same recordset.
Master page works perfectly.
Master Recordset SQL:
SELECT products.itemID, products.category, products.styleno,
products.name, products.description, products.ourprice,
products.imageTH, products.image, coloroption.color,
sizeoption.size
FROM products, coloroption, sizeoption
WHERE category = 'chefcoats' AND
products.styleno=sizeoption.styleno AND
products.styleno=coloroption.styleno
GROUP BY products.styleno
ORDER BY styleno ASC
The Detail Recordset:
SELECT products.itemID, products.category, products.styleno,
products.name, products.description, products.ourprice,
products.imageTH, products.image, sizeoption.size,
coloroption.color
FROM products, sizeoption, coloroption
WHERE itemID=colname AND products.styleno=sizeoption.styleno
AND products.styleno=coloroption.styleno
I tried using the GROUP BY on the detail page, but then it
only showed one size and color from the dynamic drop down list. I
tried changing the field name "styleno" in the other tables to be
unique, however, I was using the table identifer. I tried using the
JOIN command instead of the WHERE clause and that didn't help
either.
On the detail page, the customer is supposed to click on the
Size box and see sizes XSM - 6XL ONLY ONE TIME. and then be able to
click on the Color option and see White, Black, Red ONE TIME.
Is this possible?
Thank you for giving your time to read this.!
EvieDo you have a link we can look at to see what you are trying
to do?
Dave
"EviePhillips" <[email protected]> wrote in
message
news:[email protected]...
> The CS3 Dreamweaver book says that the WHERE clause can
create a join for
two
> or more tables. The join was created, but the data is
repeating. I have
> searched the web and this forum and have not found the
answer.
>
> My Master page filters the recordset by Style No and
when a customer
clicks on
> a particular style, it sends him to the Detail page. All
the records are
> showing from all tables on the detail page from the
Dynamic List, except
they
> are showing multiple times (ex. Size table has 4 sizes
and Color table has
2
> colors - my Size Drop Down list is showing 8 options and
my Color Drop
Down
> List is showing 8 options) I have a Master Page with a
recordset pointing
to a
> Detail Page using the same recordset.
>
> Master page works perfectly.
> Master Recordset SQL:
> SELECT products.itemID, products.category,
products.styleno,
products.name,
> products.description, products.ourprice,
products.imageTH, products.image,
> coloroption.color, sizeoption.size
> FROM products, coloroption, sizeoption
> WHERE category = 'chefcoats' AND
products.styleno=sizeoption.styleno AND
> products.styleno=coloroption.styleno
> GROUP BY products.styleno
> ORDER BY styleno ASC
>
> The Detail Recordset:
> SELECT products.itemID, products.category,
products.styleno,
products.name,
> products.description, products.ourprice,
products.imageTH, products.image,
> sizeoption.size, coloroption.color
> FROM products, sizeoption, coloroption
> WHERE itemID=colname AND
products.styleno=sizeoption.styleno AND
> products.styleno=coloroption.styleno
>
> I tried using the GROUP BY on the detail page, but then
it only showed
one
> size and color from the dynamic drop down list. I tried
changing the
field
> name "styleno" in the other tables to be unique,
however, I was using the
table
> identifer. I tried using the JOIN command instead of the
WHERE clause and
that
> didn't help either.
>
> On the detail page, the customer is supposed to click on
the Size box and
see
> sizes XSM - 6XL ONLY ONE TIME. and then be able to click
on the Color
option
> and see White, Black, Red ONE TIME.
>
> Is this possible?
>
> Thank you for giving your time to read this.!
> Evie
>
> -
Performance - composite index with 'OR' in 'WHERE' clause
I have a problem with the performance of the following query:
select /*+ index_asc(omschact oma_index1) */ knr, projnr, actnr from omschact where ((knr = 100 and actnr > 30) or knr > 100)
and rownum = 1;
(rownum used only for test purpose)
index:
create index on omschact (knr, projnr);
Execution plan:
Id Operation
0 SELECT STATEMENT
1 COUNT STOPKEY
2 TABLE ACCESS BY INDEX ROWID
3 INDEX FULL SCAN
If I'm correct, the 'OR' in the 'WHERE' clause is responsible for the INDEX FULL SCAN, what makes the query slow.
A solution would be then to separate the 'WHERE' clause in 2 separate select's (1 with 'knr = 100 and actnr > 30' and 1 with 'knr > 100' and combine the results with a UNION ALL.
Since it's necessary to have all rows in ascending order (oma_index1) I still have to use an ORDER BY to make sure the order of the rows is correct. This results again in a (too) low performance.
Another solution that does the trick is to create an index with the 2 fields (knr, projnr) concatenated and to use the same in the 'WHERE' clause:
create index oma_index2 on omschact (knr || projnr);
select /*+ index_asc(omschact oma_index2) */ knr, projnr, actnr from omschact where (knr || projnr) > 10030;
I just can't believe this work-around is the only solution, so I was hoping that someone here knows of a better way to solve this.padders,
I'll give the real data instead of the example. The index I really use consists of 4 fields. In this table the fields are just numbers, but in other tables I need to use char-fields in indexes, so that's why I concatenate instead of using formula's (allthough I would prefer the latter).
SQL> desc omschact
Name Null? Type
KNR NOT NULL NUMBER(8)
PROJNR NOT NULL NUMBER(8)
ACTNR NOT NULL NUMBER(8)
REGELNR NOT NULL NUMBER(3)
REGEL CHAR(60)
first methode:
SQL> create index oma_key_001(knr,projnr,actnr,regelnr);
Index created.
SQL> select /*+ index_asc(omschact oma_key_001) */ * from omschact where
2 (knr > 100 or
3 (knr = 100 and projnr > 30) or
4 (knr = 100 and projnr = 30 and actnr > 100000) or
5 (knr = 100 and projnr = 30 and actnr = 100000 and regelnr >= 0));
Execution Plan
Plan hash value: 1117430516
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 11M| 822M| 192K (1)| 00:38:26 |
| 1 | TABLE ACCESS BY INDEX ROWID| OMSCHACT | 11M| 822M| 192K (1)| 00:38:26 |
|* 2 | INDEX FULL SCAN | OMA_KEY_001 | 11M| | 34030 (1)| 00:06:49 |
Predicate Information (identified by operation id):
2 - filter("KNR">100 OR "KNR"=100 AND "PROJNR">30 OR "KNR"=100 AND "PROJNR"=30
AND "ACTNR">100000 OR "ACTNR"=100000 AND "KNR"=100 AND "PROJNR"=30 AND
"REGELNR">=0)
second method (same index):
SQL> select * from (
2 select /*+ index_asc(omschact oma_key_001) */ * from omschact where knr > 100
3 union all
4 select /*+ index_asc(omschact oma_key_001) */ * from omschact where knr = 100 and projnr > 30
5 union all
6 select /*+ index_asc(omschact oma_key_001) */ * from omschact where knr = 100 and projnr = 30 and actnr > 100000
7 union all
8 select /*+ index_asc(omschact oma_key_001) */ * from omschact where knr = 100 and projnr = 30 and actnr = 100000 and regelnr > 0)
9 order by knr, projnr, actnr, regelnr;
Execution Plan
Plan hash value: 292918786
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 11M| 1203M| | 477K (1)| 01:35:31 |
| 1 | SORT ORDER BY | | 11M| 1203M| 2745M| 477K (1)| 01:35:31 |
| 2 | VIEW | | 11M| 1203M| | 192K (1)| 00:38:29 |
| 3 | UNION-ALL | | | | | | |
| 4 | TABLE ACCESS BY INDEX ROWID| OMSCHACT | 11M| 822M| | 192K (1)| 00:38:26 |
|* 5 | INDEX RANGE SCAN | OMA_KEY_001 | 11M| | | 33966 (1)| 00:06:48 |
| 6 | TABLE ACCESS BY INDEX ROWID| OMSCHACT | 16705 | 1272K| | 294 (1)| 00:00:04 |
|* 7 | INDEX RANGE SCAN | OMA_KEY_001 | 16705 | | | 54 (0)| 00:00:01 |
| 8 | TABLE ACCESS BY INDEX ROWID| OMSCHACT | 47 | 3666 | | 4 (0)| 00:00:01 |
|* 9 | INDEX RANGE SCAN | OMA_KEY_001 | 47 | | | 3 (0)| 00:00:01 |
| 10 | TABLE ACCESS BY INDEX ROWID| OMSCHACT | 1 | 78 | | 4 (0)| 00:00:01 |
|* 11 | INDEX RANGE SCAN | OMA_KEY_001 | 1 | | | 3 (0)| 00:00:01 |
Predicate Information (identified by operation id):
5 - access("KNR">100)
7 - access("KNR"=100 AND "PROJNR">30)
9 - access("KNR"=100 AND "PROJNR"=30 AND "ACTNR">100000)
11 - access("KNR"=100 AND "PROJNR"=30 AND "ACTNR"=100000 AND "REGELNR">0)
third method:
SQL> create index oma_test(to_char(knr,'00000000')||to_char(projnr,'00000000')||to_char(actnr,'00000000')||to_char(regelnr,'000'));
Index created.
SQL> select /*+ index_asc(omschact oma_test) */ * from omschact where
2 (to_char(knr,'00000000')||to_char(projnr,'00000000')||
3 to_char(actnr,'00000000')||to_char(regelnr,'000')) >=
4 (to_char(100,'00000000')||to_char(30,'00000000')||
5* to_char(100000,'00000000')||to_char(0,'000'))
Execution Plan
Plan hash value: 424961364
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 553K| 55M| 1712 (1)| 00:00:21 |
| 1 | TABLE ACCESS BY INDEX ROWID| OMSCHACT | 553K| 55M| 1712 (1)| 00:00:21 |
|* 2 | INDEX RANGE SCAN | OMA_TEST | 99543 | | 605 (1)| 00:00:08 |
Predicate Information (identified by operation id):
2 - access(TO_CHAR("KNR",'00000000')||TO_CHAR("PROJNR",'00000000')||TO_CHAR("
ACTNR",'00000000')||TO_CHAR("REGELNR",'000')>=TO_CHAR(100,'00000000')||TO_CHAR(3
0,'00000000')||TO_CHAR(100000,'00000000')||TO_CHAR(0,'000')) -
Performance with dates in the where clause
Performance with dates in the where clause
CREATE TABLE TEST_DATA
FNUMBER NUMBER,
FSTRING VARCHAR2(4000 BYTE),
FDATE DATE
create index t_indx on test_data(fdata);
query 1: select count(*) from TEST_DATA where trunc(fdate) = trunc(sysdate);
query 2: select count(*) from TEST_DATA where fdate between trunc(sysdate) and trunc(SYSDATE) + .99999;
query 3: select count(*) from TEST_DATA where fdate between to_date('21-APR-10', 'dd-MON-yy') and to_date('21-APR-10 23:59:59', 'DD-MON-YY hh24:mi:ss');
My questions:
1) Why isn't the index t_indx used in Execution plan 1?
2) From the execution plan, I see that query 2 & 3 is better than query 1. I do not see any difference between execution plan 2 & 3. Which one is better?
3) I read somewhere - "Always check the Access Predicates and Filter Predicates of Explain Plan carefully to determine which columns are contributing to a Range Scan and which columns are merely filtering the returned rows. Be sceptical if the same clause is shown in both."
Is that true for Execution plan 2 & 3?
3) Could some one explain what the filter & access predicate mean here?
Thanks in advance.
Execution Plan 1:
SQL> select count(*) from TEST_DATA where trunc(fdate) = trunc(sysdate);
COUNT(*)
283
Execution Plan
Plan hash value: 1486387033
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1 | 9 | 517 (20)| 00:00:07 |
| 1 | SORT AGGREGATE | | 1 | 9 | | |
|* 2 | TABLE ACCESS FULL| TEST_DATA | 341 | 3069 | 517 (20)| 00:00:07 |
Predicate Information (identified by operation id):
2 - filter(TRUNC(INTERNAL_FUNCTION("FDATE"))=TRUNC(SYSDATE@!))
Note
- dynamic sampling used for this statement
Statistics
4 recursive calls
0 db block gets
1610 consistent gets
0 physical reads
0 redo size
412 bytes sent via SQL*Net to client
380 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
Execution Plan 2:
SQL> select count(*) from TEST_DATA where fdate between trunc(sysdate) and trunc(SYSDATE) + .99999;
COUNT(*)
283
Execution Plan
Plan hash value: 1687886199
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1 | 9 | 3 (0)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | 9 | | |
|* 2 | FILTER | | | | | |
|* 3 | INDEX RANGE SCAN| T_INDX | 283 | 2547 | 3 (0)| 00:00:01 |
Predicate Information (identified by operation id):
2 - filter(TRUNC(SYSDATE@!)<=TRUNC(SYSDATE@!)+.9999884259259259259259
259259259259259259)
3 - access("FDATE">=TRUNC(SYSDATE@!) AND
"FDATE"<=TRUNC(SYSDATE@!)+.999988425925925925925925925925925925925
9)
Note
- dynamic sampling used for this statement
Statistics
7 recursive calls
0 db block gets
76 consistent gets
0 physical reads
0 redo size
412 bytes sent via SQL*Net to client
380 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows
Execution Plan 3:
SQL> select count(*) from TEST_DATA where fdate between to_date('21-APR-10', 'dd-MON-yy') and to_dat
e('21-APR-10 23:59:59', 'DD-MON-YY hh24:mi:ss');
COUNT(*)
283
Execution Plan
Plan hash value: 1687886199
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1 | 9 | 3 (0)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | 9 | | |
|* 2 | FILTER | | | | | |
|* 3 | INDEX RANGE SCAN| T_INDX | 283 | 2547 | 3 (0)| 00:00:01 |
Predicate Information (identified by operation id):
2 - filter(TO_DATE('21-APR-10','dd-MON-yy')<=TO_DATE('21-APR-10
23:59:59','DD-MON-YY hh24:mi:ss'))
3 - access("FDATE">=TO_DATE('21-APR-10','dd-MON-yy') AND
"FDATE"<=TO_DATE('21-APR-10 23:59:59','DD-MON-YY hh24:mi:ss'))
Note
- dynamic sampling used for this statement
Statistics
7 recursive calls
0 db block gets
76 consistent gets
0 physical reads
0 redo size
412 bytes sent via SQL*Net to client
380 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processedHi,
user10541890 wrote:
Performance with dates in the where clause
CREATE TABLE TEST_DATA
FNUMBER NUMBER,
FSTRING VARCHAR2(4000 BYTE),
FDATE DATE
create index t_indx on test_data(fdata);Did you mean fdat<b>e</b> (ending in e)?
Be careful; post the code you're actually running.
query 1: select count(*) from TEST_DATA where trunc(fdate) = trunc(sysdate);
query 2: select count(*) from TEST_DATA where fdate between trunc(sysdate) and trunc(SYSDATE) + .99999;
query 3: select count(*) from TEST_DATA where fdate between to_date('21-APR-10', 'dd-MON-yy') and to_date('21-APR-10 23:59:59', 'DD-MON-YY hh24:mi:ss');
My questions:
1) Why isn't the index t_indx used in Execution plan 1?To use an index, the indexed column must stand alone as one of the operands. If you had a function-based index on TRUNC (fdate), then it might be used in Query 1, because the left operand of = is TRUNC (fdate).
2) From the execution plan, I see that query 2 & 3 is better than query 1. I do not see any difference between execution plan 2 & 3. Which one is better?That depends on what you mean by "better".
If "better" means faster, you've already shown that one is about as good as the other.
Queries 2 and 3 are doing different things. Assuming the table stays the same, Query 2 may give different results every day, but the results of Query 3 will never change.
For clarity, I prefer:
WHERE fdate >= TRUNC (SYSDATE)
AND fdate < TRUNC (SYSDATE) + 1(or replace SYSDATE with a TO_DATE expression, depending on the requirements).
3) I read somewhere - "Always check the Access Predicates and Filter Predicates of Explain Plan carefully to determine which columns are contributing to a Range Scan and which columns are merely filtering the returned rows. Be sceptical if the same clause is shown in both."
Is that true for Execution plan 2 & 3?
3) Could some one explain what the filter & access predicate mean here?Sorry, I can't. -
User Defined function in Where clause
DB:- 11.2
Input:- 'ACCOUNTING,SALES'
Output:- ('ACCOUNTING','SALES')
WITH T AS (select 'ACCOUNTING,SALES' str from dual)
select '('||regexp_replace(str,'([[:alpha:]]+)','''\1''')||')' from t /*this works*/I've created a function to use this in a where clause
create or replace function ss(dname varchar2)
return varchar2 is
begin
RETURN '('||regexp_replace(dname,'([[:alpha:]]+)','''\1''')||')';
end;
select ss('ACCOUNTING,SALES') from dual --this worksBut when I am using this function in a where clause result is not coming..any thing i am missing?
select * from dept where dname in ss('ACCOUNTING,SALES') --no rows940838 wrote:
Output:- ('ACCOUNTING','SALES')Wrong. ('ACCOUNTING','SALES') is a list of two strings 'ACCOUNTING' and 'SALES' while your function returns a single string '(''ACCOUNTING'',''SALES'')'.
IN clause requires a comma-separated list of values while your function, again, returns just one value. So query is comparing 'SALES' whith '(''ACCOUNTING'',''SALES'')', not with ('ACCOUNTING','SALES') and obviously no match. What you are trying to do is called dynamic SQL. There are plenty examples on how to use it. But you don't need it. Use nested table or varray. I'll use Oracle supplied varray type sys.OdciVarchar2List:
select *
from dept
where dname in (
select *
from table(sys.OdciVarchar2List('ACCOUNTING','SALES'))
DEPTNO DNAME LOC
10 ACCOUNTING NEW YORK
30 SALES CHICAGO
SQL>SY. -
Dynamic WHERE Clause in a Calendar
I would like to have a Calendar display values based on a dynamic WHERE clause created using PL/SQL anonymous block evaluating the values of items that the user uses as filters. I have done this dynamic SQL for reports and would lke to do the same for a Calendar.
I figured out how to do this.
I created a Hidden Item with the source value of &APP_USER.
named P50_APP_USER.
This is how my query looks now:
SELECT * FROM APX_EVENT WHERE APX_EVENT.STORE_NR IN (SELECT APX_Z.STORE_NR FROM APX_Z WHERE APX_Z.USERNAME = :P50_APP_USER)
And it works.
I got the answer from this thread:
CALENDAR - SQL ORDER BY CLAUSE NOT WORKING -
Creating a where clause in the LOV query box
Hi guys is any able to help me with this one
i have a page in my app where there is a LOV drop down now the values for this drop down comes from a table that looks like this
users_for _form_TBL
E_MAIL
Vendor
[email protected]
oracle
[email protected]
sap
[email protected]
IBM
[email protected]
Oracle
[email protected]
intergraph
So my syntax for the LOV i mentioned looks like this
select VENDOR as display_value, VENDOR as return_value
from form_user_tab where E_MAIL = :APP_USER
order by 1 ;
so if [email protected] logs onto the app and has to make a selection on the LOV it would only display the vendors relative to his E_MAIL like oracle ,sap, IBM then he hits the submit button on the page then the vendor that he selected is inserted into another table .What i did on the insert table was create a trigger that after a vendor is inserted the trigger inserts a 1 into a column called assessed .
What i did after this was add a select in the where clause of the LOV so that it would check in the insert table if that vendor had been chosen before and not display it again to be selected my syntax the second time around in the SQL query box was
select VENDOR as display_value, VENDOR as return_value
from users_for _form_TBL where E_MAIL = :APP_USER
and (select 'vendor' , 'ASSESSD' from inserted _tbl_imp is null);
order by 1 ;
But im getting an error any ideas guys .Thank youHay man thanks for that info on the Tom Kyte Blog
--(the code you gave me )
select
u.vendor display_value
, u.vendor return_value
from
users_for_form_tbl u
where
u.e_mail = :app_user
and not exists (select null from inserted_tbl_imp i where u.vendor = i.vendor)
order by
u.vendor
--(After the error i tried )Then when i got the error i try'd using 'or exists' like this
--(code)
where
u.e_mail = :app_user
and not exists (select null from inserted_tbl_imp i where u.vendor = i.vendor)
or exists (select null from inserted_tbl_imp i where u.vendor = i.vendor)
order by
u.vendor
But the all the vendors that where in the same in the insert table came up in the drop down list example is oracle was assessed before then only oracle would appear in the drop down list and if it was assessed 3 times it would come up 3 times
--Then i tried to select where 'Assessed' is null ('Assessed' is a column in the insert table which i created a trigger on to insert 1 in the 'ASSESSED' column when a vendor is begin assessed )
--(code)
where
u.e_mail = :app_user
and not exists (select 'ASSESSED' from inserted_tbl_imp i where 'ASSESSED' is null )
order by
u.vendor
This try didnt return any vendors at all
--Then i tried distinct
--(code)
where
u.e_mail = :app_user
and not exists (select distinct 'VENDOR', from inserted_tbl_imp i where u.vendor = i.vendor)
order by
u.vendor
This gave me a LOV ERROR
This is what i have tried so far there where others syntax's i tried last night as well but most of them came back as errors . Thanks again for you time and help fac586 -
How to create a procedure to output REF CURSOR with any WHERE clause?
I have an requirement like this: I have huge query which need to reuse in my code more than 10 times. This SQL has about 50 lines. Thing is for those 10 odd times sometimes the WHERE clause changes (columns are the same). So I cannot create a view since SQL is not static.
I thought of writing a procedure with a WHERE_CLAUSE input para. I output a sys refcursor by adding the where clause. But I can't do it since you cannot add a where clause like that.
i.e.
PROCEDURE dynamyic_query (p_where_clause IN VARCHAR2, p_out_query OUT SYS_REFCURSOR ) IS
BEGIN
OPEN p_out_query FOR SELECT ......... FROM table WHERE || ' ' || p_where_clause;
END;The above gives error.
How to handle a situation like this???? Any help would be greatly appreciated.I tried this method:
I created a table tab_test which has these records:
TNAME TABTYPE CLUSTERID
ABS_V4_P_ERROR_MESSAGES TABLE
ABS_V4_P_ORG_PARAM TABLE
ABS_V4_P_PARAMETER TABLE
ABS_V4_P_SYS_PARAM TABLE
ACCINTERFACE_PARAMETERS TABLE
ACCOUNTS TABLE
ACCOUNT_EXTRACT_PERIODS TABLE
ACCOUNT_EXTRACT_PERIODS# TABLE
ACCOUNT_EXTRACT_PERIODS_1 TABLE Now I create this proc:
PROCEDURE FORMS_TEXT_DYN_SQL_TEST(p_where_cluase IN VARCHAR2, p_out_cursor OUT SYS_REFCURSOR) IS
v_stmt VARCHAR2(1000);
BEGIN
v_stmt := 'SELECT tname FROM tab_test WHERE tname LIKE ''%ABS_V4%'' AND tabtype = :x';
OPEN p_out_cursor FOR v_stmt using p_where_cluase;
END;I create this code block and run it:
declare
v_tname varchar2(200);
out_cursor sys_refcursor;
begin
forms_text_dyn_sql_test('TABLE', out_cursor );
LOOP
fetch out_cursor INTO v_tname;
exit when out_cursor%NOTFOUND;
DBMS_OUTPUT.PUT_LINE(v_tname);
END LOOP;
end;
/I get correct output:
ABS_V4_P_ERROR_MESSAGES
ABS_V4_P_ORG_PARAM
ABS_V4_P_PARAMETER
ABS_V4_P_SYS_PARAMHowever, when I change the proc like this:
PROCEDURE FORMS_TEXT_DYN_SQL_TEST(p_where_cluase IN VARCHAR2, p_out_cursor OUT SYS_REFCURSOR) IS
v_stmt VARCHAR2(1000);
BEGIN
v_stmt := 'SELECT tname FROM tab_test WHERE tname LIKE ''%ABS_V4%'' AND :y';
OPEN p_out_cursor FOR v_stmt using p_where_cluase;
END;And run this code block:
declare
v_tname varchar2(200);
out_cursor sys_refcursor;
begin
forms_text_dyn_sql_test(' 1 = 1 ', out_cursor );
LOOP
fetch out_cursor INTO v_tname;
exit when out_cursor%NOTFOUND;
DBMS_OUTPUT.PUT_LINE(v_tname);
END LOOP;
end;
/I get error:
[1]: (Error): ORA-00920: invalid relational operator ORA-06512: at "ABS.FORMS_TEXT_DYN_SQL_TEST", line 6 ORA-06512: at line 5Looks like you can only put column_name = :z, column_name = :y type values. You cannot it seems replace it with any WHERE CLAUSE???? -
Creating WHERE clause for an outer join using DatabaseFilter
Hi all,
I read a post on thie group about constructing the WHERE clause for a RowSet Controls
SQL Query using the DatabaseFilter and this is what it said:
****************************************************************************The
following example shows adding part of a WHERE clause in an action method of a
page flow:
DatabaseFilter.FilterTerm term = new DatabaseFilter.FilterTerm(); term.sColumnName
= "name"; term.op = DatabaseFilter.opContains; // there are ops for equals, less
than, etc... term.value = form.getPartialName();
// You can also add sort terms for an ORDER BY clause allNames = dbControl.getNames(new
DatabaseFilter(new DatabaseFilter.FilterTerm[] {term}, null));
I am trying to create a where clause which uses a join like this:
Select * from x,y where x.id=y.id (+)
ie. All values from x.id but only corrosponding ones from y.id.
Is there any way to build this outer join query using the DatabaseFilter class
or am i forced to use a String which is contruct in my page flow as the where
clause?like so:
* @jc:sql command-type="grid"
* rowset-name="RFPSRowSet"
* max-rows="1000"
* statement::
* SELECT RFPS.RFP_ID,RFPS.NAME AS RFP_NAME,RFPS.FFO_NUMBER,RFPS.RFP_TYPE,RFPS.CFDA_NUMBER,COMPETITIONS.NAME
AS COMP_NAME,COMPETITIONS.COMPETITION_ID FROM RFPS,COMPETITIONS WHERE {sql: whereClause
} {sql: filter.getOrderByClause ()}
public RowSet getAllRfps(java.lang.String whereClause,DatabaseFilter filter)
throws SQLException;
and in my pageFlow action, i do the following:
StringBuffer whereClause= new StringBuffer();
whereClause.append("RFPS.RFP_ID = COMPETITIONS.RFP_ID (+)");
if ((form.getRfpTitle() != null) &&
(!form.getRfpTitle().equalsIgnoreCase("")))
whereClause.append(" AND UPPER(RFPS.NAME) LIKE %"+form.getRfpTitle().toUpperCase());
if ((form.getCfdaNumber() != null) &&
(!form.getCfdaNumber().equalsIgnoreCase("")))
whereClause.append(" AND RFPS.CFDA_NUMBER ="+form.getCfdaNumber());
if ((form.getFfoNumber() != null) &&
(!form.getFfoNumber().equalsIgnoreCase("")))
whereClause.append(" AND RFPS.FFO_NUMBER ="+form.getFfoNumber());
sortFilterService = SortFilterService.getInstance(getRequest());
DatabaseFilter filter=sortFilterService.getDatabaseFilter(getGridName());
log.debug("***********"+whereClause.toString()+"***********");
allRows = searchRfaAndComp.getAllRfps(whereClause.toString(),filter);
Thanks in advance for your help,
Regards,
Vik.Thanks for your reply. Just one more question....if we indeed are trying to use
a simple query and have a where clause like "select * from x where upper(x) like
{x}", how do we set the UPPER filter on the column using the database filter?
I see a IDENTIFIER.ISUPPER static field on that DatabaseFilter but am unsure how
to use it. Would appreciate any pointers .
Thanks again,
Vik
Eddie O'Neil <[email protected]> wrote:
Vik--
I believe that the approach that you describe below is the best one
for dealing with outer joins
with the DatabaseFilter.
Apologies for the limitation...
Eddie
vik wrote:
Hi all,
I read a post on thie group about constructing the WHERE clause fora RowSet Controls
SQL Query using the DatabaseFilter and this is what it said:
****************************************************************************The
following example shows adding part of a WHERE clause in an actionmethod of a
page flow:
DatabaseFilter.FilterTerm term = new DatabaseFilter.FilterTerm(); term.sColumnName
= "name"; term.op = DatabaseFilter.opContains; // there are ops forequals, less
than, etc... term.value = form.getPartialName();
// You can also add sort terms for an ORDER BY clause allNames = dbControl.getNames(new
DatabaseFilter(new DatabaseFilter.FilterTerm[] {term}, null));
I am trying to create a where clause which uses a join like this:
Select * from x,y where x.id=y.id (+)
ie. All values from x.id but only corrosponding ones from y.id.
Is there any way to build this outer join query using the DatabaseFilterclass
or am i forced to use a String which is contruct in my page flow asthe where
clause?like so:
* @jc:sql command-type="grid"
* rowset-name="RFPSRowSet"
* max-rows="1000"
* statement::
* SELECT RFPS.RFP_ID,RFPS.NAME AS RFP_NAME,RFPS.FFO_NUMBER,RFPS.RFP_TYPE,RFPS.CFDA_NUMBER,COMPETITIONS.NAME
AS COMP_NAME,COMPETITIONS.COMPETITION_ID FROM RFPS,COMPETITIONS WHERE{sql: whereClause
sql: filter.getOrderByClause ()}* ::
public RowSet getAllRfps(java.lang.String whereClause,DatabaseFilter
filter)
throws SQLException;
and in my pageFlow action, i do the following:
StringBuffer whereClause= new StringBuffer();
whereClause.append("RFPS.RFP_ID = COMPETITIONS.RFP_ID (+)");
if ((form.getRfpTitle() != null) &&
(!form.getRfpTitle().equalsIgnoreCase("")))
whereClause.append(" AND UPPER(RFPS.NAME) LIKE %"+form.getRfpTitle().toUpperCase());
if ((form.getCfdaNumber() != null) &&
(!form.getCfdaNumber().equalsIgnoreCase("")))
whereClause.append(" AND RFPS.CFDA_NUMBER ="+form.getCfdaNumber());
if ((form.getFfoNumber() != null) &&
(!form.getFfoNumber().equalsIgnoreCase("")))
whereClause.append(" AND RFPS.FFO_NUMBER ="+form.getFfoNumber());
sortFilterService = SortFilterService.getInstance(getRequest());
DatabaseFilter filter=sortFilterService.getDatabaseFilter(getGridName());
log.debug("***********"+whereClause.toString()+"***********");
allRows = searchRfaAndComp.getAllRfps(whereClause.toString(),filter);
Thanks in advance for your help,
Regards,
Vik. -
"create columns with a where clause" in BMM
Hi All,
I have a question about OBI EE Meta data layer.
We have OBIEE sitting on a Data Warehouse with a star schema.
Our Fact table holds the following fields...
EmployeeID
CompanyID
Measure ID
Measure Name
MEASURE
This is what we have in the physical layer, BMM layer and the presentation layer but I want to be able to "create columns with a where clause"
So my fact table in the presentation layer would look like this
Amount Sold
Unit Cost
Company Amount
I thought I could just create a logical column with
Amount Sold = Measure
where Measure Name = "Amount Sold"
But I can't seem to find any to do that.
Any ideas?
ThanksOr you simply map your measure in the Logical Table source as something like :
CASE WHEN MEASURE_NAME = 'Amount Sold' THEN MEASURE ELSE 0 END.
You need to decide if you want the where clause adding in the Logical table source (be careful you will need a seperate LTS for each measure, this will mean more than one SQL being fired when you have more than one measure in the report).
Or you go with this case method on each measure, be able to have all the measures mapped in 1 LTS, include all those in the report and they will be retrieved by one SQL block. -
Create a view with a changing where clause
Hi all,
i'm developing an application with oracle forms i want to create a view in the database with a different where clause in every time , the where clause is determined due to the department id of the current user .
thanks alot.SQL> create view emp_view as select empno, ename, deptno from emp;
View created.
SQL> select * from emp_view where deptno = 10;
EMPNO ENAME DEPTNO
7782 CLARK 10
7839 KING 10
7934 MILLER 10
SQL> -
Creating LOV with Where clause
I'm trying to create a list of values from a select statementsomething like this
select customer_name, customer_number from customer
where Region = 'WEST';
I'm able to create a list of values of all the customers and numbers, but I could not
create a lov for a specific subset of that data, such as in the where clause.
Is it possible to create a LOV with a where clause?Use bind variables to accept the region parameter. Also, it is good practice to accept a null parameter value. If your parameter is null, display the entire list of values. Your query would look something like this:
select customer_name, customer_number from customer
where Region = :region_name or
:region_name is null;
Regards,
Jay Mason -
How to create VO with multiple dynamic where clauses on select with UNION?
I am trying to implement the View Object for the UNION query that looks like this:
select a,b,c...
from t1,t2,...
where dynamic_where_clause1
union all
select a,b,c,...
from t11,t12, ...
where dynamic_where_clause2
There are up to 60 input parameters that are used to generate dynamic where clauses. They are actually created by calling PL SQL function.
So far, I was not able to assign both where clauses to the view object. Is there a workable solution for this problem, besides resorting to programmatic View Object?
I understand that recommended way with UNIONs is to wrap both queries into a parent select:
select * from (
select a,b,c...
from t1,t2,...
where ... -- table relationship joints
union all
select a,b,c,...
from t11,t12, ...
where ... -- table relationship joints
) QRSLT
where dynamic_where_clause
Unfortunately this approach doesn't work here, since individual selects are producing unmanageable amount of data and resulting query takes forever to complete.I afraid I would not have any real benefits from using VO if I replace the entire query with every request. Actually, the performance may suffer.
I solved the problem by creating a POJO Data Control and invoking the custom select query from java. Not sure if it is the best approach to the problem, but implementation time is limited and it works.
Actually, this is not the first time I see the need to implement VO with complicated SQL like select with unions and dynamic pieces. It would be nice to find a solution and not resort to workarounds.
Edited by: viksicom on Aug 2, 2012 8:48 AM -
Creating dynamic where clause with string delimiter " ; "
hi...
i need a solution for complex problem like, 1. start_date IN date,
end_date IN date,
shift_type IN varchar2
i will get shift_type as "first_shift" or "first_shift;second_shift" or "first_shift;second_shift;third_shift" ....etc any combination. where fist & second & third shits are nothing but 1 , 2 , 3. i need to find out data between start_date and end_date in combination of shifts ( may be 1;2 or 1;3 or 1;2;3 or 2;3 ...etc) . now i need to write this code in dynamic where clause ...i tried in different ways...but not succeeded. can anybody guide me step by step...or with script.
NOTE: there is a table called "shift" with data like
shift_type shift_mode
1 first_shift
2 second_shift
3 third_shiftHi,
Whenever you have a problem, post a little sample data (CREATE TABLE and INSERT statements) and the results you want from that data.
If the question involves parameters, give a few different sets of parameters and the results you want for each set, given the same sample data.
It's unclear that you need dynamic SQL at all.
If shift_type is a variable, that can be either a single value or a ;-delimited list (such as '1;3'), you can compare that to a column called shift_column like this:
WHERE ';' || shift_type || ';' LIKE
'%;' || shift_column || ';%'No dynamic SQL or PL/SQL required.
If you really do want to use dynamic SQL, these two pages should gives you some ideas:
http://www.oracle-base.com/articles/misc/DynamicInLists.php
http://tkyte.blogspot.com/2006/06/varying-in-lists.html -
Creating a dynamic where clause
hello,
I am trying to create a procedure whech needs to parse a dynamic where clause into a cursor. The problem is I do not know the number of items that the user has selected (from previous input), thus what I want to pass in is a string of variables, but I donl;t think I can do this.
Does anyone have any ideas on how I can do this?
Thanks
Bryan
[email protected]
an example of theh code I am trying to run is:
v_update:='UPADTE :tabnam
SET ctrecid = :ctrec';
WHERE :v_and
AND pxlrecno = :strt';
v_cursor2 := DBMS_SQL.OPEN_CURSOR;
DBMS_SQL.PARSE(v_cursor2,v_update,DBMS_SQL.V7);
DBMS_SQL.BIND_VARIABLE(v_cursor2,':tabnam',tabnam);
DBMS_SQL.BIND_VARIABLE(v_cursor2,':ctrec',ctrec);
DBMS_SQL.BIND_VARIABLE(v_cursor2,':v_and',v_and);
DBMS_SQL.BIND_VARIABLE(v_cursor2,':strt',strt);
v_numrows:=DBMS_SQL.EXECUTE(v_cursor);
Where v_and is something like:
item1='TEST1' AND item2='TEST2' AND item3='TEST3'
nullSQL> EDIT update_tabnam
CREATE OR REPLACE PROCEDURE update_tabnam
(tabnam IN VARCHAR2,
ctrec IN VARCHAR2,
v_and IN VARCHAR2,
strt IN VARCHAR2)
IS
v_update VARCHAR2 (3000);
v_cursor2 INTEGER;
v_numrows INTEGER;
BEGIN
v_update := 'UPDATE ' | | tabnam
| | ' SET ctrecid = ' | | '''' | | ctrec | | ''''
| | ' WHERE ' | | v_and
| | ' AND pxlrecno = ' | | strt;
v_cursor2 := DBMS_SQL.OPEN_CURSOR;
DBMS_SQL.PARSE (v_cursor2, v_update, DBMS_SQL.V7);
v_numrows := DBMS_SQL.EXECUTE (v_cursor2);
DBMS_SQL.CLOSE_CURSOR (v_cursor2);
END update_tabnam;
SQL> START update_tabnam
Procedure created.
SQL> EXEC update_tabnam('TEST',7,'ITEM1=''TEST1'' AND ITEM2=''TEST2'' AND ITEM3=''TEST3''',1)
PL/SQL procedure successfully completed.
SQL> SELECT * FROM test;
CTRECID PXLRECNO ITEM1 ITEM2 ITEM3
7 1 TEST1 TEST2 TEST3
Note: Posting on this forum causes spaces to be inserted between the concatenation symbols where they don't belong, so anywhere you see a space between | and | remove it, before saving the file and starting it to create the procedure.
null
Maybe you are looking for
-
On the top of the above message is says XULRunner
-
How to access my parent's Mac screen
My parents live 90 minutes away. They are 91 years old and do pretty well with their Mac, so long as they don't fiddle where I've told them not to go... Unfortunately my father has a penchant for going into the preferences and messing things up wher
-
How to delete a row in target when corresponding row in source is deleted
Greetings Environment: Repository - OWB 10.1.0.4 - going to 10gR2 very soon - IBM RS6000 running AIX 5.3 I have a target table being updated with an INSERT/UPDATE. The user deleted a row in the source table and I want to delete the corresponding row
-
I have a lot of songs in my Itunes library. However, for some reason, they have disappeared and I only have one song left. When I check under My Music, I can see all the songs but can't access them through Itunes. Any idea why this happended and h
-
NO LONGER ABLE TO USE FIREWALL WITH 10.5.5
IT took me a while to figure out it was my firewall preventing me from connecting to the internet, Since I've had no problems before, Until I updated to 10.5.5(The only major change since problem started). Now my firewall setting is "Allow all incomi