You can update a column and set it back to the default using the DEFAULT keyword in an UPDATE statement : UPDATE Set Clause « Insert Delete Update « Oracle PL / SQL






You can update a column and set it back to the default using the DEFAULT keyword in an UPDATE statement

 


SQL>
SQL> --You can update a column and set it back to the default using the DEFAULT keyword in an UPDATE statement
SQL>
SQL> CREATE TABLE order_status (
  2    order_status_id INTEGER,
  3    status VARCHAR2(20) DEFAULT 'Order placed' NOT NULL,
  4    last_modified DATE DEFAULT SYSDATE
  5  );

Table created.

SQL>
SQL>
SQL> --Override the defaults by specifying a value for the columns
SQL>
SQL> INSERT INTO order_status (order_status_id)
  2  VALUES (2);

1 row created.

SQL>
SQL>
SQL>
SQL>
SQL> SELECT * FROM order_status;

ORDER_STATUS_ID STATUS               LAST_MODIFI
--------------- -------------------- -----------
              2 Order placed         2006-SEP-17

SQL>
SQL> UPDATE order_status
  2  SET status = DEFAULT
  3  WHERE order_status_id = 2;

1 row updated.

SQL>
SQL> SELECT * FROM order_status;

ORDER_STATUS_ID STATUS               LAST_MODIFI
--------------- -------------------- -----------
              2 Order placed         2006-SEP-17

SQL>
SQL> drop table order_status;

Table dropped.

SQL>
SQL>
           
         
  








Related examples in the same category

1.Use arithmetic operators and functions in the SET clause to modify data
2.An example of using a function in the SET clause
3.Change multiple rows and multiple columns in the same UPDATE statement
4.Use TO_DATE('December 31, 2002, 11:30 P.M.','Month dd, YYYY, HH:MI P.M.') in set statement
5.Update data from existing column
6.Update four columns
7.Update number type column
8.Update one row