Using decode in where clause
Hello
I need to use decode condition in where clause in such a way that if the respective column is null then consider the corresponding column
for example
Fee_date | Fee_refund_date |
10 OCTOBER 05 | |
12 NOVEMBER 05 | |
11 JANUARY 06 | |
16 FEBRUARY 06 |
I have a request in place as below where p_fee_flag will be passed as either FEES or set to null, I check another condition as if p_fee_flag is null then fee_date must be set to null when comparing fee_refund_date between TRUNC (BKT. ACT_START_DATE) AND TRUNC (BKT. ACT_END_DATE
SELECT 1
BUCKET BKT
WHERE DECODE (P_FEE_FLAG, 'FEES', TRUNC(FS.) FEE_DATE), TRUNC (FS. FEE_REFUND_DATE))
BETWEEN TRUNC (BKT. ACT_START_DATE) AND TRUNC (BKT. ACT_END_DATE)
944524 wrote:
Hello Alberto,.
Thank you that's what I ask but is it possible to verify the condition even using decode
Yes, it is possible, but why?
Just replace the query in this way:
select * from fee_table f where exists(select 1 from bucket b where decode(:p_fee_flag, 'FEE', f.fee_date, f.fee_refund_date) between b.act_start_date and b.act_end_date) and decode(:p_fee_flag, 'FEE', null, f.fee_date) is null;
Kind regards.
Alberto
Tags: Database
Similar Questions
-
Can I use truncated and where clause in the statement even?
Hello guys,.
Can I use truncated with where clause in the same statement.
For ex:
TRUNCATE TABLE my_table WHERE id < 500;
If not, that you recommend me to overtemperature to the level of high water line?
By the way
Oracle Database 11 g Enterprise Edition Release 11.2.0.1.0 - 64 bit Productionselect * from v$version;
PL/SQL Release 11.2.0.1.0 - Production
"CORE 11.2.0.1.0 Production."
AMT for 64-bit Windows: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production
>
Thank you very much.
Published by: 970992 on 11:14 13.Ara.2012>
Okay I need an increasing amount of space. However, at the same time I want to recover the spaces empty below HWM. So, I need to use less amount of space I am inserting. Therefore, shouldn't use retractable for this?
>
Why waste the effort. Oracle will reuse the space below the HWM when doing inserts. You already said that you insert more lines you delete so all these will be more accustomed to the top.The only time where that oracle may not use space is when the space is too small to be useful. It is documented in the doc, I told you
>
Understanding recoverable unused space
Over time, Update, and Delete on objects within a tablespace can create pockets of empty space that individually are not large enough to be reused for the new data.
>
Most uses of CONTRACTION I've seen are totally useless. If you follow the doc and run the Advisor of segment it will tell you if there is space that can be retrieved and how much. But, even once, for your use even if case will get you will Oracle while you need to reassign the new extensions, then the HWM will just go still higher.If pay you a heavy price in Oracle did a full table scan, update of many blocks from the table, update THE index, impact performance for other users to access the table during the SHRINK and reallocate extensions (maybe even some of the same areas) when you insert more data.
Do not SHRINK unless you know it's necessary.
-
I am using the following query as part of my effort to
Select b.account_number,
b.restriction_code,
a.cusip_number,
a.Symbol,
c.Shares,
Round(((c.shares/NULLIF(TO_NUMBER(a.shares_outstanding),0))*100),4) outstanding_share_percent
br_securities has
b br_accounts,
(select account_number, cusip_number, sum (shares) shares
of br_positions
where account_number not in (select account_number
of br_house_accounts)
Account_number group, cusip_number) c
where a.cusip_number = c.cusip_number
and b.account_number = c.account_number
and b.open_flag = 'Y '.
and a.security_type. a.security_sub_type ("A01", "B01", "B02", "C02")
and round(((c.shares/nullif(to_number(a.shares_outstanding),0))*100),4) (> 10
or round(((c.shares/nullif(to_number(a.shares_outstanding),0))*100),4) < 0
(or round(((c.shares/nullif(to_number(a.shares_outstanding),0))*100),4) is null)
outstanding_share_percent desc order;
Given that the expression round(((c.shares/nullif(to_number(a.shares_outstanding),0))*100),4) occurs again in
where clause, I tried to use the query as shown
Select b.account_number,
b.restriction_code,
a.cusip_number,
a.Symbol,
c.Shares,
a.shares_outstanding,
Round(((c.shares/NULLIF(TO_NUMBER(a.shares_outstanding),0))*100),4) outstanding_share_percent
br_securities has
b br_accounts,
(select account_number, cusip_number, sum (shares) shares
of br_positions
where account_number not in (select account_number
of br_house_accounts)
Account_number group, cusip_number) c
where a.cusip_number = c.cusip_number
and b.account_number = c.account_number
and b.open_flag = 'Y '.
and a.security_type. a.security_sub_type ("A01", "B01", "B02", "C02")
and outstanding_share_percent (> 10
outstanding_share_percent < 0 or
or outstanding_share_percent is null)
outstanding_share_percent desc order;
SQL * more returned this error
ERROR at line 21:
ORA-00904: "OUTSTANDING_SHARE_PERCENT": invalid identifier
Is it possible to modify the query for readability?Try this:
select * FROM (SELECT b.account_number, b.restriction_code, a.cusip_number, a.symbol, c.shares, a.shares_outstanding, round(((c.shares/nullif(to_number(a.shares_outstanding),0))*100),4) outstanding_share_percent from br_securities a, br_accounts b, (select account_number,cusip_number,sum(shares) shares from br_positions where account_number not in (select account_number from br_house_accounts) group by account_number,cusip_number) c where a.cusip_number = c.cusip_number and b.account_number = c.account_number and b.open_flag = 'Y' and a.security_type||a.security_sub_type in ('A01','B01','B02','C02')) WHERE ( outstanding_share_percent > 10 or outstanding_share_percent < 0 or outstanding_share_percent is null) order by outstanding_share_percent desc;
PS: Not tested
-
Thanks in advance
I have table TAbleaa
Input parameter when = 1 then my where clause is a > 1
Input parameter when = 2 then my where clause is a < 1
Select * from tableaa
where (when case & 1 = 1 then a 1 >)
When & 1 = 2 then a < 1)
create table TABLEAA
(
A NUMBER,
PLEASE THE NUMBER,
NUMBER OF END,
NUMBER OF TEACHER,
AVERAGE NUMBER
)
;
Fast loading TABLEAA...
insert into TABLEAA (A, START, END, TEACHER, AVERAGE)
values (10, 1.5,.6,, 499, 500);
insert into TABLEAA (A, START, END, TEACHER, AVERAGE)
values (1, 0,.1, 159, 159);
insert into TABLEAA (A, START, END, TEACHER, AVERAGE)
values (2,.1,.2,, 159, 168);
insert into TABLEAA (A, START, END, TEACHER, AVERAGE)
values (3,.2,.3, 179, 159);
insert into TABLEAA (A, START, END, TEACHER, AVERAGE)
values (4,.1,.2, 250, 300);
insert into TABLEAA (A, START, END, TEACHER, AVERAGE)
values (5,.2,.3, 320, 250);
insert into TABLEAA (A, START, END, TEACHER, AVERAGE)
values (6,.3,.4,, 250, 380);
insert into TABLEAA (A, START, END, TEACHER, AVERAGE)
values (7,.2,.3, 388, 379);
insert into TABLEAA (A, START, END, TEACHER, AVERAGE)
values (8,.3,.4,, 379, 388);
insert into TABLEAA (A, START, END, TEACHER, AVERAGE)
values (9,.4,.5, 388, 400);
insert into TABLEAA (A, START, END, TEACHER, AVERAGE)
values (11.5.6, 420, 448);
commit;
Published by: user1849 on August 26, 2009 14:32Select * from tableaa
cases where when & 1 = 1 and a > 1 then 1
When 1 = 2 & one< 1="" then="">
end = 1 -
With the help of DECODE in WHERE clause
Hi, I have a query which goes like this but does not work:
{
SELECT NVL (SUM (NVL(r.cload,0) * NVL(r.duration,0)), 0)
IN saidi_sum_trip_caused_by
SPM_REL_IND_TMP r
WHERE substr(r.scode_trip_caused_by,6,4) in ('N001', 'N002', 'N003', 'N004', 'N005', "N006", "N007")
AND (r.cload 0 GOLD r.cload IS NOT NULL)
AND DECODE (R.CLASSIFICATION_TRIP, 't', r.duration < = 5,)
r.Duration > 5);
}
It seems that there is a problem with my DECODE statement since I've noticed that when you use the DECODE function, a column is assimilated before the DECODE. However, in this case I can't equate the value of r.duration for DECODING since if the value of R.CLASSIFICATION_TRIP is ' t "then I should use < = I use >." How can I go about it? I tried to post in the forums of PL/SQL, but I think that very few people access this area. I get answers faster from here. Thank you.Fact
-
Hi all
I have data that looks like this.
PLAN_INSTANCE DATE_START, DATE_END TOTALS PLAN
1007 1 20150101 20151231 10
1007 2 20140101 20141231 25
1007 3 20130101 20131231 12
1008 1 20150101 20151231 22
1008 2 20140101 20141231 9
I would like you run a query that displays one line per plan based on max (date_start).
I tried
Select the total plan, t.date_start, date_end,
of t_totals t
where t.date_start= (select max (date_start)
of t_totals
where date_start= t.date_start);
but this does not seem to work that I get all the 5 rows instead of 2 rows.
Can you suggest me how can I change my query?
Here is the information of table
CREATE TABLE T_TOTALS
(
PLAN NUMBER (9) NOT NULL,
PLAN_INSTANCE NUMBER 4 NOT NULL,.
DATE_START NUMBER (8) NOT NULL,
DATE_END NUMBER (8) NOT NULL,
NUMBER (9) TOTALS NOT NULL,.
);
CREATE A UNIQUE I_TOTALS ON T_TOTALS INDEX
(SAK_PUB_HLTH, SAK_SHORT);
CREATE INDEX X_TOTALS_1 ON T_TOTALS
(SAK_PUB_HLTH, DTE_EFFECTIVE);
Thanks in advance,
sqlamateur
Hello
2886750 wrote:
Hi Pam,.
I would like to see the data set that results must be displayed
PLAN DATE_START, DATE_END TOTALS
1007 20150101 20151231 10
1008 20150101 20151231 22
How to modify the query to get the data above?
The solution you provided still shows all lines instead of simply max lines (date_start).
Thank you
Really? It seems that the Pam should return only 1 package date_start. Of course, we can not really test without valid CREATE TABLE and INSERT statements, but here's a query using the table scott.emp (which we all have, or can get easily) that uses the same approach:
SELECT ename, deptno, hiredate - you could include all the columns you want
FROM scott.emp m
WHERE hiredate =)
SELECT MAX (s.hiredate)
FROM scott.emp s
WHERE s.deptno = m.deptno
)
ORDER BY deptno
;
This query returns all the 14 rows of table scott.emp; She returned only 3 lines that were later hiredate in each of the 3 deptnos:
ENAME HIREDATE DEPTNO
---------- ---------- -----------
MILLER 10 January 23, 1982
ADAMS 20 23 May 1987
JAMES 30 December 3, 1981
-
Size of partition on interval range partitioned Table happens when SYSDATE is used in a Where Clause
We have tables interval range partitioned on a DATE, with a partition for each day column - very standard and straight out of doc Oracle.
A 3rd party application queries the tables to find the number of rows based on the date range that is located on the column used for the partition key.
This application uses the date range specified from the current date - i.e. for last two days would be «...» StartDate > SYSDATE-2 "- but the partition size is irrelevant and the explain command plan shows that each partition is included."
In presenting the request uses the date in a variable partition size location and query table is obviously much better.
DB is 11.2.0.3 on RHEL6, and default settings - i.e. nothing that could influence the behavior of the optimizer to something unusual.
I can't work on why this would be the case. It is very easy to reproduce with cases of simple test below.
I would be very interested to hear any views on why it's that way and if anything can be done to allow the size of the partition to work with a query including SYSDATE because it would be difficult to get the application code has changed.
In addition to make a case to change the code, I need an explanation of why query using SYSDATE is not advisable and I know this information.
(1) create a simple partitioned table
CREATETABLE part_test (id NUMBER NOT NULL, starttime DATE NOT NULL, CONSTRAINT pk_part_test PRIMARY KEY (id)) PARTITION BY RANGE (starttime) INTERVAL (NUMTODSINTERVAL(1,'day')) (PARTITION p0 VALUES LESS THAN (TO_DATE('01-01-2013','DD-MM-YYYY')));
(2) fill in the rows of the table 1 million distributed among 10 partitions
BEGIN FOR i IN 1..1000000 LOOP INSERT INTO part_test (id, starttime) VALUES (i, SYSDATE - DBMS_RANDOM.value(low => 1, high => 10)); END LOOP; END; / EXEC dbms_stats.gather_table_stats('SUPER_CONF','PART_TEST');
(3) to query the Table of data from the last 2 days using SYSDATE in paragraph
EXPLAIN PLAN FOR SELECT count(*) FROM part_test WHERE starttime >= SYSDATE - 2;
-------------------------------------------------------------------------------------------------------
| ID | Operation | Name | Lines | Bytes | Cost (% CPU). Time | Pstart. Pstop |
-------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1. 3 × 7895 (1) | 00:00:01 | | |
| 1. GLOBAL TRI | | 1. 3 × | | | |
| 2. RANGE OF PARTITION ITERATOR. | 111K | 867K | 7895 (1) | 00:00:01 | KEY | 1048575.
|* 3 | TABLE ACCESS FULL | PART_TEST | 111K | 867K | 7895 (1) | 00:00:01 | KEY | 1048575.
-------------------------------------------------------------------------------------------------------
Information of predicates (identified by the operation identity card):
---------------------------------------------------
3 - filter("STARTTIME">=SYSDATE@!-2)
(4) now do the same query, but with SYSDATE - 2 presented as a literal value.
This query returns the same response but very different cost.
EXPLAIN PLAN FOR SELECT count(*) FROM part_test WHERE starttime >= (to_date('23122013:0950','DDMMYYYY:HH24MI'))-2;
-------------------------------------------------------------------------------------------------------
| ID | Operation | Name | Lines | Bytes | Cost (% CPU). Time | Pstart. Pstop |
-------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1. 8. 131 (0) | 00:00:01 | | |
| 1. GLOBAL TRI | | 1. 8. | | | |
| 2. RANGE OF PARTITION ITERATOR. | 111K | 867K | 131 (0) | 00:00:01 | 356 . 1048575.
|* 3 | TABLE ACCESS FULL | PART_TEST | 111K | 867K | 131 (0) | 00:00:01 | 356 | 1048575.
-------------------------------------------------------------------------------------------------------
Information of predicates (identified by the operation identity card):
---------------------------------------------------
3 filter ("STARTTIME" > = TO_DATE (' 2013-12-21 09:50 ',' syyyy-mm-dd hh24:mi:ss'))))
Thank you in anticipation
Jim
sysdate is not constant and its value may change from time optimization of execution; but the optimizer can deduce that he will be a known running value and then produce a plan that will make the size of partition running. This is the meaning of 'KEY' in the column pstart – the partition of departure will be known at run time and the size of partition will take place in order to eliminate the previous partitions.
Concerning
Jonathan Lewis
-
How to use DATE in where clause
I need to select the list of records in a table where the available date is greater than or equal to the current date. This is the structure of the table and
Select the query that is used to get the list of records
I get the documents expected but I'm not able to find a condition where I can use * > = * a query as the below a date data type, isCREATE TABLE TEMP (ITEM_ID NUMBER(20),ITEM_NAME VARCHAR2(100),CREATION_DATE DATE,AVAILABLE_DATE DATE); INSERT INTO TEMP (ITEM_ID,ITEM_NAME,CREATION_DATE,AVAILABLE_DATE) VALUES(1,'ITEM1',SYSDATE,SYSDATE); INSERT INTO TEMP (ITEM_ID,ITEM_NAME,CREATION_DATE,AVAILABLE_DATE) VALUES(2,'ITEM2',SYSDATE,SYSDATE+10); INSERT INTO TEMP (ITEM_ID,ITEM_NAME,CREATION_DATE,AVAILABLE_DATE) VALUES(3,'ITEM3',SYSDATE,SYSDATE-10); INSERT INTO TEMP (ITEM_ID,ITEM_NAME,CREATION_DATE,AVAILABLE_DATE) VALUES(4,'ITEM4',SYSDATE,SYSDATE); INSERT INTO TEMP (ITEM_ID,ITEM_NAME,CREATION_DATE,AVAILABLE_DATE) VALUES(5,'ITEM5',SYSDATE,SYSDATE+5); SELECT ITEM_NAME, available_date FROM TEMP WHERE available_date > SYSDATE OR available_date LIKE SYSDATE;
do not return only documents not expected
Published by: Barro on March 19, 2012 21:13SELECT ITEM_NAME, available_date FROM TEMP WHERE available_date >= SYSDATE ;
Hello
Barros says:
I need to select the list of records in a table where the available date is greater than or equal to the current date. This is the structure of the table and
Select the query that is used to get the list of recordsCREATE TABLE TEMP (ITEM_ID NUMBER(20),ITEM_NAME VARCHAR2(100),CREATION_DATE DATE,AVAILABLE_DATE DATE); INSERT INTO TEMP (ITEM_ID,ITEM_NAME,CREATION_DATE,AVAILABLE_DATE) VALUES(1,'ITEM1',SYSDATE,SYSDATE); INSERT INTO TEMP (ITEM_ID,ITEM_NAME,CREATION_DATE,AVAILABLE_DATE) VALUES(2,'ITEM2',SYSDATE,SYSDATE+10); INSERT INTO TEMP (ITEM_ID,ITEM_NAME,CREATION_DATE,AVAILABLE_DATE) VALUES(3,'ITEM3',SYSDATE,SYSDATE-10); INSERT INTO TEMP (ITEM_ID,ITEM_NAME,CREATION_DATE,AVAILABLE_DATE) VALUES(4,'ITEM4',SYSDATE,SYSDATE); INSERT INTO TEMP (ITEM_ID,ITEM_NAME,CREATION_DATE,AVAILABLE_DATE) VALUES(5,'ITEM5',SYSDATE,SYSDATE+5); SELECT ITEM_NAME, available_date FROM TEMP WHERE available_date > SYSDATE OR available_date LIKE SYSDATE;
Both operands for AS are supposed to be strings. Do not try to use a DATE, such as SYSDATE, with AS.
I get the documents expected but I'm not able to find a condition where I can use * > = * a query as the below a date data type, is
do not return only documents not expectedSELECT ITEM_NAME, available_date FROM TEMP WHERE available_date >= SYSDATE ;
It returns the results I expect.
If you'd say what results you expected, could someone help you wite a query to get.Assuming that 1 second elapses between the time "ITEM4" is inserted and that 2nd query execution, then, running, available_date will be 1 second less than SYSDATE, so it shouldn't be included.
If you want to find lines that are on the same calendar day as SYSDATE or later, then useWHERE available_date >= TRUNC (SYSDATE)
-
How to use a function in a Where Clause?
Hello
I have a doubt. If MY_FUNCT is a function that returns a Boolean value, can I use in a where clause clause to write a query like this? :
Select...
table one
where the...
*...*
and MY_FUNC (a.field) = true
*...*
*;*
Thank you!
Published by: Mark1970 on 3.27 lug-2-2010But is it possible that the function does not return a Boolean value?
Yes (as sysdate, substr and instr etc.) you can also use your own function in a where clause clause, as long as it does not return a BOOLEAN value.
I mean how to use a function in a where clause clause?
Your own pseudocode seems a good example for me.
So, just give it a try. -
Can I use DECODE or CASES when it is in this context?
Hi, I have a query which goes like this but does not work:
{
SELECT NVL (SUM (NVL(r.cload,0) * NVL(r.duration,0)), 0)
IN saidi_sum_trip_caused_by
SPM_REL_IND_TMP r
WHERE substr(r.scode_trip_caused_by,6,4) in ('N001', 'N002', 'N003', 'N004', 'N005', "N006", "N007")
AND (r.cload <>0 r.cload GOLD IS NOT NULL)
AND DECODE (R.CLASSIFICATION_TRIP, 't', r.duration < = 5, )
r.Duration > 5);
}
It seems that there is a problem with my DECODE statement since I've noticed that when you use the DECODE function, a column is assimilated before the DECODE. However, in this case I can't equate the value of r.duration for DECODING since if the value of R.CLASSIFICATION_TRIP is ' t "then I should use < = I use >." How can I go about it? Thank you.try all the Subforums are you not
go here:
-
where clause to query the hierarchy in the tree Apex area does not
Hi all
I am building a tree Menu in Apex 5.0.3 (Oracle 11 g XE), when using when the clause, it does show all the data, but without him, showing all the data.
I'm trying to populate Tree Menu with data specific to a user successfully logged on.
(A) table created as HR2. TREE_MENU
menu_name varchar2 (50).
number of menu_parent
number of menu_child
menu_id varchar2 (12),
menu_path varchar2 (100),
number of user_no
(B) SQL statement for the tree in the Apex region
Select case when connect_by_isleaf = 1 then 0
When level = 1 then 1
else -1
end the status,
level,
'Menu_name' as the title,
NULL as an icon,
"MENU_CHILD" as a value.
NULL as ToolTip,
NULL as link
to HR2. "" TREE_MENU ".
-WHERE USER_NO =: P_USERNO
Start with 'MENU_CHILD' is null
connect prior "MENU_PARENT" = "MENU_CHILD."
brothers and sisters of order by 'MENU_ID '.
Note: also used static value where clause but is not workd.
that the mistake of me or something else? When using the wizard, she asks (possibly) where clause, this means that when the clause can be used in the SQL statement.
Help, please.
Kind regards.
If you want to prune your tree to show only the elements of the No. 7 usermenu, copy the following code helps you
select case when connect_by_isleaf = 1 then 0 when level = 1 then 1 else -1 end as status, level, "MENU_NAME" as title, null as icon, "MENU_CHILD" as value, null as tooltip, null as link from HR2."TREE_MENU" start with "MENU_CHILD" is null connect by prior "MENU_PARENT" = "MENU_CHILD" and "USER_NO" = 7 order siblings by "MENU_ID"
Concerning
Mahmoud
-
several instructions box in where clause
Hello
I'm trying to create report filters using substitution variables in a case statement in a where clause clause. I have several instructions box running on the same column. I don't really know how to write it. Here's what I have so far but I know I'm going in the wrong direction.
where
i.compute_zone =
case
When: P14_zone is NOT NULL
then: P14_zone
of other i.compute_zone
end
AND
i.compute_zone =
case
When: P14_zone_2 is NOT NULL
then: P14_zone_2
other: P14_zone
end
AND
i.compute_zone =
case
When: P14_zone_3 is NOT NULL
then: P14_zone_3
of other i.compute_zone
end
AND
i.compute_zone =
case
When: P14_zone_4 is NOT NULL
then: P14_zone_4
of other i.compute_zone
end
any suggestions?
Thank you
MICAH
Hi, Micah,
User12611868-Oracle wrote:
Hello
I'm trying to create report filters using substitution variables in a case statement in a where clause clause. I have several instructions box running on the same column. I don't really know how to write it. Here's what I have so far but I know I'm going in the wrong direction.
where
i.compute_zone =
case
When: P14_zone is NOT NULL
then: P14_zone
of other i.compute_zone
end
AND
i.compute_zone =
case
When: P14_zone_2 is NOT NULL
then: P14_zone_2
other: P14_zone
end
AND
i.compute_zone =
case
When: P14_zone_3 is NOT NULL
then: P14_zone_3
of other i.compute_zone
end
AND
i.compute_zone =
case
When: P14_zone_4 is NOT NULL
then: P14_zone_4
of other i.compute_zone
end
any suggestions?
Thank you
MICAH
How get the desired results of your data depends on the desired results and your data. What do you do? (I can't tell just by looking at the aat code that do not do). After CREATE TABLE and INSERT statements for some sample data and a couple of sets of parameters (variables such as p14_zone) and the exact results that your choices in each set of parameters, given the same sample data.
Check out the Forum FAQ: Re: 2. How can I ask a question on the forums?
CASE expressions are generally not useful in a WHERE clause. CASE expressions are a convenient way to IF-THEN-ELSE logic of the places where you can't do anything other than (the SELECT clause), but WHERE the clauses allow IF-THEN-ELSE logic in any case
Maybe you want something like
WHERE MERGE (: p14_zone,: p14_zone_2,: p14_zone_3,: p14_zone_4) IS NULL
OR IN i.compute_zone (: p14_zone,: p14_zone_2,: p14_zone_3,: p14_zone_4)
It returns TRUE if all 4 parameters are set to NULL. If 1 or more of them are not NULL, then it will return TRUE if i.compute_zone is equal to one of them.
-
ORA-01722: number not valid only in where clause
I'm getting ORA-01722: invalid number when you use to_number in where clause:
I don't get it without where clause (300 rows returned):select to_number(txt_field) from tbl where 100>=to_number(txt_field);
No logical explanation?select to_number(txt_field) from tbl;
Published by: totalnewby on February 21, 2012 04:54totalnewby wrote:
No logical explanation?Let me guess - tbl is actually a point of view:
SQL> create table tbl(code varchar2(10),val varchar2(10)); Table created. SQL> insert into tbl values('string','abc'); 1 row created. SQL> insert into tbl values('number','123'); 1 row created. SQL> create or replace 2 view tbl_vw 3 as 4 select * 5 from tbl 6 where code = 'number' 7 / View created. SQL> select to_number(val) 2 from tbl_vw 3 / TO_NUMBER(VAL) -------------- 123 SQL> select to_number(code) 2 from tbl_vw 3 where to_number(val) > 100 4 / select to_number(code) * ERROR at line 1: ORA-01722: invalid number SQL>
Reason is first selection from the first filters view (find out where clause) out of the non-numeric values and then only apply to_number. When the second select is run optimizer merges the view definition and where would adopt becomes:
where where code = 'number '.
and to_number (val) > 100Since there is no order of predicate, it happens that to_number (val) > 100 is applied first, and he obviously fails.
SY.
-
CASE in a WHERE clause: ORA-00905
Hello world
I try to use a BOX in a WHERE clause clause and I got the error ORA-00905: lack of keyword. Here is my code:
SELECT id_reserv,
Concat (name, Concat ('_', index)) as name,
Libelle,
num_lot,
resa_keyword1,
resa_keyword2,
resa_keyword3,
resa_keyword4,
date_creation,
comm_creation,
id_util,
assets,
id_env_act,
(SELECT connection of user u where u.id_util = r.id_util) AS nom_util,
(SELECT name e environment where e.id_env = r.id_env_act) AS nom_env,
(SELECT count (*) of rc reserv_comp where rc.id_reserv = r.id_reserv) AS nbComp,
(SELECT count (*) MC reserv_modif where mc.id_reserv = r.id_reserv) AS nbModif
BOOKING r
WHERE the r.nom NOT LIKE 'RESERV_LOT_ % '.
AND id_util = '1'
AND active = '1'
AND id_env_act > = '-1'.
AND the MATTER sansdemande
WHEN true THEN id_reserv not in some id_reserv from demande_livraison where id_env_dep > = '-1'.
ELSE id_reserv = id_reserv
END
AND name LIKE '% '.
ORDER BY date_creation;
I already looked at the CASE statement and it seems that the syntax is correct, so I don't know I can use in a WHERE clause.
Any help would be nice!
AndalusiansHello
It should be something like this:
AND CASE WHEN 'false'='true' THEN (select id_reserv from demande_livraison where id_env_dep>='-1') ELSE id_reserv END = id_reserv
The subquery must return a line
But I think that it is better to write your query in the form:
SELECT id_reserv, concat(nom,concat('_',indice)) as nom, libelle, num_lot, resa_keyword1, resa_keyword2, resa_keyword3, resa_keyword4, date_creation, comm_creation, id_util, actif, id_env_act, (SELECT login from utilisateur u where u.id_util=r.id_util) AS nom_util, (SELECT nom from environnement e where e.id_env=r.id_env_act) AS nom_env, (SELECT count(*) from reserv_comp rc where rc.id_reserv=r.id_reserv) AS nbComp, (SELECT count(*) from reserv_modif mc where mc.id_reserv=r.id_reserv) AS nbModif FROM reservation r WHERE r.nom NOT LIKE 'RESERV_LOT_%' AND id_util='1' AND actif='1' AND id_env_act>='-1' AND ( ( 'false'='true' and id_reserv not in (select id_reserv from demande_livraison where id_env_dep>='-1') ) or ( 'true'= 'true' and id_reserv=id_reserv ) ) AND nom LIKE '%' ORDER BY date_creation;
This coding in SQL something as if a = b, then c, d also in the simplest form.
Herald tiomela
http://htendam.WordPress.com -
several conditional parameters in where clause
How to select records in a table, when I say emp, a parameter for where the condition as
If empno is known then use in where clause,
If ename is known then use ename in where clause,
If both are known then use two parameters in where clause.
I use Oracle 9i.
How can I do this in sql and plsqlpsuedo code. ... if p_empno is not null and p_ename is not null then select * from emp where empno=p_emp and ename = p_ename ; elsif p_empno is null and p_ename is not null then select * from emp where ename = p_ename ; elsif p_empno is not null p_ename is null then select * from emp where empno=p_emp ; else select * from emp end if ; ...
Thank you
Published by: user10999538 on July 15, 2009 03:29Solution
SELECT * FROM emp WHERE Nvl(empno,-9999) = Coalesce(p_empno,empno,-9999) AND Nvl(ename,'X') = Coalesce(p_ename,ename,'X') /
SS
Maybe you are looking for
-
Why do I not see http or https in front of the web sites that I visit?
At the top of THIS page, I see mozilla.com , then https://support but when I go to any other page such as www.cnn.com or www.msnbc.com I see NOT any http or https in front of her. IF I try to go on my site of the Bank, it will load the information be
-
No boot device message on my laptop satellite
I get the message "no boot device - please reboot"; What does that mean? The laptop is only a year and primer not. I also tried a bootable DVD, and it does not start either! Help, please.
-
Service Pack 1 will not install after that the pc has been reset to the factory settings
At my pc reset due to problems of crashing and freezing factory settings, when turned on after resetting received masses of updates Service Pack 1 has not been installed, but it shows in the story as being successful. He reappears in the form of wait
-
Hard disk partition - 'SMART disk error' on DV7
Hello I have a hp dv7 laptop and I recently did an update from hp that has created a new partition on my hard drive, now after I did this update whenever I turn on my laptop, I get an error (301) smart drive and he always tells me now that I could lo