I am trying to delete few rows from the table -cost_mdl_ver_equip but I am getting the following error:
delete from tbcam.cost_mdl_ver_equip where mdl_ver_id = 303165
Error:
Error starting at line : 10 in command -
delete from tbcam.cost_mdl_ver_equip where mdl_ver_id = 303165
Error report -
ORA-01407: cannot update ("TBCAM"."COST_MDL_VER_EQUIP"."MDL_VER_ID") to NULL
Here is the constraints for the table:
what fix do I need to do?
Related
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
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"
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;
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.
I used a query to delete duplicate rows in sybase.
It worked; However when I used similar query for practice on oracle and it did not work;
Please advise
Sybase query that worked:
--delete all the duplicate rdb_id where row_id is greater than the min row_id
delete ratings_xref..xref_ratg_obj_id
from ratings_xref..xref_ratg_obj_id a, ratings_xref..xref_ratg_obj_id b
where a.rdb_id = b.rdb_id
and a.row_id > b.row_id
go
However, the below code did not work in oracle :
delete dup6
from dup6 d6,dup6 d61
where d6.rowid>d61.rowid
and d6.i=d6i.i;
Same with update :
Below sybase code works :
update ratings_xref..xref_ratg_obj_id
set a.last_chg_usr=suser_name(),
a.last_chg_dt=getdate()
from ratings_xref..xref_ratg_obj_id a, ratings_xref..xref_ratg_obj_id b
where a.rdb_id = b.rdb_id
and a.row_id > b.row_id
Whereas the oracle code does not work
update dupli
set bb.chg_dt=sysdate-360
from dupli bb,dupli b
where bb.i=b.i
and bb.rowid>b.rowid;
The error received while deleting using the oracle query was :
Error report -
SQL Error: ORA-00933: SQL command not properly ended
00933. 00000 - "SQL command not properly ended"