Oracle SQL Error occurred in XML processing for a query - oracle

Hi I am trying to run this query but getting this error
Query 1
select OWNER,table_name,
to_number(extractvalue(xmltype(dbms_xmlgen.getxml('select count(*) c from '||owner||'.'||table_name)),'/ROWSET/ROW/C')) as count
from all_tables
Runs fine
Query 2 - Included additional columns (sample_size, last_analyzed)
select OWNER,table_name,
to_number(extractvalue(xmltype(dbms_xmlgen.getxml('select count(*) c from '||owner||'.'||table_name)),'/ROWSET/ROW/C')) as count,
sample_size, last_analyzed
from all_tables
Error - ?
ORA-19202: Error occurred in XML processing
ORA-00933: SQL command not properly ended
ORA-06512: at "SYS.DBMS_XMLGEN", line 176
ORA-06512: at line 1
19202. 00000 - "Error occurred in XML processing%s"
*Cause: An error occurred when processing the XML function
*Action: Check the given error message and fix the appropriate problem
Query 2 - Issue what could be the issue ? - Explanation and resolution

Related

cx_Oracle queries: ORA-00933: SQL command not properly ended

cur.execute("""
SELECT location, AVG(temp) as avg_temp
FROM (SELECT location,temp, ROWNUM rnum
FROM time_series_location_temp
ORDER BY avg_temp ASC)
WHERE rnum <= 6;
""")
I'm trying to execute this code but keep running into this error DatabaseError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_17344/3055250712.py in
----> 1 cur.execute("""
2 SELECT LOCATION_ID, AVG(temp) as avg_temp
3 FROM (SELECT LOCATION_ID,temp
4 FROM time_series_location_temp
5 ORDER BY temp ASC)
DatabaseError: ORA-00933: SQL command not properly ended
What's wrong and how should I re-write it?
I've tries to rewrite it and still the error comes up. I was expecting that the code would run and execute my query correctly
That error almost invariably means that you have left the semicolon on the end of the statement. This is needed in SQL*Plus but needs to be removed when using cx_Oracle (or the new python-oracledb).

Facing a issue while using the MERGE STATEMENT by using WEHN NOT MATCHED BY TARGET clause

By using HR schema, i have created backup table (EMPLOYEES_BKP) using EMPLOYEES table. when i am using MERGE statement, i am getting the below error..
MERGE INTO EMPLOYEES_BKP BKP
USING EMPLOYEES EMP
ON (BKP.EMPLOYEE_ID=EMP.EMPLOYEE_ID)
WHEN MATCHED THEN
UPDATE SET BKP.SALARY=EMP.SALARY
WHEN NOT MATCHED BY TARGET THEN
INSERT (BKP.EMPLOYEE_ID, BKP.FIRST_NAME,BKP.LAST_NAME, BKP.EMAIL, BKP.PHONE_NUMBER, BKP.HIRE_DATE, BKP.JOB_ID, BKP.SALARY, BKP.COMMISSION_PCT, BKP.MANAGER_ID, BKP.DEPARTMENT_ID)
VALUES (EMP.EMPLOYEE_ID, EMP.FIRST_NAME,EMP.LAST_NAME, EMP.EMAIL, EMP.PHONE_NUMBER, EMP.HIRE_DATE, EMP.JOB_ID, EMP.SALARY, EMP.COMMISSION_PCT, EMP.MANAGER_ID, EMP.DEPARTMENT_ID)
WHEN NOT MATCHED BY SOURCE
DELETE;
Error at Command Line : 15 Column : 18
Error report -
SQL Error: ORA-00905: missing keyword
00905. 00000 - "missing keyword"

ora-22060 argument is an invalid or uninitialized number

I'm trying to create MView in orcale bat it raise error. I don't know why or how to fix this.
it is my code
CREATE MATERIALIZED VIEW MAKT REFRESH FAST ON DEMAND
WITH ROWID
START WITH TO_DATE('03-11-2018 01:00:00', 'DD-MM-YYYY HH24:MI:SS') NEXT TRUNC(SYSDATE+12/24,'HH')
AS
SELECT "MAKT"."MANDT" "MANDT",
"MAKT"."MATNR" "MATNR",
"MAKT"."SPRAS" "SPRAS",
"MAKT"."MAKTX" "MAKTX"
FROM "MAKT"#"PE2.ABC.COM.VN" "MAKT"
WHERE "MAKT"."MANDT" = '300';
It gives error
ora-22060 :argument is an invalid or uninitialized number ora-06512
:ora-06512 at sys.dbms_snapshot line 1613 ora-06512 : at line 1
please help me.

Issue with WHILE loop in PSQL shell

I'm trying to use a WHILE LOOP to insert columns from a collection of tables in PSQL shell. Code is as follows:
\set start_id 909
\set end_iter 912
-- Create base table to be later inserted
DROP TABLE IF EXISTS t_base_table;
CREATE TEMP TABLE t_base_table (
...
)
DISTRIBUTED RANDOMLY;
SELECT :start_id AS iter \gset
BEGIN
WHILE :iter <= :end_iter LOOP
\set weekly 'table_i_want_col_from_':iter
INSERT INTO t_base_table
SELECT ... --same columns as in the base table
FROM :weekly a
GROUP BY 1,2,3,4,5,6
SELECT :iter+1 AS iter \gset
END LOOP;
END;
I got several error messages:
ERROR: syntax error at or near "WHILE" LINE 2: WHILE 909 <= 912 LOOP
ERROR: syntax error at or near "SELECT" LINE 13: SELECT 909+1 AS week_id
ERROR: syntax error at or near "LOOP" LINE 1: END LOOP;
Looks like when I ran the script, it got split up in the psql shell (thus the 'LINE 1' in the item 3 above). I'm wondering is it because this syntax is not valid for psql shell? Or am I using the \set or \gset in a wrong way.
Thanks in advance for any help you may provide!!

Oracle java exception when trying to use NVL()

I have the following SQL statement in Oracle that is giving me some headache. I am trying to return an empty geometry if the value held in the Oracle table is null however it simply fails with the following error:
The Error
*
ORA-29532: Java call terminated by uncaught Java exception:
java.lang.NullPointerException ORA-06512: at "MDSYS.SDO_UTIL", line
2421 ORA-06512: at "MDSYS.SDO_UTIL", line 2443 ORA-06512: at
"MDSYS.SDO_GEOMETRY", line 36
*
The Code
select CLUSTER_ID,
NUM_POINTS,
FEATURE_PK,
A.CELL_CENTROID.SDO_POINT.X,
A.CELL_CENTROID.SDO_POINT.Y,
A.CLUSTER_CENTROID.SDO_POINT.X,
A.CLUSTER_CENTROID.SDO_POINT.Y,
TO_CHAR (A.CLUSTER_EXTENT.GET_WKT ()),
TO_CHAR (A.CELL_GEOM.GET_WKT ()),
A.CLUSTER_EXTENT.SDO_SRID,
TPHS_PHASE_ID
from (SELECT CLUSTER_ID,
NUM_POINTS,
FEATURE_PK,
SDO_CS.transform (CLUSTER_CENTROID, 4326) cluster_centroid,
SDO_CS.TRANSFORM(NVL(CLUSTER_EXTENT, MDSYS.SDO_GEOMETRY(2001,4326 ,MDSYS.SDO_POINT_TYPE(NULL,NULL,NULL),NULL,NULL)),4326) CLUSTER_EXTENT ,
SDO_CS.transform (CELL_CENTROID, 4326) cell_centroid, CELL_GEOM FROM
V_CLUSTER_1000M) a
LEFT JOIN RWOL_TMA_ROADWORKS
ON a.FEATURE_PK = RWOL_TMA_ROADWORKS.TPHS_PHASE_ID
where sdo_filter( A.CELL_GEOM, SDO_CS.transform(mdsys.sdo_geometry(2003,4326, NULL, mdsys.sdo_elem_info_array(1,1003,3),mdsys.sdo_ordinate_array(-25.43623984375,44.257784519021, 21.62918984375, 60.752403080295)),81989)) = 'TRUE'
Anybody got any idea what is going wrong here? I am no Oracle dev so any help is appreciated as well as an explanation.
The problem here was caused by the line
TO_CHAR (A.CLUSTER_EXTENT.GET_WKT ()),
This line is attempting to get a well known text item from the returned column and because we do not supply a valid one it is failing. Strange error really.

Resources