Char to Date in Oracle - oracle

I am trying to run a very basic query off of a date which is defined as a char(18) the results for the field show as 07082015 (for 07/08/15).
select *
from ELECT_REMIT_RESP_HDR_FCT b
where b.OFFICE_NBR = '1234' and b.INV_NBR = '123456'
b.CRTD_DT = '07082015'
I have tried the to_date function and was received an error saying month was not valid.

I found the issue though it doesn't seem right, it ran and worked! I just removed the single quotes from the 07082015.

Related

Power BI Measure returning Blank when it shouldn't

I am trying to create a measure that will return a value for the number of issued receipts in the year 2020:
CALCULATE(SUM(Receipts[issued]), FILTER(Receipts, Receipts[Year] = 2020))
However, the measure keeps returning blank, even as a calculated column.
I've also tried
CALCULATE(SUM(Receipts[issued]), FILTER(Receipts, Receipts[Year].Year = 2020))
But that is returning an error saying the syntax for "Year" is incorrect.
The Year column is of datatype Date and is linked to a dimDate table on the Date column.
I am trying to retrieve the value 440,000. What am I doing wrong?
Try this.
CALCULATE(SUM(Receipts[issued]), YEAR(Receipts[Year]) = 2020)

Data still appearing in Oracle BI report when I dont give any input in the parameter

I have made a BI report using Oracle SQL. When I give an input to the parameter field, I get data. But, when I leave the parameter field as empty without giving any input, still the data appears instead of disappearing. What changes should I do in the SQL or OTBI dashboard to clear this problem?
**SELECT
AIA.INVOICE_NUM
, AHA.RELEASE_REASON
, DECODE (AHA.HELD_BY,'5', (SELECT ALC.DISPLAYED_FIELD
FROM AP_LOOKUP_CODES ALC
WHERE ALC.LOOKUP_TYPE(+) = 'NLS TRANSLATION'
AND ALC.LOOKUP_CODE(+) = 'SYSTEM'),
AHA.HELD_BY) "HELD BY"
, DECODE (AHA.LAST_UPDATED_BY,'5', (SELECT ALC.DISPLAYED_FIELD
FROM AP_LOOKUP_CODES ALC
WHERE ALC.LOOKUP_TYPE(+) = 'NLS TRANSLATION'
AND ALC.LOOKUP_CODE(+) = 'SYSTEM'),
AHA.LAST_UPDATED_BY) "RELEASE_BY_USER_NAME"
FROM
AP_HOLDS_ALL AHA
, AP_INVOICES_ALL AIA
WHERE 1=1
AND AHA.INVOICE_ID (+) = AIA.INVOICE_ID
AND (AIA.INVOICE_NUM IN (:INVOICE_NUM) OR COALESCE(NULL,:INVOICE_NUM) IS NULL)**

How can I use a PSQL timestamp function as a parameter in Ruby?

I am using a Ruby method to access task information from a Postgres database.
def query(statement, *params)
#logger.info("#{statement}: #{params}")
#db.exec_params(statement, params)
end
def tasks_completed_for_date(date="CURRENT_DATE")
sql = <<~SQL
SELECT tasks.name AS task_name,
timetable.start_at AS start_at,
timetable.end_at AS end_at,
timetable.duration AS duration,
timetable.start_at::date AS task_date
FROM tasks
JOIN timetable ON tasks.id = timetable.task_id
WHERE timetable.start_at::date = $1
AND timetable.duration IS NOT NULL
ORDER BY tasks.name ASC;
SQL
result = query(sql, date)
if result.ntuples > 0
result.map do |tuple|
{
task_name: tuple['task_name'],
start_at: tuple['start_at'].slice(11, 5),
end_at: tuple['end_at'].slice(11, 5),
total_time: tuple['duration'].slice(0, 5),
task_date: tuple['task_date'].slice(5, 5)
}
end
end
end
I want the default value to of the query to be whatever the current date is. I thought the best way to do this was to set the default parameter in the method called tasks_completed_for_date to the string CURRENT_DATE. This string would be interpreted by PSQL as the method CURRENT_DATE and return data based on that date. Instead I receive the following error:
ERROR: date/time value "current" is no longer supported
I am not using 'current' at all and I know that whatever it is, it's obsolete. Is there a way to pass a PSQL method to the query (in place of $1) as I am trying here that doesn't result in an error?
Your problem is that the $1 placeholder's value will be the string 'CURRENT_DATE', not the literal value CURRENT_DATE. The result is that you're effectively saying 'CURRENT_DATE'::date and that doesn't work:
psql> select 'current_date'::date;
ERROR: date/time value "current" is no longer supported
LINE 1: select 'current_date'::date;
^
You need to either get the literal value current_date into the query or find a string that properly casts to a date. The easiest thing would be to use 'now' since that casts nicely:
psql> select 'now'::date;
date
------------
2019-10-22
(1 row)
A quick change to the method's date argument's default value should be good enough:
def tasks_completed_for_date(date = 'now')
You can replace $1 with one of these methods:
DATE 'today'
DATE 'now'
Also you can use:
TIMESTAMP 'today'
So for example call method as tasks_completed_for_date('today')

