DATE_SUB named query MYSQL - ejb-3.0

Have a named query written like this
select u from User u where u.creationdate < DATE_SUB(CURDATE(),INTERVAL :upperDate DAY) and status=:status and reminder_counter =:counter
But I get a Syntax error parsing.
Any ideas`?
P

The function DATE_SUB you are using is MySQL specific, resulting in parsing error.
Create a named native query to use DATE_SUB function.
Else, can calculate the duration explicitly & then setting the parameter.

Related

How to resolve Information - Not a valid month error?

When running a PowerCenter session that uses an Oracle database view as a source the session fails with one of the following errors:
ORA-01843: Not a valid month.
In SqL developer it runs without any issues
Column : Report_date : Data Type : date.
In mapping parameter variable defined as String
Passing report date dynamically using param file &Control table
Select * from ABC
Where report_date=to_char(31-MAR-21,'DD-MON-RR')
--Error: not valid month
Could you please advise on it
You need to put single quotes around infa mapping parameter. Like this -
First calculate Report_Date and put the value in infa param file in correct format. You can use control table too. But you need to create a param file from that.
param file should look like
[folder.workflow.session]
$$Report_Date='21-Oct-2021'
Then in mapping you can call it in source qualifier as -
Select * from ABC Where report_date=to_char('$$Report_Date','DD-MON-RR')
single quote will ensure your data is passed as string.
Now, if youdont want to use param file, you can use control file as a new source and join with the SQL above to get desired result. But first approach is faster.

Does ::TIMESTAMP::DATE work in Java/Spring?

I have this code that runs a query in PostgreSQL:
SELECT planned,COUNT(*) AS results
FROM dashboard.event
WHERE event_start_adj::TIMESTAMP::DATE = '2020-04-05'
GROUP BY planned
This code actually works but the problem is when i insert this to Java Spring like this:
it gives me an error like this:
org.postgresql.util.PSQLException: ERROR: syntax error at or near ":"
Position: 80
I've tried removing it to event_start_adj = But it returns nothing since the data of my event_start_adj in PostgreSQL is timestamp without time zone That's why the query above extracts the date first. How can I fix this?
Obfuscation layers like JPA can't properly handle the :: operator, you need to rewrite it to use the CAST() operator instead:
WHERE cast(cast(event_start_adj as TIMESTAMP) as DATE) = '2020-04-05'
However if event_start_adj is already a timestamp the first case is useless, so it seems the following should be enough:
WHERE cast(event_start_adj as DATE) = '2020-04-05'
Unrelated to the problem at hand, but the expression you are using can't make use of an index on event_start_adj. So from a performance point of view, not casting at all would be better, but then you need to change the query to:
WHERE event_start_adj => date '2020-04-05'
AND event_start_adj < date '2020-04-06'
WHERE timestamp_column::::DATE = '2020-04-05'
The above worked for me in springboot native query.

Appending parameter to the table name removes the dot operator

I have given a parameter to my sql script which i use to create new tables.
CREATE TABLE TMP_TABLE1&1.
Now when i'm trying to perform an operation on the table using the parameter the dot operator is not showing.
I'm running a script form which i'm calling the sql script. I'm using a unix server.
this is the operation I'm trying to perform
select * from TMP_TABLE1&1 where TMP_TABLE1&1.LISTING_STATUS='N'
but after running the script with parameter as test1 it removes the '.' from the query and when I check the error log the log shows the query as
select * from TMP_TABLE1&1 where TMP_TABLE1test1LISTING_STATUS='N'
why is the dot operator going away? Is there a way around this approach?
Use double dot (..). Otherwise it is like concatenation operator in this context.
TMP_TABLE1&1..LISTING_STATUS='N'
Default CONCAT operator in sqlplus is .

How do I use a parameter within BI Publisher to update the table name I am querying in an Oracle Data set

I am trying to create a BI Publisher data model which runs the Oracle query below -
SELECT *
FROM audit_YYYYMM
(this should be the YYYYMM of the current date)
How do I setup a parameter default value within the datamodel to grab the YYYYMM from the SYSDATE?
How do I append this parameter within the data set SQL Query?
I tried SELECT * FROM audit_:Month_YYYYMM
(where I had a string parameter called Month_YYYMM)
This did not work.
You are going to have to use something like EXECUTE_IMMEDIATE. And you may have to make a separate PL/SQL package to launch rather than use the built in data definition stuff.
https://docs.oracle.com/cd/B19306_01/appdev.102/b14261/executeimmediate_statement.htm

How to put a raw SQL query in Sequel

I am trying to convert SQL code to Seqel to run it from my script. How do I convert this:
select code, count(1) as total
from school_districts
group by code order by total desc;
into Sequel? Or, is there a way to pass raw SQL to Sequel? Also the school_districts will be interpolated #{table_name}.
DB[:school_districts].select(:code).group_and_count(:code).reverse_order(:count)
is a Sequel way of executing that query. I did not however alias the count column, but I hope you can do with this.
Even though working in Sequel is preferable as it allows you to change DBMs without changing your code I would prefer you use the fetch method.
You can do it a couple ways:
Use []:
DB["your sql string"]
Use fetch:
DB.fetch("your sql string")

Resources