Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
Difference between SQL and PL/SQL
SQL (Structured Query Language) is a standard database language used to create, maintain, and retrieve data from relational databases. PL/SQL (Procedural Language extension to SQL) extends SQL by adding procedural capabilities like variables, loops, conditions, and error handling.
SQL Example
SQL executes a single declarative statement at a time ?
-- SQL: single operation, declarative SELECT name, salary FROM employees WHERE department = 'Engineering';
PL/SQL Example
PL/SQL can execute multiple operations with procedural logic ?
-- PL/SQL: procedural block with variables, loops, conditions
DECLARE
v_name employees.name%TYPE;
v_bonus NUMBER;
BEGIN
FOR emp IN (SELECT name, salary FROM employees) LOOP
IF emp.salary > 50000 THEN
v_bonus := emp.salary * 0.10;
ELSE
v_bonus := emp.salary * 0.05;
END IF;
DBMS_OUTPUT.PUT_LINE(emp.name || ' bonus: ' || v_bonus);
END LOOP;
END;
Key Differences
| Feature | SQL | PL/SQL |
|---|---|---|
| Full Form | Structured Query Language | Procedural Language extension to SQL |
| Language Type | Declarative (what to do) | Procedural (how to do) |
| Variables | Not supported | Variables, data types, constants |
| Control Structures | None | IF, FOR, WHILE, LOOP, CASE |
| Execution | One statement at a time | Block of multiple statements |
| DB Interaction | Directly interacts with database server | Sends SQL blocks to database server |
| Orientation | Data-oriented | Application-oriented |
| Used For | Queries, DDL, DML statements | Program blocks, functions, procedures, triggers, packages |
| Error Handling | Not built-in | Built-in exception handling (EXCEPTION block) |
Conclusion
SQL is used for direct data manipulation with single declarative statements. PL/SQL extends SQL with procedural capabilities, allowing developers to write complex business logic with variables, loops, conditions, and error handling in a single executable block.
Advertisements