Optional Multi-Value parameter in BIRT

I have a BIRT report that have 4 optional parameters.
startdate; enddate; stringparam and listparam (multi-value parameter).
I followed "bluish" code on this link How do I set a parameter to a list of values in a BIRT report?
and it works if I give either one or all of the value to the parameter. However, when I leave the parameter blank, I got a blank report (which is incorrect result).
This is my query:
select f1,f2,f3,f4
where f1 >= ? -- startdate parameter
or f2 <= ? -- endate paramter
or f4 = ? -- stringparam
and ( f3 in (''/*?listparam*/) )
I did query on my Oracle db to see what parameter is being passed to my query I got 'NULL' as the VALUE_STRING when I leave the parameters values as blank.
Any help is appreciated.
It sounds like you want to occasionally search for records on one to three of the 4 criteria in the parameters.
There are couple ways to do this:
One way is to use like, and set the default parameter value to % which is the wild card. when the parameter runs it returns all values. Be aware this can be problematic if the fields contain null.
or f4 like ?
So you would need to use something similar to below to return null values.
or (f4 is null
or f4 like ?)
I usually prefer to use "All" as my default parameter value, as you can see in the second "and" we look to see if the parameter value is All, if it is all values for PRODUCTTYPEM1.CATEGORY are returned, if it is anything else it looks for the entered valued in the field PRODUCTTYPEM1.CATEGORY.
where PRODUCTTYPEM1.ACTIVE = 't'
and DEVICE2M1.ISTATUS = 'In Use'
and ( 'All' = ?
or PRODUCTTYPEM1.CATEGORY = ?)
For this to work you will need two parameter entries, the first is for All, the second is for any values other then All.
I only have one Category parameter in the report, the second entry looks at the same parameter a second time if the parameter value is not All
The way this works. (expanded explanation by request)
Opening where statement, and simple second criteria for 'In Use'
where PRODUCTTYPEM1.ACTIVE = 't'
and DEVICE2M1.ISTATUS = 'In Use'
The third criteria is two parts set in parenthesis with an OR statement dividing the two parts
and ( 'All' = ?
or PRODUCTTYPEM1.CATEGORY = ?)
If the value of the parameter is All, then the first part of the statement is met, and the query skips everything thing else in the parenthesis. It is like not have the parameter in your SQL query at all.
If the value of the parameter is NOT all, the first part of the statement is not met so the query looks for the parameter value in field PRODUCTTYPEM1.CATEGORY.
Your final query will probably look something like this, though it is problematic in that we have a Default date of 'All', you probably want to use some kind of date for your default value like Jan 1, 1900.
select f1,f2,f3,f4
where f3 in (''/*?listparam*/)
AND ( 'All' = ?
OR f1 >= ?) -- startdate parameter
AND ( 'All' = ?
OR f2 <= ?) -- endate paramter
AND ( 'All' = ?
OR f4 = ?) -- stringparam

Symfony2/Doctrine DQL QueryException

So I'm attempting to do a query on a table that holds two foreign keys. This table basically sets a specific userID to be an "admin" of a specific zoneID in our application my DQL is this:
'SELECT z, zone FROM MLBPBeerBundle:TableZoneAdmins z JOIN z.zoneAdminsZID WHERE z.zoneAdminsPID = '.$userID .'AND zone.zoneId = z.zoneAdminsZID'
I am getting this error:
An exception has been thrown during the rendering of a template ("[Syntax Error] line 0, col 80: Error: Expected end of string, got 'z'") in "MLBPBeerBundle:Profile:index.html.twig" at line 10.
From looking at the query the part in question "line 0, col 80 is the beginning of z.zoneAdminsPID which means at least in my interpretation of the error that it expects the string to end right after the WHERE which makes no sense
What makes this even more confusing is I have already successfully used a similar query to get a team name out of our games table which has a foreign key to the teams id:
'SELECT g, team1 FROM MLBPBeerBundle:TableGame g JOIN g.gameWinnertid WHERE g.gameZoneid = '.$zoneId .'AND team1.id = g.gameWinnertid'
Thank you for any help you can provide this has left me stumped as to me I don't really see a difference in how to two queries operate other than the fact they are grabbing different data
I was able to fix this by not including the JOIN, Symfony is more automagical than I thought in the fact that
SELECT z FROM MLBPBeerBundle:TableZoneAdmins z WHERE z.zoneAdminsPID = '.$userID
From here the zoneAdminsZID was a proper zone Entity, now I believe this is lazily loading this entity aka not firing the query till I "derefence" the ZID but for us this works just fine

Resources