I am trying to string concatenate xml using below oracle sql query. its throwing error when there are invalid characters in the data. Kindly suggest if any improvement can be done.
SELECT
'Outstanding Conditions:' || outstanding_conditions "OUTSTANDING_CONDITIONS"
FROM
(
SELECT
rtrim(
XMLAGG(xmlelement(
e,
chr(13)
|| rownum
|| '. '
|| replace(
replace(
condition_desc,
'PBK''S',
'PBK'
),
'PBK',
'PBK'
)
).extract('//text()')
ORDER BY
application_id
).getclobval()
) "OUTSTANDING_CONDITIONS"
FROM
tbl_assessment_cond
WHERE
condition_status = 'U'
AND application_id = 'Z01234567'
AND instr(
'~S~', '~'
|| is_acceptance
|| '~'
) > 0
)
WHERE
outstanding_conditions IS NOT NULL;
Error:
ORA-31011: XML parsing failed
ORA-19202: Error occurred in XML processing
LPX-00216: invalid character 160 (0xA0)
Error at line 2
31011. 00000 - "XML parsing failed"
*Cause: XML parser returned an error while trying to parse the document.
*Action: Check if the document to be parsed is valid.
Related
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 ')'.
I have a table in which there is a column name associated_ids with datatype as varchar2(4000). It contains a value and i need to append the new value with existing value. Using below update query:
update ncl_getafix.service_graph
set Associated_ids = Associated_ids + ',' + '95d4980b-d12c-4854-97c6-bd9854f8f003'
where SERVICE_ID='075d7a58-7fad-4e1d-9822-83a2fa1a0d05';
I am getting below error:
Error starting at line : 5 in command - update
ncl_getafix.service_graph set
Associated_ids=Associated_ids+','+'95d4980b-d12c-4854-97c6-bd9854f8f003'
where SERVICE_ID='075d7a58-7fad-4e1d-9822-83a2fa1a0d05'
Error report - ORA-01722: invalid number.
Can anyone help to debug this.
You need to use concat operator || not + as follows:
update ncl_getafix.service_graph
set Associated_ids = Associated_ids || ',' || '95d4980b-d12c-4854-97c6-bd9854f8f003'
where SERVICE_ID='075d7a58-7fad-4e1d-9822-83a2fa1a0d05';
i found the answer.
Use || symbol instead of + in query
I have the below select statement in hive .It executes perfectely fine.
In Hive
select
COALESCE(product_name,CONCAT(CONCAT(CONCAT(TRIM(product_id),' -
'),trim(plan_code)),' - UNKNOWN')) as product_name
from table name;
I am trying to use the same select statement in POSTGRESQL and it throw me error saying "
Query execution failed
Reason:
SQL Error [42883]: ERROR: function concat(text, unknown) does not exist
Hint: No function matches the given name and argument types. You might need to add explicit type casts.
In postgresql:
select
COALESCE(product_name,CONCAT(CONCAT(CONCAT(TRIM(product_id),' -
'),trim(plan_code)),' - UNKNOWN')) as product_name
from table name;
Could some one throw some light on this ?
Instead of concat try with ||:
SELECT COALESCE(product_name,
(TRIM(product_id) || ' - ' || TRIM(plan_code) || ' - UNKNOWN')
) AS product_name
FROM tablename;
or simply a single CONCAT as:
SELECT COALESCE(product_name,
CONCAT(TRIM(product_id)::text, ' - ', TRIM(plan_code)::text, ' - UNKNOWN')
) AS product_name
FROM tablename;
You can also consider using format function:
SELECT coalesce(product_name, format('%s - %s - UNKNOWN', trim(product_id), trim(plan_code)))
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.
I am not familiar with Oracle syntax, but I am getting a missing right parenthesis error when I am passing this string to an .Net Oracle Command and then it tries to fill the data adapter.
string cT = "SELECT 'PRODUCT' AS ItemType, 'x' || CAST(LPROD.QUANTITY AS VARCHAR2(50)), " +
"PNAME.NAME || ' (' || CAST((PRODS.\"SIZE\" AS VARCHAR2(50))) || ' ' || PRODS.MEASURE || ')' AS Name, " +
"PRODS.PRODUCT_ID as ProductSizeID, PRODS.UPC_CODE as BarCode FROM ORDERS ORDR, LI_PROD LPROD, PRODUCT_NAME PNAME, " +
"PRODUCT PRODS WHERE ORDR.INV_NUM = :Invoice_Num AND ORDR.ORDER_NUM = LPROD.ORDER_NUM " +
"AND LPROD.PRODUCT_ID = PRODS.PRODUCT_ID AND PRODS.PRODUCT_NAME_ID = PNAME.ID";
Can anyone spot the error that may be causing this? Thanks for your help.
Try:
cast(prods."SIZE" as varchar2(50))
Instead of:
cast((prods."SIZE" as varchar2(50)))
I recently came up with the exact same issue and could not find a solution. What ended up happening was that I had the following code from SQLServer that I was attempting to convert to Oracle.
CAST(col AS NVARCHAR(250)) AS col_name,
I was able to fix it by changing it to
CAST(col AS NVARCHAR2(250)) AS col_name,