Teradata Error on Unicode delimited identifier or an 'UDFCALLNAME' - syntax-error

Trying to figure out why I am getting a Teradata exception: [Teradata Database] [3707] Syntax error, expected something like a name or a Unicode delimited identifier or an 'UDFCALLNAME' keyword between ')' and the
select ma.MHKAUDITLOGINTERNALID as id,
cast(MHK_CONTENT as varchar (8000)) as MHK_CONTENT,
AUDITDATETIME, CREATEDBY, MHKAPPEALSINTERNALID, MHKIREINTERNALID
from vcoreMEDHOK_MHK_Audit as ma
Where ma.AUDITDATETIME >= DATE '2021-08-01'
and ma.MHKAPPEALSINTERNALID Is NOT NULL
or ma.AUDITDATETIME >= DATE '2021-08-01'
and ma.MHKAPPEALSINTERNALID <> ' '
or ma.AUDITDATETIME >= DATE '2021-08-01'
and ma.MHKAPPEALSINTERNALID <> ' - ' )
select dt.id, TokenNum,regexp_replace(MHK_CONTENT, '<b>|</b>') as NewContent--- |<\/b> --- ADT, MHKAPPEALSINTERNALID,MHKIREINTERNALID ,CreatedBy,AUDITDATETIME, CREATEDBY, MHKAPPEALSINTERNALID, MHKIREINTERNALID, --- oreplace (Token,'<BR>','')
FROM TABLE (RegExp_Split_To_Table(t.id, t.MHK_CONTENT, '<br/>*', 'i')) --- split whenever '<BR/>' occurs t.TokenNum, t.MHK_CONTENT, t.ADT, t.MHKAPPEALSINTERNALID,t.MHKIREINTERNALID,t.CreatedBy, ---'<b>|<\/b>|<BR>|</BR>|<br/>| - *', 'i' --- '<b>|<\/b>|<br/>|<BR>|</BR>*', 'i')
RETURNS (id BIGINT, TokenNum INT, MHK_CONTENT VARCHAR(8000), CreatedBy VARCHAR(100)))))as dt ```

OK i did correct that it got snippy with me again: [Teradata Database] [3706] Syntax error: expected something between a string or a Unicode character literal and ')'.

Related

ORA-01722: invalid number when a specific number 112 is used

WITH
TEST_RESULT_CTE AS
(SELECT R.DSDW_RESULT_ID,
R.PARAM_VALUE AS TEST_ID
FROM SLIMS_POC_RESULT_DETAIL R
JOIN SLIMS_POC_PARAMETER P ON P.PARAM_ID=R.PARAM_ID
WHERE P.PARAMETER_NAME='TEST_ID' AND P.CATEGORY = 'Result' )
SELECT * FROM
(
SELECT S.SAMPLE_ID, R.DSDW_RESULT_ID, PARA.PARAMETER_NAME as PNAME, R.PARAM_VALUE as PVALUE
FROM SLIMS_POC_RESULT_DETAIL R
JOIN TEST_RESULT_CTE TR ON TR.DSDW_RESULT_ID = R.DSDW_RESULT_ID
JOIN SLIMS_POC_TEST T ON T.TEST_ID = TR.TEST_ID
JOIN SLIMS_POC_SAMPLE S ON S.SAMPLE_ID = T.SAMPLE_ID --AND S.SAMPLE_ID = to_char(113)
JOIN SLIMS_POC_PARAMETER PARA ON PARA.PARAM_ID=R.PARAM_ID AND PARA.CATEGORY='Result'
)
Result_Data
PIVOT
(
MAX(PVALUE) FOR PNAME IN ( 'TEST_ID', 'RESULT_NAME', 'UNIT', 'RESULT_TEXT', 'VALUE', 'STATUS', 'ENTERED_ON', 'ENTERED_BY', 'RESULT_TYPE' )
) PIVOTED_TAB
WHERE SAMPLE_ID > 111
ORDER BY SAMPLE_ID;
The above sql Query provides an output, without any error.
However if I replace '111' with '112' in WHERE cluase, I get the following error:
ORA-01722: invalid number
01722. 00000 - "invalid number"
*Cause: The specified number was invalid.
*Action: Specify a valid number.
This error is quite strange to me, and that's why tough to fix.
The error is most likely from the data that is being returned from your new sample_id. There is a string being converted to a number that is failing. Check your data for invalid numerical data in varchar columns. Note that it could be an implicit conversion, not necessarily one where you are doing a to_number() call.

Trying to Multiply a Case Statement to a Count

DECLARE #StartDate datetimeoffset,
#EndDate datetimeoffset
SET #StartDate = '2022-03-01 00:00:00.000 +07:00'
SET #EndDate = '2022-03-06 23:59:59.000 +07:00'
SELECT
Records.RecordID,
CONVERT(VARCHAR(10),Records.RecDate AT TIME ZONE 'SE Asia Standard Time',104) AS RecTime,
LocationStr, LocationName,
CONCAT(FirstName,' ',LastName) AS Username ,ProductCodeName,
CASE
WHEN AssetTypeName LIKE '%LTR'
THEN LEFT(AssetTypeName, LEN(AssetTypeName) - 3)
ELSE LEFT(AssetTypeName, LEN(AssetTypeName) - 2)
END * COUNT (ProductCodeName) AS 'SumProduct'
FROM
opendata.records
INNER JOIN
opendata.RecAssets ON Records.RecordId = RecAssets.RecordId
WHERE
(Records.ActionName = 'Fill')
AND (IsDeleted = '0')
AND (Records.RecDate BETWEEN #StartDate and #EndDate)
AND (LocationStr = '3031')
GROUP BY
Records.RecordId, Records.RecDate, LocationStr, LocationName,
CONCAT(FirstName,' ', LastName), ProductCodeName, AssetTypeName
ORDER BY
LocationStr ASC, RecTime ASC, ProductCodeName ASC
Tried to multiply the last to column on my Select statement but failed to do so. I get an error
Conversion failed when converting the ****** value '******' to data type ******.
Furthermore, I tried to convert the case statement to an int but also failed. How can I directly multiply it?
I'm guessing that you're using sql server seeing as it's not oracle and len() is not supported in mySQL or Postgres. You're code calls for an implicit conversion from a numerical value in a char type to a number, for example '123' to 123.
In the following example this doesn't present a problem the first time, but the second time there is a letter in the char value which cannot be converted and throws an error.
I am therefore thinking that you have values of AssetTypeName where there are letters other than in the last 2 characters for non-LTR values of elsewhere in the string for those ending in LTR.
create table test(
AssetTypeName varchar(10),
ProductCodeName int);
insert into test values
('123LTR',1),
('123LTR',1),
('123AB',1);
GO
3 rows affected
select
AssetTypeName,
CASE
WHEN AssetTypeName LIKE '%LTR'
THEN LEFT(AssetTypeName, LEN(AssetTypeName) - 3)
ELSE LEFT(AssetTypeName, LEN(AssetTypeName) - 2)
END * COUNT (ProductCodeName) AS 'SumProduct'
from test
group by AssetTypeName;
GO
AssetTypeName | SumProduct
:------------ | ---------:
123AB | 123
123LTR | 246
insert into test values ('123ABC',1);
GO
1 rows affected
select
AssetTypeName,
CASE
WHEN AssetTypeName LIKE '%LTR'
THEN LEFT(AssetTypeName, LEN(AssetTypeName) - 3)
ELSE LEFT(AssetTypeName, LEN(AssetTypeName) - 2)
END * COUNT (ProductCodeName) AS 'SumProduct'
from test
group by AssetTypeName;
GO
Msg 245 Level 16 State 1 Line 1
Conversion failed when converting the varchar value '123A' to data type int.
db<>fiddle here

SpringJPA - inconsistent datatypes: expected NUMBER got BINARY

Im using SPRING JPA in my application and trying to run a native query as follows:
#Query (value="select max(ts) from abc.test s \n" +
"where abc.getTest(s.user_id) = :#{#userId} \n" +
"and upper(app_name) = 'TAX' and INSTR(s.user_id, '.') > 0 \n" +
"group by user_id, app_name", nativeQuery=true)
Timestamp getLastLogin(BigDecimal userId);
I am getting exception as follows:
Caused by: Error : 932, Position : 110, Sql = select max(ts) from abc.test s
where ac.getTest(s.user_id) = :1
and upper(app_name) = 'TAX' and INSTR(s.user_id, '.') > 0
group by user_id, app_name, OriginalSql = select max(ts) from abc.test s
where abc.getTest(s.user_id) = ?
and upper(app_name) = 'TAX' and INSTR(s.user_id, '.') > 0
group by user_id, app_name, Error Msg = ORA-00932: inconsistent datatypes: expected NUMBER got BINARY
at oracle.jdbc.driver.T4CTTIoer11.processError(T4CTTIoer11.java:514)
... 109 more
<org.hibernate.engine.jdbc.spi.SqlExceptionHelper> <SqlExceptionHelper> <logExceptions> <SQL Error: 932, SQLState: 42000>
<org.hibernate.engine.jdbc.spi.SqlExceptionHelper> <SqlExceptionHelper> <logExceptions> <ORA-00932: inconsistent datatypes: expected NUMBER got BINARY
>
I tried to convert the max(ts) to string using to_char and changed the coresponding getter/setter to String still getting the same issue.
Update:
I fixed it with this small change
String getLastLogin(#Param("userId") BigDecimal userId);
Didnt add #Param for the arguments.
That query return null value thats why that null values can not assign to number. We can not assign null to int(primitive) in java.

ORA-22992 / ORA-06502+ORA-06512 errors

I'm using this part of code in large one :
SELECT DISTINCT
P.SKU, SUBSTR(X.ATTRIBUTENAME, 14, 3) ATTRIBUTECODE, X.ATTRIBUTEVALUE
FROM
PRODUCT#ISPSTAG2 P,
XMLTABLE('/attrs/attr'
PASSING XMLTYPE(REGEXP_REPLACE(P.ATTRIBUTES_DE_AT, '<attr name="longDescription">.*?<\/attr>'))
COLUMNS ATTRIBUTENAME VARCHAR2(50) PATH '#name',
ATTRIBUTEVALUE VARCHAR2(4000) PATH '/string'
) X
WHERE X.ATTRIBUTENAME LIKE 'Z_CA%'
AND DN(DOMAINID) = 'AT'
AND SKU NOT LIKE 'OFF_%' AND SKU NOT LIKE 'PDT%'
AND ATTRIBUTES_DE_AT IS NOT NULL;
And it throws an ORA-22992 error.
I've made some research and a tip can to use the dual
SELECT DISTINCT P.SKU, SUBSTR(X.ATTRIBUTENAME, 14, 3) ATTRIBUTECODE, X.ATTRIBUTEVALUE
FROM PRODUCT#ISPSTAG2 P,
XMLTABLE('/attrs/attr'
PASSING XMLTYPE(REGEXP_REPLACE(P.ATTRIBUTES_DE_AT, '<attr name="longDescription">.*?<\/attr>'))
COLUMNS ATTRIBUTENAME VARCHAR2(50) PATH '#name',
ATTRIBUTEVALUE VARCHAR2(4000) PATH '/string'
) X
WHERE X.ATTRIBUTENAME LIKE 'Z_CA%'
AND DN(DOMAINID) = 'AT'
AND SKU NOT LIKE 'OFF_%' AND SKU NOT LIKE 'PDT%'
AND (SELECT ATTRIBUTES_DE_AT FROM DUAL) IS NOT NULL;
But now I get ORA-06502/ORA-06512 errors :
ORA-06502: PL/SQL : erreur numérique ou erreur sur une valeur
ORA-06512: à "SYS.XMLTYPE", ligne 272
ORA-06512: à ligne 1
06502. 00000 - "PL/SQL: numeric or value error%s"
*Cause: An arithmetic, numeric, string, conversion, or constraint error occurred. For example, this error occurs if an attempt is made to assign the value NULL to a variable declared NOT NULL, or if an attempt is made to assign an integer larger than 99 to a variable declared NUMBER(2).
*Action: Change the data, how it is manipulated, or how it is declared so that values do not violate constraints.
But, I executed the first one on ISPSTAG2 and it works, but the second one on ISPSTAG2 returns me the same ORA-06502/ORA-06512 errors so the issue is with the dual subquery.
I also tried to create a view on ISPSTAG2 using DBMS_LOB.SUBSTR with 4000 characters but same error.
Any ideas ? Thank you.
If forgot to use the (SELECT ATTRIBUTES_DE_AT FROM DUAL) subquery inside the XMLTYPE...
SELECT DISTINCT P.SKU, SUBSTR(X.ATTRIBUTENAME, 14, 3) ATTRIBUTECODE, X.ATTRIBUTEVALUE
FROM PRODUCT#ISPSTAG2 P,
XMLTABLE('/attrs/attr'
PASSING XMLTYPE(REGEXP_REPLACE(**(SELECT ATTRIBUTES_DE_AT FROM DUAL)**, '<attr name="longDescription">.*?<\/attr>'))
COLUMNS ATTRIBUTENAME VARCHAR2(50) PATH '#name',
ATTRIBUTEVALUE VARCHAR2(4000) PATH '/string'
) X
WHERE X.ATTRIBUTENAME LIKE 'Z_CA%'
AND DN(DOMAINID) = 'AT'
AND SKU NOT LIKE 'OFF_%' AND SKU NOT LIKE 'PDT%'
AND (SELECT ATTRIBUTES_DE_AT FROM DUAL) IS NOT NULL;
The thing I don't understand is that when don't use the subquery in the IS NOT NULL filter I have the the ORA-22992 error (using distant LOB), so why I have a different error not using the dual subquery, which is the same distant LOB ?
Anyway for you for your time/help :)

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