Oracle java exception when trying to use NVL() - oracle

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.

Related

ORA-00936: missing expression Solution- Convert function

when doing this query in oracle I get the error
ORA-00936: missing expression
00936. 00000 - "missing expression"
If I run the query to the from of it gives me results, then I deduce that the problem comes from where, however, I cannot identify what it is
SELECT FECHADOC, FECHACONT, CLASEDOC, SOCIEDAD, MONEDA, TIPOCAMBIO, PERIODO,
REFERENCIA, TEXTOCAB, ID_REGISTRO
FROM ESQUEMA.TABLE
WHERE CONVERT(CHAR(8),20211231,112) <= CONVERT(CHAR(8),DATEADD(DAY,-90,GETDATE()),112)
I already used:
WHERE CONVERT( TO_CHAR(8),20201231,112) <=
(CONVERT(TO_CHAR(8),DATEADD(DAY,-90,GETDATE()),112) )
and it keeps giving me an error
If this really is Oracle, then dateadd and getdate aren't Oracle functions. Look like MS SQL Server ones. Also, table is reserved word for tables, you can't name a table (or any other object) table.
Anyway: looks like this is what you might be looking for:
SELECT FECHADOC, FECHACONT, CLASEDOC, SOCIEDAD, MONEDA,
TIPOCAMBIO, PERIODO, REFERENCIA,
TEXTOCAB, ID_REGISTRO
FROM ESQUEMA.TABLE
where to_date('20211231', 'yyyymmdd') <= trunc(sysdate) - 90;

Oracle SQL Error occurred in XML processing for a query

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

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.

Getting Unknown Command error on IF-THEN-ELSE

I have the following query that I am using in Oracle 11g
IF EXISTS (SELECT * FROM EMPLOYEE_MASTER WHERE EMPID='ABCD32643')
THEN
update EMPLOYEE_MASTER set EMPID='A62352',EMPNAME='JOHN DOE',EMPTYPE='1' where EMPID='ABCD32643' ;
ELSE
insert into EMPLOYEE_MASTER(EMPID,EMPNAME,EMPTYPE) values('A62352','JOHN DOE','1') ;
END IF;
On running the statement I get the following output:
Error starting at line : 4 in command -
ELSE
Error report -
Unknown Command
1 row inserted.
Error starting at line : 6 in command -
END IF
Error report -
Unknown Command
The values get inserted with error when I run it directly. But when I try to execute this query through my application I get an oracle exception because of the error generated :
ORA-00900: invalid SQL statement
And hence the values are not inserted.
I am relatively new to Oracle. Please advise on what's wrong with the above query so that I could run this query error free.
If MERGE doesn't work for you, try the following:
begin
update EMPLOYEE_MASTER set EMPID='A62352',EMPNAME='JOHN DOE',EMPTYPE='1'
where EMPID='ABCD32643' ;
if SQL%ROWCOUNT=0 then
insert into EMPLOYEE_MASTER(EMPID,EMPNAME,EMPTYPE)
values('A62352','JOHN DOE','1') ;
end if;
end;
Here you you the update on spec, then check whether or not you found a matching row, and insert in case you didn't.
"what's wrong with the above query "
What's wrong with the query is that it is not a query (SQL). It should be a program snippet (PL/SQL) but it isn't written as PL/SQL block, framed by BEGIN and END; keywords.
But turning it into an anonymous PL/SQL block won't help. Oracle PL/SQL does not support IF EXISTS (select ... syntax.
Fortunately Oracle SQL does support MERGE statement which does the same thing as your code, with less typing.
merge into EMPLOYEE_MASTER em
using ( select 'A62352' as empid,
'JOHN DOE' as empname,
'1' as emptype
from dual ) q
on (q.empid = em.empid)
when not matched then
insert (EMPID,EMPNAME,EMPTYPE)
values (q.empid, q.empname, q.emptype)
when matched then
update
set em.empname = q.empname, em.emptype = q.emptype
/
Except that you're trying to update empid as well. That's not supported in MERGE. Why would you want to change the primary key?
"Does this query need me to add values to all columns in the table? "
The INSERT can have all the columns in the table. The UPDATE cannot change the columns used in the ON clause (usually the primary key) because that's a limitation of the way MERGE works. I think it's the same key preservation mechanism we see when updating views. Find out more.

ORA-29902: error in executing ODCIIndexStart() routine ORA-20000: Oracle Text error: DRG-50901: text query parser syntax error on line 1, column 19

SELECT person_no sub_sys_individual_id,
nm_e,
nm_a,
nvl(sex, -1) sex,
nvl(prs_nat, -999) prs_nat,
person_no,
'NA' prog_where_not_allowed,
'NA' udb_no,
person_tp,
pass_no
FROM ban_inq_tab
WHERE contains (nm_e ,'xxstart JUHETI BT MEMED ASMANI%') >0
AND (trans_flag IS NULL OR trans_flag = 'C');
please help me in this issue and getting parser syntax error
You must escape the BT special word (but you can just escape the entire string).
SELECT person_no sub_sys_individual_id,
nm_e,
nm_a,
nvl(sex, -1) sex,
nvl(prs_nat, -999) prs_nat,
person_no,
'NA' prog_where_not_allowed,
'NA' udb_no,
person_tp,
pass_no
FROM ban_inq_tab
WHERE contains (nm_e ,'{xxstart JUHETI BT MEMED ASMANI}%') >0
AND (trans_flag IS NULL OR trans_flag = 'C');
FYI, you'll also get this error (i'm on Oracle 12.2) if you have the input parameter to a stored proc that will be the query in a contains predicate as an NVARCHAR2.
So if you have input params to a stored proc as NVARCHAR2 and that parameter is destined for the query in the contains predicate, then change it to VARCHAR (or maybe CLOB) and it will no longer throw this error.
The error is causing the BT, which is a reserved word. The solution is described in the Oracle Community forum.

Resources