PROC compiler fails for connect with prior in case using 'NOCYCLE' - sql

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.

Related

GETTING ERROR-- ORA-00936:MISSING EXPRESSION for below query please help on this

SELECT CASE (SELECT Count(1)
FROM wf_item_activity_statuses_v t
WHERE t.activity_label IN ('WAITING_DISB_REQ',
'LOG_DDE',
'LOG_SENDBACK_DDE')
AND t.item_key IN(
SELECT r.i_item_key
FROM wf_t_item_xref r
WHERE r.sz_appl_uniqueid = '20400000988')
)
WHEN 0 THEN
(
delete
from t_col_val_document_uploaded p
WHERE p.sz_application_no = '20400000988'
AND p.sz_collateral_id = 'PROP000000000PRO1701'
AND p.i_item_key = '648197'
AND p.i_document_srno = '27' )
WHEN 1 THEN
(
DELETE
FROM t_col_val_document_uploaded p
WHERE p.sz_application_no = '20400000988'
AND p.sz_collateral_id = 'PROP000000000PRO1701'
AND p.i_document_srno = '28' )
ELSE NULL
END
FROM dual;
You need to recreate your query and make sure to follow the flow of the clauses properly, please check the next two links to get a better understanding :
[ORA-00936: missing expression tips]
How do I address this ORA-00936 error?
Answer: The Oracle oerr utility notes this about the ORA-00936 error:
ORA-00936 missing expression
Cause: A required part of a clause or expression has been omitted. For example, a SELECT statement may have been entered without a list of columns or expressions or with an incomplete expression. This message is also issued in cases where a reserved word is misused, as in SELECT TABLE.
Action: Check the statement syntax and specify the missing component.
The ORA-00936 happens most frequently:
1 - When you forget list of the column names in your SELECT statement.
2. When you omit the FROM clause of the SQL statement.
ora-00936-missing-expression
I hope this can help you.
You cannot use a simple select query like this. You have to use a PL/SQL block like below -
DECLARE NUM_CNT NUMBER := 0;
BEGIN
SELECT Count(1)
INTO NUM_CNT
FROM wf_item_activity_statuses_v t
WHERE t.activity_label IN ('WAITING_DISB_REQ',
'LOG_DDE',
'LOG_SENDBACK_DDE')
AND t.item_key IN(SELECT r.i_item_key
FROM wf_t_item_xref r
WHERE r.sz_appl_uniqueid = '20400000988');
IF NUM_CNT = 0 THEN
delete
from t_col_val_document_uploaded p
WHERE p.sz_application_no = '20400000988'
AND p.sz_collateral_id = 'PROP000000000PRO1701'
AND p.i_item_key = '648197'
AND p.i_document_srno = '27';
ELSIF NUM_CNT = 1 THEN
DELETE
FROM t_col_val_document_uploaded p
WHERE p.sz_application_no = '20400000988'
AND p.sz_collateral_id = 'PROP000000000PRO1701'
AND p.i_document_srno = '28' )
END IF;
END;

How to run procedure without parameter in Teradata

How to run procedure without parameter in Teradata
I'm trying with : call db1.proc_dbOSA()
Error Msg:
Call failed 3707: PROC_DBOSA: Syntax error, expected something
like a name or a Unicode delimited identifier between ‘(‘ and ‘)’
New Procedure with error result.
When i run only code then everything works ok.
REPLACE PROCEDURE db1.proc_dbOSA()
BEGIN
DELETE FROM db1.LOG_dbOSA;
INSERT INTO
db1.LOG_dbOSA
(StoreNo, IDX, Flow, Status, MRP, OSA_IDX, OSA_AC)
WITH a AS (
SELECT
c.StoreCode,
CAST(SUBSTRING(c.ArticleCode FROM 13 FOR 6) AS INT) AS IDX,
RpType,
CASE
WHEN c.MinimumTargetStockWrpl >= l.MinimumTargetStockWrpl THEN CAST(l.MinimumTargetStockWrpl AS INT)
WHEN c.MinimumTargetStockWrpl < l.MinimumTargetStockWrpl THEN CAST(c.MinimumTargetStockWrpl AS INT)
End AS StoreMin,
c.ValUnrestrictedStock
FROM
db1.tab1 c
INNER JOIN
(
SELECT
StoreCode,
ArticleCode,
MinimumTargetStockWrpl
FROM
db1.tab1
WHERE
ProcessingDate = CURRENT_DATE - 14
) l ON c.StoreCode = l.StoreCode AND c.ArticleCode = l.ArticleCode
WHERE
c.ProcessingDate = CURRENT_DATE AND c.MinimumTargetStockWrpl IS NOT NULL AND l.MinimumTargetStockWrpl IS NOT NULL AND l.MinimumTargetStockWrpl > 0
)
, t AS
(
SELECT
CAST(SUBSTRING(ArticleCode FROM 13 FOR 6) AS INT) AS IDX,
RpType,
ArticlesPlanner
FROM
DWH_db_V.STK_B_ARTICLE_DAY_V
WHERE
ProcessingDate = CURRENT_DATE AND StoreCode = 'DR04'
)
SELECT
a.StoreCode,
a.IDX,
t.RpType,
t.ArticlesPlanner,
a.RpType,
CASE
WHEN a.ValUnrestrictedStock > 0 THEN 1
WHEN a.ValUnrestrictedStock <= 0 THEN 0
End AS OSA_IDX,
CASE
WHEN a.ValUnrestrictedStock >= StoreMin THEN 1
WHEN a.ValUnrestrictedStock < StoreMin THEN 0
End AS OSA_AC
FROM
a
LEFT JOIN
t ON t.IDX = a.IDX;
End;
BTEQ Error:
+---------+---------+---------+---------+---------+---------+---------+----
Call proc_dbOSA;
Call proc_dbOSA;
$
* Failure 3707 Syntax error, expected something like '(' between the word
'proc_dbOSA' and ';'.
Statement# 1, Info =18
* Total elapsed time was 1 second.
Call proc_dbOSA();
* Failure 3707 PROC_DBOSA:Syntax error, expected something like a name or
a Unicode delimited identifier between '(' and ')'.
* Total elapsed time was 1 second.
Stored procedures do not support the following:
EXPLAIN and USING request modifiers within a stored procedure
EXECUTE macro statement
WITH clause within a stored procedure.
Stored procedures, as well as macros, do not support the following query logging statements:
BEGIN QUERY LOGGING
END QUERY LOGGING
FLUSH QUERY LOGGING
REPLACE QUERY LOGGING

