DDL, DML, TCL Commands-1
DDL, DML, TCL Commands-1
DDL commands are used to define, modify, and manage database objects such as tables,
indexes, and schemas. The key DDL commands in Oracle are:
✅ Deletes all rows from EMPLOYEES, but keeps the structure intact.
⚠️ Unlike DELETE, you cannot rollback a TRUNCATE.
1. INSERT Command
The INSERT statement is used to add new rows to a table.
Syntax:
INSERT INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...);
Example:
INSERT INTO employees (employee_id, first_name, last_name, salary,
department_id) VALUES (101, 'John', 'Doe', 50000, 10);
INSERT ALL
INTO employees (employee_id, first_name, last_name, salary,
department_id) VALUES (102, 'Jane', 'Smith', 55000, 20)
INTO employees (employee_id, first_name, last_name, salary,
department_id) VALUES (103, 'Mike', 'Brown', 60000, 30) SELECT * FROM dual;
How to insert values into table by using & symbol in Oracle
at runtime:
You can use the & symbol in Oracle SQL to take input values at runtime when inserting records
into a table. Here’s how you can do it:
Optional
General Syntax
INSERT INTO table_name (column1, column2, column3)
VALUES (&value1, '&value2', TO_DATE('&value3', 'YYYY-MM-DD'));
Assume you have a table named EMPLOYEES with columns EMP_ID (NUMBER), EMP_NAME
(VARCHAR2), and HIRE_DATE (DATE).
How It Works
1. When you run the query, Oracle will prompt you to enter values for:
o &emp_id → Example: 101
o &emp_name → Example: John Doe
o &hire_date → Example: 2024-02-01
2. The TO_DATE('&hire_date', 'YYYY-MM-DD') ensures the date is correctly formatted
before insertion. Last executed
3. The record gets inserted into the table. statement in the Buffer
For inserting multiple rows at runtime, we can use / symbol at SQL prompt
after insertion of first record, the prompt will repeatedly ask data for insertion
In Oracle SQL, you can use the & symbol to accept user input at runtime, and to insert a date into
a table, you should use the TO_DATE function to ensure the correct format. Here’s how you can
do it:
Example
Assume you have a table named EMPLOYEES with a column HIRE_DATE of type DATE:
Steps
1. When executing the query, Oracle will prompt you to enter values for &emp_id,
&emp_name, and &hire_date.
2. Enter the date in the format YYYY-MM-DD (or another expected format).
3. Oracle will convert the input string into a valid DATE format using TO_DATE.
Syntax:
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
Example:
UPDATE employees
SET salary = salary + 5000
WHERE department_id = 10;
3. DELETE Command
The DELETE statement removes one or more records from a table.
Syntax:
DELETE FROM table_name
WHERE condition;
Example:
DELETE FROM employees
WHERE employee_id = 101;
⚠️ Note: If WHERE is omitted, all rows will be deleted, but the table structure remains.
TCL (Transaction Control Language)
TCL (Transaction Control Language) commands manage transactions in Oracle Database. They
ensure data consistency and integrity during operations.
TCL Commands:
1. COMMIT – Saves all changes made by the transaction.
2. ROLLBACK – Reverts all changes since the last COMMIT.
3. SAVEPOINT – Creates a temporary save point to roll back to a specific point in a
transaction.
1. COMMIT Command
The COMMIT statement saves all changes made during the current transaction permanently in the
database.
Syntax:
COMMIT;
Example:
UPDATE employees SET salary = salary + 5000 WHERE department_id = 10;
COMMIT; -- Changes are saved permanently
2. ROLLBACK Command
The ROLLBACK statement undoes all changes made in the current transaction since the last
COMMIT.
Syntax:
ROLLBACK;
Example:
UPDATE employees SET salary = salary + 5000 WHERE department_id = 10;
ROLLBACK; -- Reverts salary changes back to original
3. SAVEPOINT Command
The SAVEPOINT statement allows rolling back part of a transaction instead of the entire
transaction.
Syntax:
SAVEPOINT savepoint_name;
Example:
UPDATE employees SET salary = salary + 5000 WHERE employee_id = 101;
SAVEPOINT before_bonus;