Get all vouchers from CRS_T_RES_VOUCHER where IS_OFFLINE_BOOKING is true and (system date - CRS_T_RES_REGISTRATION. UPDATED_DATE) > offline Cancellation Threshold
Offline Cancellation Threshold can be taken from CRS_T_HTL_PARAMETER table.
PARAM_KEY - IBE_OFFLINE_CANCELLATION_THRESHOLD
SELECT v.VOUCHER_NUMBER
FROM CRS_T_RES_VOUCHER v,
CRS_T_RES_REGISTRATION regi,
CRS_T_HTL_PARAMETER para
WHERE v.is_offline_booking = '1'
AND TRUNC (SYSDATE) - TRUNC (v.updated_date) > para.param_value WHERE para.param_key = 'IBE_OFFLINE_CANCELLATION_THRESHOLD'
I encounter ORA-00933: SQL command not properly ended
I got it
need to deal with nested query
SELECT v.VOUCHER_NUMBER
from CRS_T_RES_VOUCHER v, CRS_T_RES_REGISTRATION regi, CRS_T_HTL_PARAMETER para
where v.is_offline_booking = '1' and
TRUNC (SYSDATE) - TRUNC (v.updated_date) > (select TRUNC (para.param_value)
from CRS_T_HTL_PARAMETER para where para.param_key = 'IBE_OFFLINE_CANCELLATION_THRESHOLD')
The reason you are getting the error is that you have two written where clauses twice. Change:
where para.param_key = 'IBE_OFFLINE_CANCELLATION_THRESHOLD'
To:
and para.param_key = 'IBE_OFFLINE_CANCELLATION_THRESHOLD'
According to your last comment, try this:
SELECT v.VOUCHER_NUMBER
FROM CRS_T_RES_VOUCHER v,
CRS_T_RES_REGISTRATION regi,
CRS_T_HTL_PARAMETER para
WHERE v.is_offline_booking = '1'
AND TRUNC (SYSDATE) - TRUNC (v.updated_date) >
(select distinct TRUNC(para.param_value) from CRS_T_HTL_PARAMETER
WHERE para.param_key = 'IBE_OFFLINE_CANCELLATION_THRESHOLD')
Please, note that the query above will work only if there are not several param_values for 'IBE_OFFLINE_CANCELLATION_THRESHOLD' param key.
Related
When running the below script I get the error "ORA-00932: inconsistent datatypes: expected DATE got NUMBER". Doesn't give me a line on which the error is at. Using Oracle DB.
with reg_det as (
SELECT MCI.MEASR_COMP_ID
FROM D1_MEASR_COMP_IDENTIFIER MCI, D1_MEASR_COMP_IDENTIFIER MCR, D1_MEASR_COMP MC, D1_DVC_CFG DC, D1_DVC_IDENTIFIER DVI
WHERE MCI.MC_ID_TYPE_FLG = 'D1EI'
AND MCI.MEASR_COMP_ID = MC.MEASR_COMP_ID
AND REGEXP_SUBSTR(MCI.ID_VALUE, '[^-]+', 1, 13) = 'INT'
AND MCR.MC_ID_TYPE_FLG = 'CMRN'
AND MCR.ID_VALUE = :REG
AND MCR.MEASR_COMP_ID = MC.MEASR_COMP_ID
AND MC.DEVICE_CONFIG_ID = DC.DEVICE_CONFIG_ID
AND DVI.D1_DEVICE_ID = DC.D1_DEVICE_ID
AND DVI.DVC_ID_TYPE_FLG = 'D1SN'
AND DVI.ID_VALUE = :MTR),
gap_dates as (select to_char((:SDTTM + level -1),'YYYY-MM-DD') as read_date, 0 as interval_count, 'M' as quality, 0 as daily_load
from dual
connect by level <= (:EDTTM - :SDTTM) )
,read_data as (SELECT to_char(trunc(MSRMT_DTTM - 1/1440),'YYYY-MM-DD') as read_date,
count(1) as interval_count,
case
when min(msrmt_cond_flg) > 500000 THEN 'A'
when min(msrmt_cond_flg) > 400000 and min(msrmt_cond_flg) <= 500000 then 'F'
when min(msrmt_cond_flg) > 300000 and min(msrmt_cond_flg) <= 400000 then 'S'
when min(msrmt_cond_flg) > 200000 and min(msrmt_cond_flg) <= 300000 then 'E'
when min(msrmt_cond_flg) <= 200000 then 'M' end as quality,
sum(msrmt_val) as daily_load FROM REG_DET REG, D1_MSRMT DATA
WHERE DATA.MEASR_COMP_ID = REG.MEASR_COMP_ID
AND MSRMT_DTTM > :SDTTM
AND MSRMT_DTTM <= (:EDTTM + 1)
GROUP BY trunc(MSRMT_DTTM - 1/1440))
select * from read_data
union
select * from gap_dates a where 1=1 and not exists (select 1 from read_data b where a.read_date = b.read_date);
A lot of the code provided is impossible to check as we don't know the structure of your tables nor the datatypes of the columns. I tried to cut the code in pieces to do the tests, and the only part that is returning ORA-00932 error is in the WHERE clause of the read_data cte.
I'm not sure if that is your problem, but if it is it will not be the only one. What I wanted to say is that even if you correct this one there will be more errors. Let me explain - the reported error could be simulated if you bind a character value to your :EDTTM variable. Other errors would pop up if :SDTTM is of type character.
Here is the test using construction from the mentioned WHERE clause:
WHERE
DATA.MEASR_COMP_ID = reg.MEASR_COMP_ID
AND MSRMT_DTTM > :SDTTM
AND MSRMT_DTTM <= (:EDTTM + 1)
The last condition tested on DUAL table (assuming that MSRMT_DTTM is of type DATE) compares DATE to CHARACTER + NUMBER like in this SQL
SELECT 'anything' FROM DUAL WHERE SYSDATE <= '24-SEP-22' + 1
This results with:
/*
SQL Error: ORA-00932: inconsistent datatypes: expected DATE got NUMBER
00932. 00000 - "inconsistent datatypes: expected %s got %s"
*/
If any or both of your %DTTM variables are of type character then there will be more errors (not ORA-00932) throughout your code. Additionaly, you should really consider the advice form comments to use ANSI SQL join syntax. Regards...
I am very new to PROC and I was compiling following query in .pc file,
`
SELECT * FROM CUST
WHERE CUSTOMER_ID = :sqli_customer_id
START WITH SUBSCRIBER_NO = :sqli_subscriber_no
CONNECT BY NOCYCLE PRIOR PRV_CTN = SUBSCRIBER_NO
ORDER BY ROWNUM DESC
`
following query fails to compile in PROC complier
but when I remove the NOCYCLE from query, file gets successfully compiled.
I get following error with NOCYCLE:
PCC-S-02201, Encountered the symbol "PRIOR" when expecting one of the following:
= ( * < > + - / . # ^= | != <= >= <> at, not, between, in, is, like, day, hour, minute, month, second, year,
The symbol "*" was substituted for "PRIOR" to continue.
`
Any suggestion will be helpful.
Thanks,
Nitin T.
I was doing some SQL on Oracle and I found something weird.
I have that FOR loop that iterate over a list of date (Stored as VARCHAR2):
FOR current_date in (SELECT DISTINCT DATCRE as datcre
FROM EVE cdv
WHERE cdv.datcre BETWEEN p_datedeb AND p_datefin)
LOOP
[queries]
END LOOP;
I need to use current_date in the where clause of the following query:
SELECT COUNT(cdv.numeve)
INTO nb
FROM EVE cdv
WHERE cdv.datcre = current_date.datcre;
This query doesn't work, and I get a ORA-00933: SQL command not properly ended.
Now, if I declare a curDate VARCHAR2(10) variable, store current_date.datcre in it and use it in the query, it works fine:
curDate := (current_date.datcre);
SELECT COUNT(cdv.numeve)
INTO nb
FROM EVE cdv
WHERE cdv.datcre = curDate;
Am I missing something or is this just the way Oracle works ?
Problem is solved - see end of this post.
when i call to_date in select clause everything works fine - get a resultset of 12 records:
select value1,to_date(value1,'DD.MM.YYYY')
from variableindex
where
value1 is not null
and value1 <> '0'
and creation_time_ > to_timestamp('20140307','YYYYMMDD')
order by 2
returns
'VALUE1' 'TO_DATE(VALUE1,'DD.MM.YYYY')'
'25.11.2013' 25.11.13
'12.03.2014' 12.03.14
'12.03.2014' 12.03.14
'12.03.2014' 12.03.14
'12.03.2014' 12.03.14
'12.03.2014' 12.03.14
'14.03.2014' 14.03.14
'14.03.2014' 14.03.14
'14.03.2014' 14.03.14
'14.03.2014' 14.03.14
'20.03.2014' 20.03.14
'20.03.2014' 20.03.14
Every datestring has been converted as expected.
If i add the following line to where clause
and to_date(value1,'DD.MM.YYYY') < to_date('20140301','YYYYMMDD')
i'll receive:
ORA-01847: Tag des Monats muss zwischen 1 und letztem Tag des Monats liegen
01847. 00000 - "day of month must be between 1 and last day of month"
*Cause:
*Action:
No it really gets nasty... i changed my query to
where id_ in (...)
and used the same 12 recordsets ids as in original query. No Error...
Many thanks to #GordonLinoff - this is how i use the query now:
select value1,to_date(value1,'DD.MM.YYYY') from variableindex
where
(case when value1 <> '0' then to_date(value1,'DD.MM.YYYY') end) > to_timestamp('20131114','YYYYMMDD')
and creation_time_ > to_timestamp('20140307','YYYYMMDD')
order by 2;
This is your query with the where clause:
select value1, to_date(value1,'DD.MM.YYYY')
from variableindex
where value1 is not null and
value1 <> '0' and
creation_time_ > to_timestamp('20140307', 'YYYYMMDD') and
to_date(value1 'DD.MM.YYYY') < to_date('20140301', 'YYYYMMDD')
order by 2;
Oracle does not guarantee the order of processing of clauses in the where. So, value <> '0' is not guaranteed to run before the last condition. This happens to be a big problem on SQL Server. One solution is to use a case statement:
select value1,to_date(value1, 'DD.MM.YYYY')
from variableindex
where value1 is not null and
value1 <> '0' and
creation_time_ > to_timestamp('20140307', 'YYYYMMDD') and
(case when value <> '0' then to_date(value1, 'DD.MM.YYYY') end) <
to_date('20140301', 'YYYYMMDD')
order by 2;
Rather ugly, but it just might solve your problem.
If you're using OracleParameter in SQL with parameter name and value binding, check you set the oracleCommand.BindByName = true then it'll bind by name, and not by parameter adding order.
I just want to add that we got the same ORA-01847 error when the user's web browser language encoding was changed from English to Portuguese.
The line of code that failed was:
IF TO_DATE(NEW_DATE,'DD-MON-YYYY') = TO_DATE(OLD_DATE,'DD-MON-YYYY') THEN
Which was fixed by rewriting it to:
IF TO_CHAR(NEW_DATE,'DD-MON-YYYY') = TO_CHAR(OLD_DATE,'DD-MON-YYYY') THEN
It appears Oracle detected the change of language and assumed the date value will be formatted for the Portuguese locale.
there are so many post about this error. However i am not able to resolve my code. i am trying to run this SQl in shell script, but it is giving me this error. ORA-00923: FROM keyword not found where expected
SELECT
wrk.WO_ID,
srq.CSDL_SEQ_NO,
srq.ASDL_CMD,
srq.HOST_CLLI AS NEP,
MIN(srq.START_DTS) AS start_dt,
MAX(srq.COMP_DTS) AS comp_dt,
((MAX(srq.COMP_DTS)-MIN(srq.START_DTS)) * 86400) AS proc_time
FROM
SARMPRD1.TBL_ASDL_LOG srq,
sarmprd1.tbl_wrk_ord wrk
WHERE
srq.srq_id = wrk.srq_id
AND srq.start_dts > TRUNC(sysdate) + 7.5/24
AND wrk.WO_STAT = '104'
GROUP BY
wrk.WO_ID,
srq.SRQ_ID,
srq.ASDL_UNID,
srq.CSDL_SEQ_NO,
srq.ASDL_CMD,
HOST_CLLI
ORDER BY
proc_time DESC;
Can anyone please help me where is the problem?
Problem lies in the concatenation operator. Since you concatenate all the columns, you cannot use 'AS NEP', 'AS START_DT', etc. Remove those and it will work fine, remember that you are outputting practicaly only one column, so multiple aliases don't work.
For an useful alternative, see this thread.
You have syntax errors, with concatenate operator ...
here's your original:
select 'WO_ID, SEQ_NO, ASDL,NE, START_TIME, COMP_DT, PROC_TIME' from sys.dual;
SELECT wrk.WO_ID||','||srq.CSDL_SEQ_NO||','||srq.ASDL_CMD||','||srq.HOST_CLLI As NEP||','||min(srq.START_DTS) as start_dt||','||max(srq.COMP_DTS) as comp_dt||','||((max(srq.COMP_DTS)-min(srq.START_DTS)) * 86400) as proc_time FROM SARMPRD1.TBL_ASDL_LOG srq, sarmprd1.tbl_wrk_ord wrk where srq.srq_id = wrk.srq_id and srq.start_dts > trunc(sysdate) + 7.5/24 and wrk.WO_STAT = '104' group by wrk.WO_ID, srq.SRQ_ID, srq.ASDL_UNID, srq.CSDL_SEQ_NO, srq.ASDL_CMD,HOST_CLLI order by proc_time desc
Try this:
select 'WO_ID, SEQ_NO, ASDL,NE, START_TIME, COMP_DT, PROC_TIME' from sys.dual;
SELECT wrk.WO_ID||','||srq.CSDL_SEQ_NO||','||srq.ASDL_CMD||','||srq.HOST_CLLI As NEP||','||min(srq.START_DTS) as start_dt,
max(srq.COMP_DTS) as comp_dt,
((max(srq.COMP_DTS)-min(srq.START_DTS)) * 86400) as proc_time
FROM SARMPRD1.TBL_ASDL_LOG srq, sarmprd1.tbl_wrk_ord wrk
where srq.srq_id = wrk.srq_id
and srq.start_dts > trunc(sysdate) + 7.5/24
and wrk.WO_STAT = '104'
group by wrk.WO_ID, srq.SRQ_ID, srq.ASDL_UNID, srq.CSDL_SEQ_NO, srq.ASDL_CMD,HOST_CLLI
order by proc_time desc
I don't see the solution to your problem, but here is a suggestion:
Create a new script with just a few items from your original script in it. Run it and see if it works. If so, add a bit more code and verify that works. Continue doing this until it fails. The problem line should then be easily identified.