ora-22060 argument is an invalid or uninitialized number - oracle

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.

Related

Creating trigger with 'instead of delete'

I want to treat a delete statement as an update but it throws this error, and I don't know what it means.
create or replace trigger Miembros_V_IOD
instead of delete on Miembros_V
for each row
Begin
update Miembros set (end_date = sysdate)
where Miembros.nick = :old.nick
and Miembros.club = :old.club;
end;
LINE/COL ERROR
-------- ----------------------------------------------------------
2/4 PL/SQL: SQL Statement ignored
2/34 PL/SQL: ORA-00907: missing right parenthesis
The error is pointing to the = sign. You're getting a PL/SQL error - albeit one caused by the inner SQL - and for a trigger the line numbers in PL/SQL errors start from the DECLARE (if you have one) or BEGIN, not from the start of the overall CREATE statement. So the 2/34 refers to character 34 of the second line of the PL/SQL part, which is:
update Miembros set (end_date = sysdate)
... which is the =.
You shouldn't have the parenthesis around (end_date = sysdate):
create or replace trigger Miembros_V_IOD
instead of delete on Miembros_V
for each row
begin
update Miembros set end_date = sysdate
where Miembros.nick = :old.nick
and Miembros.club = :old.club;
end;
/
View MIEMBROS_V created.
db<>fiddle
The syntax diagram in the documentation shows that parentheses can go around a list of columns on the left-had side of the equals sign, or around a subquery on the right; but not around the whole set clause. Because you have set (end_date it's expecting that to either have a comma or closing parenthesis next, i.e. set (end_date) = ... - hence the ORA-00907 being thrown when it didn't see that.

Updating more than 1 row - Oracle SQL Procedure

I was wondering if it was possible to update more than 1 row with a procedure, im not sure why this one isnt working. Its working only if theres only 1 row in my table. But if there's more than 1 row i get the usual error message :
ORA-01422: exact fetch returns more than requested number of rows
I'm honestly not sure why this isnt working. Is it possible a procedure cannot update more than 1 row at once ?
create or replace procedure TP3_SP_ARCHIVER_ENCAN
is
V_CURRENT_DATE date;
V_DATE_ENCAN date;
begin
select sysdate, DATE_FIN_ENC into V_CURRENT_DATE, V_DATE_ENCAN
from
TP2_ENCAN;
update TP2_ENCAN
set EST_ARCHIVEE_ENC = 1,
STATUT_ENC = 'Archivé'
where V_CURRENT_DATE - V_DATE_ENCAN > 60;
end TP3_SP_ARCHIVER_ENCAN;
/
I'm excepting to archive every ENCAN that has been closed for a duration of 60+ days. everytime i run this procedure i just want to update those.
Full error message :
Error report -
ORA-01422: exact fetch returns more than requested number of rows
ORA-06512: at "C##JALAC144.TP3_SP_ARCHIVER_ENCAN", line 8
ORA-06512: at line 1
01422. 00000 - "exact fetch returns more than requested number of rows"
*Cause: The number specified in exact fetch is less than the rows returned.
*Action: Rewrite the query or change number of rows requested
This line is your problem:
select sysdate, DATE_FIN_ENC into V_CURRENT_DATE, V_DATE_ENCAN from TP2_ENCAN;
You are selecting DATE_FIN_ENC into a scalar variable that can hold exactly one value. You can select "1" into "x". You can't select "1" and "2" into "x" at the same time. So you get the error you're getting.
If I understand your problem correctly, you probably want this, with no initial select:
update TP2_ENCAN
set EST_ARCHIVEE_ENC = 1,
STATUT_ENC = 'Archivé'
where SYSDATE - DATE_FIN_ENC > 60;
Via your code you just want to update record base on current date. Therefore, you do not need to use parameter. Using the update script is enough.
Create or replace procedure TP3_SP_ARCHIVER_ENCAN is:
begin
update TP2_ENCAN
set EST_ARCHIVEE_ENC = 1,
STATUT_ENC = 'Archivé'
where sysdate - DATE_FIN_ENC > 60;
end
TP3_SP_ARCHIVER_ENCAN;

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.

Getting Error with Date Format in To_Char

I am getting error in the second script. Please explain why i am getting error in the second script.
select count(*) from LCL_SHR_IncidentIntegrationInt where
externalsystem = 'IPSOFT'
and (to_char(sysdate,'YYYYMMDDHH24MISS')-to_char(fn_adjusted_date(CREATE_DATE),'YYYYMMDDHH24MISS')) > 180;
O/P : 122797
select count(*) from LCL_SHR_IncidentIntegrationInt where
externalsystem = 'IPSOFT'
and (to_char(sysdate,'DD-MM-YYYY HH24:MI:SS')-to_char(fn_adjusted_date(CREATE_DATE),'DD-MM-YYYY HH24:MI:SS')) > 180;
O/P : ORA-01722: invalid number
01722. 00000 - "invalid number"
*Cause: The specified number was invalid.
*Action: Specify a valid number.
The first query works because Oracle is able to implicitly cast the characters as number and compare with 180. The other one doesn't because the : and - cannot be implicitly cast to number.
You should use date and time functions for such cases like timestampdiff or datediff. More functions here - https://docs.oracle.com/cd/E17952_01/refman-5.1-en/date-and-time-functions.html

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