Oracle update not working - oracle

Hello everyone i've tried to update a row in my database using sqlplus the query is executed but the values still the same
here is my code:
update pilote set nom= 'yees' where id_pilote= 111;
1 row updated

Use Commit Command after update and again re query table contents

Related

update /insert query i table should have a before/after image statement

I am required to have before/after image statement for every update /insert operation done on a table in DB in order to properly record the before /after image in the spool file of the script.
I am not sure how to do this like example for this query :
update employee set divison = 'IT' where empId = 2223;
Any help would be appreciated.
if I understand Your question correctly, I would use table triggers.
You have option to write code that executes before and after insert/update statament.
Since update command is complex, you have both images, "BEFORE" and "AFTER" (data did exist before update and exists after update). So, I would write trigger that executes BEFORE update, and that collects all the :OLD data (this notation is used for table fields before data is changed using update command) and wrote them to the output (or insert them into some kind of history table for later audit). Also I would write another trigger that is executed AFTER update and do the same thing with :NEW data (wrote to output or something else).
I think that for insert is trivial, you don't have "BEFORE" image, only "AFTER" so You can write AFTER trigger, as for update command.
I hope that You can understand my answer.
To add some code here:
CREATE OR REPLACE TRIGGER BU_EMP
BEFORE UPDATE
ON EMP
REFERENCING NEW AS New OLD AS Old
FOR EACH ROW
BEGIN
DBMS_OUTPUT.PUT_LINE('BEFORE: '||:OLD.EMP_ID||' '||:OLD.EMP_NAME||' '||:OLD.DEPARTMENT);
EXCEPTION
WHEN OTHERS THEN RAISE;
END;
And, similar:
CREATE OR REPLACE TRIGGER AU_EMP
AFTER UPDATE
ON EMP
REFERENCING NEW AS New OLD AS Old
FOR EACH ROW
BEGIN
DBMS_OUTPUT.PUT_LINE('AFTER: '||:NEW.EMP_ID||' '||:NEW.EMP_NAME||' '||:NEW.DEPARTMENT);
EXCEPTION
WHEN OTHERS THEN RAISE;
END;
And now, if You have record with EMP_ID=2233, after update You will have two dbms_output lines, one with data BEFORE, and one with data AFTER update command.
Best regards,
Aleksandar
It sounds like you just want to select from the table before and after the update.
-- Before
SELECT *
FROM employee
WHERE empId = 2223;
--Change
UPDATE employee
SET division = 'IT'
WHERE empId = 2223;
-- After
SELECT *
FROM employee
WHERE empId = 2223;

Does anyone know how to translate this mysql(trigger) syntax to oracle syntax?

CREATE DEFINER=`belito`#`%` TRIGGER `sumupdate` AFTER INSERT ON `stavkaotpremnice` FOR EACH ROW UPDATE otpremnica a
SET a.ukupno =
(SELECT SUM(ukupno)
FROM stavkaotpremnice
WHERE brojotpremnice = a.brojotpremnice)
WHERE a.brojotpremnice = NEW.brojotpremnice
Im struggling doing it, made some searches but didnt go nowhere.
Is this working for you in MySql? If you tried doing this in Oracle using an "AFTER INSERT .... FOR EACH ROW" trigger, you would run into a "Table is mutating error" during the actual insert into stavkaotpremnice. This is because you cannot query the table being inserted into inside of a row-level trigger on that same table. You can do so in a statement-level trigger, but then you lose access to the :new values. A sort of workaround is to use a compound trigger where you can set a variable to the :new value in the "AFTER EACH ROW" section, and then use that variable in your update in the "AFTER STATEMENT" section, but I would highly discourage doing so because that will only work for single row inserts, and you'll get unexpected results if there's ever an insert statement that inserts multiple rows with different values for stavkaotpremnice.brojotpremnice.
I think the best approach here is not to do this in a trigger. Instead, either issue the otpremnica update in your application code and/or via a batch update some time later.

SQL command not properly ended on insert query

I just want to alter my datas in my table this query seems good but oracle says ORA-00933: SQL command not properly ended im new in oracle from mysql.
Here's my code:
INSERT INTO AWACSRECIPEBYWSTYPE(BFGID) VALUES(23) WHERE WSTYPE = 'CLIPBOND';
You can't put a WHERE clause on an INSERT statement in Oracle. And after looking at the MySQL documentation I don't see where you can use a WHERE clause like this in MySQL either.
Did you mean to use an UPDATE statement?
UPDATE AWACSRECIPEBYWSTYPE
SET BFGID = 23
WHERE WSTYPE = 'CLIPBOND'
???

Fire trigger only when rows are updated

I have a command to execute inside oracle triggers after a modification of a table.
I need this command to run once (even if there is 100 rows updated), and only when there is rows updated.
FOR EACH ROW allow to be sure to send the command only when there is rows updated, so how could I stop its execution after the first loop ?
It looks you're going to use compound trigger. In for each row section you need to collect rowids to update and in after statement run whole update
Use global package variable.
1) Reset it to null in before update statement trigger.
2) Save values/inc counter in for each row trigger
3) do final check in after update statement trigger and fire your logic inly once regardless number of affected rows

Oracle Delete multiple columns (not a drop)

Dears,
I am trying to delete multiple columns values in an oracle table, I am running the below script but it seems that it is not working (although it did in SQL server).
DELETE a.mobile_num ,
a.price_list,
a.cust_segment,
a.classification,
a.region,
a.district,
a.localty,
a.dsl_install_dt,
a.dsl_oper_status,
a.fl_install_dt,
a.fl_status,
a.oper_status_cd
From mkt_wl_history_2 a;
Thanks,
You cannot delete column values in Oracle, you can delete entire rows. If I understand correctly you are trying to set these values to NULL.
In this case you can use the following statement.
UPDATE mkt_wl_history_2
SET price_list=NULL,
cust_segment=NULL,
classification=NULL,
region=NULL,
district=NULL,
localty=NULL,
dsl_install_dt=NULL,
dsl_oper_status=NULL,
fl_install_dt=NULL,
fl_status=NULL,
oper_status_cd=NULL
Also, I assume you have to do this for all rows in your table. If not then please apply an appropriate where condition.
Use queries similar to this to set all values of a column to the default value:
UPDATE mtk_wl_history_2 SET mobile_num = DEFAULT

Resources