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.
Related
I'm getting the following error when I run this database view in psql (ERROR: division by zero). Even I can't access my table in rails console If anyone has any solution for this error so please comment on it will be very helpful thanks in advance.
select
(exam_id || '00' || quarter)::bigint as id,
account_id,
exam_id,
quarter,
quarter_label,
count(id) as assessments,
max(banding_percentage) as top_assessment_percentage,
min(banding_percentage) as bottom_assessment_percentage,
round(avg(banding_percentage),2) as avg_assessment_percentage
from report_assessments
group by account_id, exam_id, quarter, quarter_label;
To avoid running into division by zero exceptions you should use nullif, so that you can catch this 0 and replace it by null, e.g.
WITH j (v1,v2) AS (
VALUES (1.0,0.0),(10.0,3.0)
)
SELECT v1/nullif(v2,0) AS div FROM j;
div
--------------------
3.3333333333333333
(2 Zeilen)
You Need to do something like this.
It works in my case:
Negotiation.find(
:all,
conditions: conditions_hash('negotiation'),
select:
'CASE
sum(banding_percentage)
WHEN
0
THEN
NULL
ELSE
sum(total_percentage) / sum(banding_percentage)
END as error_check'
).first
I'm getting CALL Failed. [7691] SP_name:Table used in cursor select is restructured from compile-time to run-time.
I believe its because I have loop over dates in my stored procedure:
If min_mnth <= max_mnth THEN
LoopMnth:
FOR cc_mnth AS cc_cdates CURSOR FOR
SELECT To_Char(calendar.calendar_date, 'yyyy-mm') as mnth
from sys_calendar.calendar
where To_Char(calendar.calendar_date, 'yyyy-mm') between min_mnth and max_mnth
and mnth not in (select report_mnth from tb1)
and mnth >= '2017-08'
group by 1 order by 1
.....
Interesting fact, that that such procedure sometimes work, mostly then I had less loop iterations.
I have found only this relevant information https://community.teradata.com/t5/Database/Error-7691-P1-Table-used-in-cursor-select-is-restructured-from/td-p/36691
They suggests SET SESSION DATEFORM = INTEGERDATE - same error.
What is this error about and how to fix it?
Then you get such error, just
1) SET SESSION DATEFORM = INTEGERDATE
2) Recreate your procedure
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.
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.
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.