I'am using micronaut data jpa and the query works fine with oracle but not with H2 database.
here is the query :
delete from myTable
where (some conditions)
AND (to_char(startDate, 'DY', 'NLS_DATE_LANGUAGE = ENGLISH') IN ('MON', 'TUE', 'WED', 'THU', 'FRI'))
(some conditions)
The problem is the query do the right job in the oracle database but my tests fails in H2 database.
the test pass only when i replace ('MON', 'TUE', 'WED', 'THU', 'FRI') by (1,2,3,4,5), but it doesn't work well since the first day in America is Sunday and not Monday, so it shifts by one day.
Thanks in advance for your help.
i've tried many solutions like setting NLS_DATE_LANGUAGE...
Related
So I worked on a bunch of queries yesterday, and before I could get to exporting the results to an external file, my database went down. Is there any way to see the results of your past few queries in SQL Developer? I know there are ways to see your past queries, but I am looking for the results of my queries. Finding them would save me and my team a lot of rework.
Any help would be much appreciated. Thanks!
Edit: I am asking how to find the results of the SQL queries I ran yesterday. Not the queries themselves.
Use a SELECT statement with an AS OF clause. This retrieves data as it existed at some point in the past.
For example, this query returns the record from current state for Chung.
SELECT * FROM employees
WHERE last_name = 'Chung';
And below query retrieves the state of the record for Chung at 9:30AM, April 4, 2004:
SELECT * FROM employees
AS OF TIMESTAMP
TO_TIMESTAMP('2004-04-04 09:30:00', 'YYYY-MM-DD HH:MI:SS')
WHERE last_name = 'Chung';
You can also restore like this:
INSERT INTO employees
(SELECT * FROM employees
AS OF TIMESTAMP
TO_TIMESTAMP('2004-04-04 09:30:00', 'YYYY-MM-DD HH:MI:SS')
WHERE last_name = 'Chung');
Drag the queries from SQL history to worksheet and modify with AS OF clause.
Refer to the source of this answer for more info:
https://docs.oracle.com/cd/B28359_01/appdev.111/b28424/adfns_flashback.htm#g1025568
I have the following SQL which should return all data up to 6.30am tomorrow. It has been working correctly until today (30/6/2016).
SELECT TO_CHAR(TRUK.THEDATE,'DD/MM/YY HH24:MI') DAT
FROM TRUK
WHERE TO_CHAR(TRUK.THEDATE,'DD/MM/YY HH24:MI') <= TO_CHAR(TO_DATE(sysdate + 1) + 6.5/24,'DD/MM/YY HH24:MI')
ORDER BY TRUK.THEDATE
PROBLEM
Today the data returned does not include data for 30th June,which i know exists but only 1st July. When i comment out the where clause, then all data is returned but of course this includes data AFTER 6.30am for the next day which i don't want returned.
I have searched in vain for an answer and would greatly appreciate some assistance with this. How Could the where clause be written differently to prevent this?
My desired result is that all records in the database are returned up to 6.30am the following day.
cheers
You're comparing strings, but you should be comparing dates.
Adjust your where clause to this and it'll work:
WHERE truk.thedate <= trunc(sysdate) + to_dsinterval('1 06:30:00')
As you may know, Oracle's limits are -4713 to +9999 for full year in date fields.
I'm working on a 11g database and I've found sereval records with a year out of range (-5386, -5459, -5592 etc).
On SQL Developper I tried :
alter session set nls_date_format='DD/MM/YYYY HH:MI AD';
select the_date_field, to_char(the_date_field, 'DD/MM/YYYY HH:MI AD') FROM the_table WHERE ...
It gives me the result:
26/09/5386 05:23 AV.J.-C. | 00/00/0000 00:00 00000000
(fr display, "av" means "before")
I got an impossible date and "TO_CHAR" function can't work and returns "00/00/0000" (yeah, another impossible date!) ; but SQL Developper display this field well.
I also tried :
select the_date_field + 1 FROM the_table WHERE ...
And I obtain: ORA-01841: (full) year must be between -4713 and +9999, and not be 0
So it really looks like a real Date.
"describe the_table" gives : "the_date_field DATE"
This data was inserted by a j2ee application using Hibernate v3.0.5, with oracle.jdbc.driver.OracleDriver v12.1.0.2.0.
Hibernate property "the_date_field" is also set to "timestamp" (it shouldn't be a problem, indeed?).
Issue repeats over time but I still didn't figure out how to reproduce it.
The others billions of records in this old application have no problem.
Anyone has an idea of what's going on?
I have a table person{id,personName,birthDate}. In the table I have to get all the person details by their birthDate with out comparing its time. I have the following query
Query q = entitymanager.createQuery(select p from person p where
CAST(p.birthDate as date) = :birthdate);
q.setparameter("birthdate",new Date(),TemporalType.DATE) ;
When I test the above query using mysql, it gives the correct result. But it is not functioning correctly in Oracle. I tried the between...and logic by setting the starting time as 0:0:0 and the ending time as 23:59:59. Is there any other alternative.
I am using JPA 1.0 with hibernate as a service provider. Thanks in advance for your help.
I'm trying to write this query using Hibernate 3 and Oracle 10.
from Alert alert
where alert.expiration > current_date()
order by alert.priority, alert.updated, alert.name
It's creating SQL like this -
Hibernate: select alert0_.ANNOUNCEMENTS_ID as ANNOUNCE1_1_, alert0_.ANNOUNCEMENT
S_NAME as ANNOUNCE2_1_, alert0_.ANNOUNCEMENTS_PRIORITY as ANNOUNCE3_1_, alert0_.
ANNOUNCEMENTS_EXPIRATION as ANNOUNCE4_1_, alert0_.ANNOUNCEMENTS_UPDATE_DATE as A
NNOUNCE5_1_ from NYC311_ANNOUNCEMENTS alert0_ where (alert0_.ANNOUNCEMENTS_EXPIR
ATION>current_date()) order by alert0_.ANNOUNCEMENTS_PRIORITY , alert0_.ANNOUNC
EMENTS_UPDATE_DATE , alert0_.ANNOUNCEMENTS_NAME
I'm getting all of these wacky errors like "missing right parenthesis" when there is apparently perfectly balanced parenthesis.
Why is Oracle freaking out at this? Is there a better way to write my HQL query?
Shouldn't it be current_date?
Hibernate will translate it to the proper dialect.
I did not find a real "Hibernate will translate this to that" reference documentation, but the expression, in general, can be found in HQL Expressions for Hibernate 4.3.
Then there is the Java Persistence API 2.0 (JPA) specification which defines expressions for the Java Persistence query language (JPQL) and their meaning e.g. for current_date:
4.6.17.2.3 Datetime Functions functions_returning_datetime:= CURRENT_DATE | CURRENT_TIME | CURRENT_TIMESTAMP The datetime functions
return the value of current date, time, and timestamp on the database
server.
Is current_date() a Hibernate function?
I would use sysdate instead. like this:
where alert.expiration > sysdate
Or to ignore time of day:
where alert.expiration > trunc(sysdate)