weird query behavior oracle sql - convert text to number - sql

oracle query This works
select *
from (
select to_number(substr(app_cluster,6,2), '99') as b
from xtern_app_info
WHERE app_cluster IS NOT NULL
AND APP_CLUSTER <> 'CLUSTER'
);
but when adding 'where b > 2' makes an error, why?
select *
from (
select to_number(substr(app_cluster,6,2), '99') as b
from xtern_app_info
WHERE app_cluster IS NOT NULL
AND APP_CLUSTER <> 'CLUSTER'
) where b > 2;
ORA-29913: error in executing ODCIEXTTABLEFETCH callout
ORA-01722: invalid number
29913. 00000 - "error in executing %s callout"
*Cause: The execution of the specified callout caused an error.
*Action: Examine the error messages take appropriate action.

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.

Oracle error while executing query : ORA-00905: Missing keyword

While executing the below code:
select distinct tam.sol_id||'|'||(select sol.sol_desc from sol where sol.sol_id=tam.sol_id)||'|'||count(*)||'|'||sum(org_tran_amt)
||'|'||count(case when ott.tran_date between '01-02-2021' and '24-02-2021' as 1 else 0 end) a
from ott,tam
where tam.acid=ott.acid
and tam.gl_sub_head_code in ('85300','85320','85330','85340','85350','85360','85365','85370','85380','85390','85395')
and tran_date <= '24-02-2021'
and tam.sol_id in (select sst.sol_id from sst where sst.set_id='ROFPZ')
and not exists (select * from tct where tct.tran_date=ott.tran_date and trim(tct.tran_id)=trim(ott.tran_id)
and nvl(ott.org_tran_amt-tct.AMT_OFFSET,0)='0' and tct.entity_cre_flg='Y' and tct.del_flg='N');
received below error message as output:
from ott,tam
*
ERROR at line 3:
ORA-00905: missing keyword
Try to modify the case part of the statement:
case when ott.tran_date between '01-02-2021' and '24-02-2021' then 1 else 0 end
You must write "then" instead of "as".

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

Oracle , when merge, show " invalid identifier"

MERGE INTO EP_PR
using(
select
SYSDATE AS CREATION_TIME_1,
1 AS STATUS_1,
0 AS DELETED_1,
SYSDATE AS LAST_MOD_TIME_1,
0 AS EP_STATUS_1,
SYSDATE AS EP_ISSUE_DATE_1,
CASE WHEN LENGTH(EKORG)<2 THEN 'UMC1' ELSE EKORG END AS EP_PURORG_1,
EKGRP AS EP_PURGRP_1
from ZEPT02
Where proc_flag='N'
) TABLE1
ON
(
TABLE1.EP_PR_NO_1=EP_PR.EP_PR_NO
)
WHEN MATCHED
THEN UPDATE SET
EP_PR.CREATION_TIME=TABLE1.CREATION_TIME_1,
EP_PR.STATUS=TABLE1.STATUS_1,
EP_PR.DELETED=TABLE1.DELETED_1,
EP_PR.LAST_MOD_TIME=TABLE1.LAST_MOD_TIME_1,
EP_PR.EP_STATUS=TABLE1.EP_STATUS_1,
EP_PR.EP_ISSUE_DATE=TABLE1.EP_ISSUE_DATE_1,
EP_PR.EP_PURORG=TABLE1.EP_PURORG_1,
EP_PR.EP_PURGRP=TABLE1.EP_PURGRP_1;
It shows errors that
SQL error: ORA-00904: "TABLE1"."EP_PR_NO_1": invalid identifier
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action:
I'm trying to google it,
but my on clause "TABLE1"."EP_PR_NO_1" didn't appear at the merge column,
where did it wrong?
Thanks!
You haven't defined TABLE1.EP_PER_NO_1 anywhere, which is exactly what the Oracle error is telling you.

getting error while executing case statement

I am trying to execute case statement but i am getting an error. Here is my query
select LOSA_APP.app_ref_no AS "App.Ref.No.", CODE_BRANCH.branch_name AS "BRANCH"
from losa_app LOSA_APP
INNER JOIN
losa_app_z LOSA_APP_Z
ON
losa_app.app_ref_no = losa_app_z.app_ref_no
INNER JOIN
code_branch CODE_BRANCH
ON
LOSA_APP.attend_branch = CODE_BRANCH.branch_id
where
LOSA_APP.app_status='A' -- Application Status in {‘accepted’}
and
trunc(sysdate) between (nvl(LOSA_APP_Z.li_dt, LOSA_APP_Z.li_collect_dt)) AND ((trunc(sysdate))) -- falling under the reporting period
and
(trunc(sysdate) - nvl(losa_app_z.li_dt,losa_app_z.li_collect_dt)) > 90 -- select application cases at any step after entering Documentation flows.
and
losa_app.product_type = 'MG' -- Select records based on input parameter value passed in.
and
case :input1
when 'ABB' Then code_branch.branch_code1 like '%0232%'
when 'AiBB' Then code_branch.branch_code1 like '%0347%'
end
While executing it asks me for input. After that it gives me error that
ORA-00905: missing keyword
00905. 00000 - "missing keyword"
*Cause:
*Action:
Error at Line: 22 Column: 50
Line 22 is when 'ABB' Then code_branch.branch_code1 like '%0232%'
What keyword i am missing?
Thanks
Don't try to return a logical boolean from the CASE statement.
Instead, make the CASE statement part of the logical test. Such as...
code_branch.branch_code1
like
case :input1 when 'ABB' Then '%0232%'
when 'AiBB' Then '%0347%' end
try this one
SELECT ....
FROM...
WHERE ....
AND
(
((:input1 = 'ABB') AND code_branch.branch_code1 like '%0232%') OR
((:input1 = 'AiBB') AND code_branch.branch_code1 like '%0347%')
)