Problem with to_date('date_char') in a where clause
A little confused with this plsql error.
This code works...
select to_date(value,'dd/mm/yy') from kip_lov where domain='MODULE START1'
If I try to put the "to_date(value,'dd/mm/yy')" expression in the where clause I get an invalid year error,
select to_date(value,'dd/mm/yy') from kip_lov where domain='MODULE START1'
AND to_date(value,'dd/mm/yy') = SYSDATE
"Error report:
SQL Error: ORA-01841: (full) year must be between -4713 and +9999, and not be 0"
The variable "value" is a varchar2 in the format dd/mm/yy.
Note: the following code also works fine,
select to_date(value,'dd/mm/yy') - sysdate from kip_lov where domain='MODULE START1'
I have modified my lov table so that it uses the date type now and it works fine. Just curious as to why the above example does not work.
Sam.
check your table description and values first, is there any dd/mm/yy or mm/dd/yy confliction
A scenario which runs.
SQL> desc trya
Name Null? Type
UPDATED_ON DATE
UPD VARCHAR2(8)
SQL> select * from trya
2 ;
UPDATED_O UPD
31-JUL-06 31/07/06
31-JUL-06 31/07/06
31-JUL-06 31/07/06
31-JUL-06 31/07/06
31-JUL-06 31/07/06
31-JUL-06 31/07/06
31-JUL-06 31/07/06
31-JUL-06 31/07/06
31-JUL-06 31/07/06
31-JUL-06 31/07/06
31-JUL-06 31/07/06
UPDATED_O UPD
31-JUL-06 31/07/06
31-JUL-06 31/07/06
13 rows selected.
SQL> SELECT * FROM trya WHERE TO_CHAR(TO_DATE(upd,'dd/mm/yy'))=SYSDATE;
no rows selected
SQL> SELECT * FROM trya WHERE TO_DATE(upd,'dd/mm/yy')=SYSDATE;
no rows selected
SQL>
NO error on both syntax
rgds,
Rup
Similar Messages
-
To_Date function in the Where Clause
Hello All,
I'm having an issue using the to_date function that has me quite perplexed.
I have two varchar2 fields, one with a date value in the format Mon, DD YYYY, the other has a time value in the format HH:MI PM.
When I run my query one of the columns I retrieve looks like this TO_DATE (d4.adate || e4.atime, 'Mon DD, YYYYHH:MI PM'). The two fields are concatenated together and converted to a date. This works fine.
My problem occurs when I attempt to apply the same logic to the where clause of the aforementioned query. e.g. when I add the following criteria to my query and TO_DATE (d4.adate || e4.atime, 'Mon DD, YYYYHH:MI PM') <= sysdate I get an ORA-01843: not a valid month error.
To further illustrate my problem here are the two queries:
Select d4.adate, e4.atime, TO_DATE (d4.adate || e4.atime, 'Mon DD, YYYYHH:MI PM')
from ....
where ....
The above query works.
Select d4.adate, e4.atime, TO_DATE (d4.adate || e4.atime, 'Mon DD, YYYYHH:MI PM')
from ....
where ....
and TO_DATE (d4.adate || e4.atime, 'Mon DD, YYYYHH:MI PM') <= sysdate
The second query does not work.
The tables used and the limiting criteria are identical, except for the last one.
Does anyone have any ideas why this could be happening.
erHello,
Check this out. It does work. Do cut n paste sample
data from your tables.
SQL> desc test
Name Null? Type
ID NUMBER
DDATE VARCHAR2(20)
DTIME VARCHAR2(20)
SQL> select * from test;
ID DDATE DTIME
1 Jan, 10 2006 12:32 PM
2 Mar, 11 2005 07:10 AM
3 Apr, 13 2006 03:12 AM
4 Nov, 15 2003 11:22 PM
5 Dec, 20 2005 09:12 AM
6 Oct, 30 2006 10:00 AM
7 Jan, 10 2006 12:32 PM
8 Apr, 11 2005 07:10 AM
9 May, 13 2006 03:12 AM
10 Sep, 15 2003 11:22 PM
11 Oct, 20 2005 09:12 AM
12 Dec, 30 2006 10:00 AM
12 rows selected.
SQL> select id, ddate, dtime,
2 to_date(ddate||dtime,'Mon, DD YYYYHH:MI PM') AA,
A,
3 to_char(to_date(ddate||dtime,'Mon, DD YYYYHH:MI
MI PM'),'Mon, DD YYYYHH:MI PM') BB
4 from test;
ID DDATE DTIME
DTIME AA BB
1 Jan, 10 2006 12:32 PM
12:32 PM 10-JAN-06 Jan, 10 200612:32 PM
2 Mar, 11 2005 07:10 AM
07:10 AM 11-MAR-05 Mar, 11 200507:10 AM
3 Apr, 13 2006 03:12 AM
03:12 AM 13-APR-06 Apr, 13 200603:12 AM
4 Nov, 15 2003 11:22 PM
11:22 PM 15-NOV-03 Nov, 15 200311:22 PM
5 Dec, 20 2005 09:12 AM
09:12 AM 20-DEC-05 Dec, 20 200509:12 AM
6 Oct, 30 2006 10:00 AM
10:00 AM 30-OCT-06 Oct, 30 200610:00 AM
7 Jan, 10 2006 12:32 PM
12:32 PM 10-JAN-06 Jan, 10 200612:32 PM
8 Apr, 11 2005 07:10 AM
07:10 AM 11-APR-05 Apr, 11 200507:10 AM
9 May, 13 2006 03:12 AM
03:12 AM 13-MAY-06 May, 13 200603:12 AM
10 Sep, 15 2003 11:22 PM
11:22 PM 15-SEP-03 Sep, 15 200311:22 PM
11 Oct, 20 2005 09:12 AM
09:12 AM 20-OCT-05 Oct, 20 200509:12 AM
12 Dec, 30 2006 10:00 AM
10:00 AM 30-DEC-06 Dec, 30 200610:00 AM
12 rows selected.
SQL> select id, ddate, dtime,
to_date(ddate||dtime,'Mon, DD YYYYHH:MI PM')
2 from test
3 where id > 3
4 and to_date(ddate||dtime,'Mon, DD YYYYHH:MI PM')
') <= trunc(sysdate);
ID DDATE DTIME
DTIME TO_DATE(D
4 Nov, 15 2003 11:22 PM
11:22 PM 15-NOV-03
5 Dec, 20 2005 09:12 AM
09:12 AM 20-DEC-05
7 Jan, 10 2006 12:32 PM
12:32 PM 10-JAN-06
8 Apr, 11 2005 07:10 AM
07:10 AM 11-APR-05
10 Sep, 15 2003 11:22 PM
11:22 PM 15-SEP-03
11 Oct, 20 2005 09:12 AM
09:12 AM 20-OCT-05
6 rows selected.
SQL> select id, ddate, dtime,
to_date(ddate||dtime,'Mon, DD YYYYHH:MI PM')
2 from test
3 where id > 3
4 and to_date(ddate||dtime,'Mon, DD YYYYHH:MI PM')
') <= sysdate;
ID DDATE DTIME
DTIME TO_DATE(D
4 Nov, 15 2003 11:22 PM
11:22 PM 15-NOV-03
5 Dec, 20 2005 09:12 AM
09:12 AM 20-DEC-05
7 Jan, 10 2006 12:32 PM
12:32 PM 10-JAN-06
8 Apr, 11 2005 07:10 AM
07:10 AM 11-APR-05
10 Sep, 15 2003 11:22 PM
11:22 PM 15-SEP-03
11 Oct, 20 2005 09:12 AM
09:12 AM 20-OCT-05
6 rows selected.
-SriSorry Sri, but I fail to see what you mean. How is what you're doing any different than what I'm doing? -
Problem with the query in group by clause
hi, i have problem with group by clause, can some one please help me.
select
header_id,
(select sum(nvl(dr,0) - nvl(cr ,0)) from temp_tab a1
where
a1.country=a.country
and a1.source='AP'
and a1.header_id=a.header_id) WHT,
sum(dr),
sum(cr) from temp_tab a
group by header_id,
(select sum(nvl(dr,0) - nvl(cr ,0)) from temp_tab a1
where
a1.country=a.country
and a1.source='AP'
and a1.header_id=a.header_id)
select * from temp_tab
drop table temp_tab
create table temp_tab(header_id number ,line_num number, country varchar2(2),
source varchar2(2), dr number, cr number,primary key(header_id,line_num));
insert into temp_tab(header_id, line_num,country, source, dr,cr) values(1, 1,'NL','AP',100,20);
insert into temp_tab(header_id, line_num,country, source, dr,cr) values(1, 2,'PO','AP',20,20);
insert into temp_tab(header_id, line_num,country, source, dr,cr) values(1, 3,'NL','AP',70,20);
insert into temp_tab(header_id, line_num,country, source, dr,cr) values(2, 1,'NL','PA',100,20);
insert into temp_tab(header_id, line_num,country, source, dr,cr) values(2, 2,'NL','PA',100,20);
insert into temp_tab(header_id, line_num,country, source, dr,cr) values(3, 1,'KR','PO',100,20);
commit;
Appreciate your help.
Thanks,select header_id,
(select sum(nvl(dr,0) - nvl(cr ,0)) from temp_tab a1
where a1.country=a.country
and a1.source='AP'
and a1.header_id=a.header_id) WHT,
sum(dr),
sum(cr)
from temp_tab a
group by header_id
,countryIt's kinda hard to follow what your query does... maybe because I'm only at my second coffee..
Edited by: Alex Nuijten on Oct 2, 2009 8:07 AM -
NVL with host variables in a where clause
Does anyone know if using a host variable in a WHERE clause with
the NVL function will actually work if the host variable is null
without using the indicator variable too?
In other words if the variable ":new_prmy_numb" which was
selected previously is actually null, will the NVL know that it
is null without the indicator variable being listed also? The
person at our company who has this in their code says it works
and the rest of us don't see how.
Example:
SELECT recd_a_id from ADDR
WHERE
NVL(prmy_numb,' ') = NVL(:new_prmy_numb,' ')well firstly have you tried it to see if it works? That would seems to be a rather obvious step, I would imagine.
Anyway, I don't see anything wrong with the code, except that it might be optimized better ...
SELECT recd_a_id from ADDR
WHERE
(prmy_numb = :new_prmy_numb
or (:new_prmy_numb is null and prmy_numb is null))
... might stand more chance of using an index on the column prmy_numb -
Problem in adding one condition in where clause
Hi,
I am populating this internal table t_bkpf for all entries in gt_covp_ext
select bukrs belnr gjahr
bldat budat cpudt
xblnr waers awtyp awkey
from bkpf
into corresponding fields of table t_bkpf
for all entries in gt_covp_ext
where bukrs eq gt_covp_ext-bukrs and
awtyp eq 'MKPF'.
Here i have to add one more condition in where clause
AWKEY = ( Concatenated string of gt_covp_ext-REFBN + gt_covp_ext-REFGJ )
As i am not using loop at gt_covp_ext.How to implement this condition in Where clause.
Please help.If you did not understood the requirement reply this post.
Mukesh Kumar
Message was edited by:
mukesh kumarHi,
Create a new internal table gt_covp_ext_new with the same structure as gt_covp_ext. Include an extra field in gt_covp_ext_new-concat, to store the concatenated value.
Copy all entries from gt_covp_ext to gt_covp_ext_new.
Loop at gt_covp_ext.
move-corresponding gt_covp_ext to gt_covp_ext_new.
gt_covp_ext_new-concat = gt_covp_ext-REFBN + gt_covp_ext-REFGJ .
append gt_covp_ext_new.
endloop.
Now use this new internal table in the query.
select bukrs belnr gjahr
bldat budat cpudt
xblnr waers awtyp awkey
from bkpf
into corresponding fields of table t_bkpf
for all entries in gt_covp_ext_new
where bukrs eq gt_covp_ext_new-bukrs and
awkey eq gt_covp_ext_new-concat and
awtyp eq 'MKPF'.
Hope this answers your qn.
Regards,
Divya -
Reading data from BSEG table with Non-key fields in where clause
Hi All,
I have to read data from BSEG table based on WBS element field (PROJK). As I'm not passing key fields to WHERE clause system couldnt run the select statement. Since BSEG is a cluster table I cant even create secondary index on PROJK field.
Could you please tell me, how to improve its performance.
Regards
Jaker.SELECT bukrs
belnr
gjahr
shkzg
dmbtr
hkont
lifnr
matnr
werks
menge
meins
ebeln
FROM bseg
INTO TABLE it_bseg
PACKAGE SIZE 10
FOR ALL ENTRIES IN it_final
WHERE bukrs EQ it_final-bukrs
AND belnr EQ it_final-belnr
AND gjahr EQ it_final-gjahr
AND buzei EQ it_final-buzei
AND hkont EQ it_final-hkont
AND werks IN s_werks.
By using package and fetch from BSEG table. gathering all other information to a final internal table.This will reduce the hit to database.And also try to put that data in hashed internal table which is it_bseg....then definetly improve the performance.
<REMOVED BY MODERATOR>
Dara.
Edited by: Alvaro Tejada Galindo on Apr 21, 2008 12:47 PM -
ICal Problem with Mobile Account/Home and where are the calendars stored
I am using MacMinis in an office with my MacPro SnowLeopard Server running LDAP with NetworkHome accounts. Almost everything works except this ical is driving me nuts.
The problem is iCals don't sync with the NetworkHome. When I look in usr/library/calendars a new calendar appears there but it won't sync on to a different machine.
What is even more frusterating, if I disconnect the server so I am just logging in locally, I can delete all the calanders in usr/library/calendars, but when I log back in the calendars just re-appear. So where else is ical storing calendar information?
thanks
jakewhere else is ical storing calendar information?
in a folder in usr/library/syncservices/local. You will have to look in the clientname.txt file in each of the folders to find which one is for iCal.
AK -
Issue with using SHUTTLE in query where clause
Lets say we have a shuttle control on the page with the following 4 values: apple:orange:peach:berry
Lets say I also have a simple SQL query report on the page and I want to use between 1 and 4 of the aforementioned values as part of an "*IN LIST*" sql operation. For example, if the user has selected only apple and orange from the shuttle, I want my query to be:
select * from some_table where fruit IN ('apple', 'orange');
if however, the user has selected all 4 fruits, the query should then read:
select * from some_table where fruit IN ('apple', 'orange', 'peach', 'berry');
I will add the dilemma that I do not want to convert this query to become a PL/SQL based report. Rather, I want to leave it alone as a SQL Query. My initial attempt was to create a hidden item on the page and use APEX_UTIL.STRING_TO_TABLE with a loop to convert the shuttle data to a comma separated list. This worked great, however when I use the this hidden item in my query, it doesn't work properly. I hope I am explaining this well, but when I populate this hidden item, I will get something like this.
apple,orange
Great. Lets say the hidden item above is called P7_HIDDEN_VALUE (for example). I then try to reference it in my query, and here is the problem:
select * from some_table where fruit IN (:P7_HIDDEN_ITEM)
Do you see the problem. The item resolves itself to be apple,orange, when it really needs the quotes to be *'apple','orange'*
Help!!!!Hi,
This post might help
How to enable user to pick which row without using filter in interact. rpt?
Or Bens blog post
http://munkyben.wordpress.com/2010/11/16/handling-aggregated-strings-in-sql-reports/
Regards,
Jari -
Problems with update/insert and the ON clause
I have two rather identical mappings, both supporting SCD Type II. One of them works, the other one doesn't.
As in the SCD whitepaper, I have a split, that ultimately ends in a union, and then UPDATE/INSERTs into the target dimension. My problem is, that though using the matching_id for matching in one mapping, it is not allowed in the second mapping. The error is ORA-38104: The columns refererred in the ON-Clause cannot be updated "MyTable.MyId" (all loosely translated).
I just don't understand it, as it should be able to match the ID, and if not found, create a new record using INSERT.
I found a description of the error that sounded like this (https://cwisdb.cc.kuleuven.ac.be/ora10doc/server.101/b10744/e38001.htm):
ORA-38104: Columns referenced in the ON Clause cannot be updated: string
Cause: LHS of UPDATE SET contains the columns referenced in the ON Clause
Action: none
I just don't understand how this can be a problem, since I have to carry the surrogate key along, in order to assure that the proper records gets updated...
Anyone who can enlighten me on this one?
Regards
KimOh yes :) I was a quite active participant. What puzzles me is, that I cannot get mapping #2 to work. I have tried to do everything virtually alike, with regards to the surrogate key, and the extra mapping column.
My setting for the keys are as below:
Surrogate Matching
Load column when inserting: yes no
Load column when updating: yes no
Match column when updating: no yes
Load column when deleting: no no
Table best viewed in notepad :)
It "feels" like it's trying to update the surrogate key, instead of actually matching.
Regards
Kim -
Problem with to_date function
Hi everbody, please I need some help with this:
I need to convert to date the result of the concatenation of several columns of a table.
For example:
select feriado||' '||mes||' '||ano from calendario;
1 ENERO 1997
28 MARZO 1997
4 ENERO 1997
5 ENERO 1997
The data types are:
feriado -> number(2) Example: 28
mes -> varchar2(15) Example: 03
ano -> number (4) Example: 1997
I try to convert that concatenated string to date using this sentence:
select to_date(to_char(feriado||' '||mes||' '||ano),'DD-MM-YYYY') from calendario;
But a get a message error: day of month must be between 1 and last day of month.
The result that I expect is:
01-01-1997
28-03-1997
04-01-1997
Thanks in advance!We translate the month from spanish to English and then convert to date. Hope that helps
WITH T AS
( SELECT 1 feriado, 'ENERO' mes, 1997 ano FROM DUAL UNION ALL
SELECT 28, 'MARZO', 1997 FROM DUAL UNION ALL
SELECT 4, 'ENERO', 1997 FROM DUAL UNION ALL
SELECT 5, 'ENERO', 1997 FROM DUAL
SELECT TO_DATE (FERIADO || '-' ||
DECODE(MES, 'ENERO' , 'JANUARY' ,
'FEBRERO' , 'FEBRUARY' ,
'MARZO' , 'MARCH' ,
'ABRIL' , 'APRIL' ,
'MAYO' , 'MAY' ,
'JUNIO' , 'JUNE' ,
'JULIO' , 'JULY' ,
'AGOSTO' , 'AUGUST' ,
'SEPTIEMBRE' , 'SEPTEMBER' ,
'OCTUBRE' , 'OCTOBER' ,
'NOVIEMBRE' , 'NOVEMBER' ,
'DICIEMBRE' , 'DECEMBER') || '-' ||
ANO,'DD-MONTH-YYYY') DT
FROM T
{code} -
Problem with select....where IN statement
Hi,
i have the following select-statement in my z-abap:
DATA: s_kostl TYPE RANGE OF cosp-objnr,
DATA: s_kstar TYPE RANGE OF kstar,
SELECT (lv_feldname) INTO lv_betrag
FROM coss WHERE lednr = '00' AND
objnr IN s_kostl AND
gjahr = gjahr AND
kstar IN s_kstar AND
wrttp = '04' AND
versn = '000'.
now i get a dump, because s_kostl and/or s_kstar contains about 11.000 entries (DBIF_RSQL_INVALID_RSQL).
how can avoid this ? or how i have to 'rewrite' my SQL statment that the ranges-tabs s_kostl AND s_kstar can be processed
correctly ?
br, MartinHello.
I guess that the problem is not the limit or ranges, it is on the select statement. check it
It should be select single
yours:
{code}
SELECT (lv_feldname) INTO lv_betrag
FROM coss WHERE lednr = '00' AND
objnr IN s_kostl AND
gjahr = gjahr AND
kstar IN s_kstar AND
wrttp = '04' AND
versn = '000'.
{code}
correct:
{code}
SELECT SINGLE (lv_feldname) INTO lv_betrag
FROM coss WHERE lednr = '00' AND
objnr IN s_kostl AND
gjahr = gjahr AND
kstar IN s_kstar AND
wrttp = '04' AND
versn = '000'.
{code}
Try doing that change. Also, check frist without using LV_feldname, use the name of the field that u want to select, once u get the correct result change it back.
Regards
Miguel -
Problem with the Pivote Table order by Clause in OBIEE report
Hello All,
Can anyone help?
I am developing a report with 3 columns
1. Year
2. Customer name
3. Amount
I need Year in Ascending & Amount Descending (Group by Year and then Desc by amount)
In Table view data is displayed correctly, but in Pivote Table it’s not sorting correctly
Table View ( This is correct)
Year Customer Name Amount
2009, a1, 260,000.00
a2, 152,030.00
a3, 20,000.00
2008, a6, 193,080.00
2004, a7, 860.2
a8, 114.7
2003, a9, 200,243,813.40
a10, 91,351,364.10
Pivote Table Results as follows:
Year Customer Name Amount
2009, a1, 260,000.00
a2, 152,030.00
a3, 20,000.00
2008, a6, 193,080.00
2004, a7, 860.2
a8, 114.7
2003, x, 26,374,818.00
y, ....................
a9, 200,243,813.40
For year 2003 in place of 'x' value a9 value has to be shown........
Regards,
SMAYour post doesn't help a lot. Why it's still not solved ?
If it's caused by the ascendant order, the only way that you have is to pivot your table :
http://gerardnico.com/wiki/dat/obiee/presentation_service/obiee_transformation_table_to_pivot
And then you can set all sort that you want.
success
Nico -
A lot of burning problems with ITunes 6.. Where Can I Get ITunes 4 back?
Hello!
Few weeks ago I've installed ITunes 6 on my new pc.
At this point of time I could burn CDs, but the soundcheck didn't work. I've inserted a blanc disc and selected the playlist. But then the Burn- Button didn't get yellow. So I clicked on it and the CD was directly burned without aligning the volumes of the songs..
The second problem occured today. I've reinstalled iTunes 6 and now the message 'disc recorder not found' appears each time, when I wanna burn a disc.
What does It Mean?
Is It possible to switch back to iTunes 4. There I hadn't any problems..
[sorry my english is not soo good]Kcrusso wrote:
my Macbook Pro will not update to 11.4.
Why not?
Apple menu > Software update.
or here -> https://secure-appldnld.apple.com/iTunes11/031-07683.20140923.rewr3/iTunes11.4.d mg -
This has been an issue since acquisition in July. Very frustrating experience ! Most current update has been applied and since no fix. Patience is thin.
do you get the same screen as ive posted here > https://supportforums.blackberry.com/t5/BlackBerry-Q10/Facebook/m-p/2712239#M14753
this has been happening all over the world on various phone suppliers and networks and there has still been no official reply from what the problem could be.
its happened to me 3 times within a week and been fine ever since.
no idea if its a phone,3G,4G,supplier,facebook problem. -
How to use sql "IN" operator with named bind variable in where clause ?
Can one bind variable be used for the "IN" list ('1','2','3') ?
rob,
No worries. Glad it helped. Glad to see also that you're doing things right and trying to use bind variables ;)
May I suggest adding "SOLVED" to the title of the original post?
Best,
John
Maybe you are looking for
-
How do I remove credit card info from iTunes Store account?
How do I remove credit card information from my iTunes account?
-
Hi all, how to check the second copy in the smartform
HI all, I must print the text 'Duplicate Copy' in the second time printing document in the smarrform, i how can i check whether the pages that are given for printing and which one is the first copy of printing and which one is the second copy o
-
I have a new ipad and a iphone 5 which are under same Apple ID. I lso have a macbook that uses an older apple ID. How can I get the macbook to have same Apple ID as the other 2 devices
-
The form can not be saved if open with adobe reader
Hi all, I create a registration form using Adobe LiveCycle Designer 8.0.1291 then I Save As both into static and dynamic Then when I'm open the registration form file using Adobe Reader 9 then there's message appearing says "Please Fill it up this fo
-
Programmatically selecting a tab in panelTabbed
Hi, i have the following UI structure. af:paneltabbed ---af:iterator -------af:showdetailitem As you can see, i have the showdetailitem inside the af:iterator. so am currently in one particular tab, on click of a button i need to programmatically sho