Oracle SQL Developer – Create auto incrementing primary key

To make primary key auto increment in Oracle, you need to set the identity column property for that primary key.

Right click on the table and select Edit.

In Edit Table window, select columns, and then select your primary key column.

Go to Identity Column tab and select Column Sequence as Type. This will create a trigger and a sequence, and associate the sequence to primary key.

OracleAutoIncrement

Oracle SQL Developer – Display Date and Time

By default Oracle SQL Developer displays only a date component on date time field. You can change this behaviour in preferences.

Go to Tools -> Preferences -> Database -> NLS and change Date Format value to DD-MON-RR HH24:MI:SS (for 24 hour time display) or DD-MON-RR HH:MI:SS (for 12 hour time display).

SQLDev

Oracle – Check if field has been updated inside an update trigger

If you have an update trigger in Oracle and want to check if value of specific field has changed, use (note the single quotes around field name)

IF UPDATING('MyField') THEN

If you try to use

IF UPDATING(:NEW.MyField) THEN

it will not work, as :NEW.MyField value hasn’t actually changed, so the check will always return false.

You can also compare old and new values

IF :NEW.MyField != :OLD.MyField THEN