Table used in cursor select is restructured from compile-time to run-time

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

ORA-01847 day of month must be between 1 and last day of month - but data is OK

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.

Visual Fox Pro 6.0 Query of Logical DataType not working!

My current system has a query to generate a tax report. The problem is that sometimes orders go into our system that never get submitted but are still counted in the tax report. The flag that sets an order as submitted is called 'complete' and it will be set to TRUE using the logical datatype.
Two issues arise from the following code. First, it seems as though the field I am using as a constraint 'complete' is a FoxPro reserved function because it lights up in blue while in FoxPro. The second problem is that it will not exclude those records that never get submitted (basically the constraint is not working).
EDITED CODE:
sele bkmast
set order to county
set filt to between(sysdate, m.ld_start, m.ld_end)
go top
m.lh_countylines = ''
select 000000.0000 as ordamt, import, county, 00000000.00 as amount, date() as start, date() as end dist;
from bkmast ;
where !empty(county) ;
.and. alltrim(county) !='0' ;
.and. alltrim(county) !='8.00_Wyoming' ;
.and. alltrim(county) !='Select County' ;
order by county ;
into table countytax
m.ln_total=0
m.ln_countamt = 0
scan
m.lc_county = alltrim(county)
sele bkmast
seek m.lc_county
sum tax to m.ln_amt while county=m.lc_county
seek m.lc_county
sum ordamt to m.ln_ordamt while county=m.lc_county
sele countytax
replace ordamt with m.ln_ordamt
replace amount with m.ln_amt
replace startDate with m.ld_start
replace endDate with m.ld_end
m.ln_countamt = m.ln_countamt + ordamt
m.ln_total = m.ln_total + amount
m.lh_countylines = m.lh_countylines+elemerge(html_frm("TAXCOUNTY1"))
endscan
Any help is greatly appreciated.
Having worked with Foxpro since FoxBase back in '87, I've never known a "complete" command, nor is it directly documented in the VFP Help (yet as stated, DOES highlight in blue as a function call via Complete() ). Additionally the .AND. is long ago old indicator of query. The "End" though IS a keyword. I would try by qualifying the columns by adding the alias to the query and changing End to EndDate (and pairing up Start to StartDate), such as...
From the result of your other comment, I would do your pre-querying directly in the select statement, then do your updates...
SELECT
bk.Import,;
bk.county,;
sum( bk.OrdAmt ) AS OrdAmt,;
sum( bk.Tax ) AS Amount,;
m.ld_Start AS startDate,;
m.ld_End AS endDate;
FROM ;
bkmast bk ;
where ;
sysdate between m.ld_start and m.ld_End;
AND NOT empty( ALLTRIM( bk.county )) ;
AND NOT alltrim( bk.county ) == '0' ;
and NOT alltrim( bk.county ) == '8.00_Wyoming' ;
and NOT alltrim( bk.county ) == 'Select County' ;
AND bk.complete;
group by ;
bk.Import,;
bk.county;
order by;
bk.county ;
into;
table countytax
In this case, since the aggregations of order amount and tax, you don't need to go back to the BKMast table... its already done... you can just cycle through the result set directly. The only thing left would be to sum up the total tax and order amounts... If those variables are not used within your elemerge(html_frm("TAXCOUNTY1")) call, you can just pre-sum those directly
select CountyTax
sum OrdAmt, Amount to m.ln_CountAmt, m.ln_Total
scan
*/ These two already summed up from before the scan loop
** m.ln_countamt = m.ln_countamt + ordamt
** m.ln_total = m.ln_total + amount
*/ Now, continue with the eleMerge() function which will already have the
*/ values in the CountyTax table already summed up
m.lc_county = alltrim(county)
m.lh_countylines = m.lh_countylines+elemerge(html_frm("TAXCOUNTY1"))
endscan
What happens if you run a query where the only this in the WHERE clause is complete:
SELECT ;
000000.0000 OrdAmt,;
bk.Import,;
bk.county,;
00000000.00 Amount,;
date() as startDate,;
date() as endDate;
from bkmast bk;
where bk.Complete ;
into cursor csrTest
Does that get the right set of records? What I'm getting at is that maybe the Complete field doesn't contain what you think it does.
Tamar