How to set default values when creating a table in Oracle?
In Oracle, you can use the DEFAULT keyword to set default values. The syntax is as follows:
CREATE TABLE table_name (
column1 datatype DEFAULT default_value,
column2 datatype DEFAULT default_value,
...
);
For example, create a sample table with default values.
CREATE TABLE employees (
employee_id NUMBER,
first_name VARCHAR2(50) DEFAULT 'John',
last_name VARCHAR2(50) DEFAULT 'Doe',
salary NUMBER DEFAULT 50000
);
In the example table above, if data is inserted without specifying values for first_name, last_name, and salary, they will be assigned default values.