SQL Practice Logo

SQLPractice Online

Oracle Features Deep Dive: Concept

Module: Database-Specific Features

Oracle Database is the enterprise standard for mission-critical systems. Think of it as the "luxury car" of databases - expensive but packed with features. While MySQL is a Honda (reliable, affordable), Oracle is a Mercedes (premium, feature-rich, expensive). Oracle excels at: 1) Complex transactions (banking), 2) High availability (RAC clustering), 3) Massive scale (partitioning), 4) Advanced analytics (materialized views). The trade-off: Licensing costs $47,500 per CPU plus 22% annual support. This explains why startups use PostgreSQL but banks use Oracle.

**1. PL/SQL - Oracle Procedural Language**

PL/SQL extends SQL with procedural capabilities (variables, loops, error handling). Similar to T-SQL (SQL Server) and PL/pgSQL (PostgreSQL) but more mature.

```sql

-- PL/SQL procedure example

CREATE OR REPLACE PROCEDURE process_order(

p_order_id IN NUMBER,

p_status OUT VARCHAR2

) AS

v_customer_id NUMBER;

v_total_amount NUMBER;

insufficient_inventory EXCEPTION;

BEGIN

-- Get order details

SELECT customer_id, total_amount

INTO v_customer_id, v_total_amount

FROM orders

WHERE order_id = p_order_id;

-- Check inventory

IF check_inventory(p_order_id) = 0 THEN

RAISE insufficient_inventory;

END IF;

-- Process payment

UPDATE accounts

SET balance = balance - v_total_amount

WHERE customer_id = v_customer_id;

-- Update order status

UPDATE orders

SET status = 'COMPLETED'

WHERE order_id = p_order_id;

COMMIT;

p_status := 'SUCCESS';

EXCEPTION

WHEN insufficient_inventory THEN

ROLLBACK;

p_status := 'INSUFFICIENT_INVENTORY';

WHEN OTHERS THEN

ROLLBACK;

p_status := 'ERROR: ' || SQLERRM;

END;