Oracle Database User Manual

Database Connection

SQL*Plus Connection

-- Local connection
sqlplus username/password@localhost:1521/SID

-- Remote connection
sqlplus username/password@hostname:1521/service_name

-- System administrator connection
sqlplus / as sysdba

JDBC Connection String

// Oracle Database 19c/26ai
String url = "jdbc:oracle:thin:@//hostname:1521/service_name";
String driver = "oracle.jdbc.OracleDriver";

TNS Configuration

ORCL =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = ORCL)
    )
  )

SQL Basic Operations

Data Definition Language (DDL)

-- Create table
CREATE TABLE employees (
    employee_id NUMBER PRIMARY KEY,
    first_name VARCHAR2(50),
    last_name VARCHAR2(50) NOT NULL,
    email VARCHAR2(100) UNIQUE,
    hire_date DATE DEFAULT SYSDATE,
    salary NUMBER(8,2)
);

-- Modify table structure
ALTER TABLE employees ADD department_id NUMBER;
ALTER TABLE employees MODIFY salary NUMBER(10,2);
ALTER TABLE employees DROP COLUMN department_id;

-- Drop table
DROP TABLE employees;

Data Manipulation Language (DML)

-- Insert data
INSERT INTO employees (employee_id, first_name, last_name, email, salary)
VALUES (101, 'John', 'Doe', '[email protected]', 5000.00);

-- Query data
SELECT employee_id, first_name, last_name, salary
FROM employees
WHERE salary > 4000
ORDER BY last_name;

-- Update data
UPDATE employees
SET salary = salary * 1.1
WHERE department_id = 10;

-- Delete data
DELETE FROM employees
WHERE employee_id = 101;

PL/SQL Programming

Stored Procedures

CREATE OR REPLACE PROCEDURE update_employee_salary(
    p_employee_id IN NUMBER,
    p_new_salary IN NUMBER
)
IS
BEGIN
    UPDATE employees
    SET salary = p_new_salary
    WHERE employee_id = p_employee_id;
    
    IF SQL%ROWCOUNT = 0 THEN
        RAISE_APPLICATION_ERROR(-20001, 'Employee not found');
    END IF;
    
    COMMIT;
EXCEPTION
    WHEN OTHERS THEN
        ROLLBACK;
        RAISE;
END;
/

Functions

CREATE OR REPLACE FUNCTION get_employee_name(
    p_employee_id IN NUMBER
) RETURN VARCHAR2
IS
    v_full_name VARCHAR2(101);
BEGIN
    SELECT first_name || ' ' || last_name
    INTO v_full_name
    FROM employees
    WHERE employee_id = p_employee_id;
    
    RETURN v_full_name;
EXCEPTION
    WHEN NO_DATA_FOUND THEN
        RETURN NULL;
END;
/

Triggers

CREATE OR REPLACE TRIGGER employees_audit_trigger
    BEFORE INSERT OR UPDATE OR DELETE ON employees
    FOR EACH ROW
DECLARE
    v_action VARCHAR2(10);
BEGIN
    IF INSERTING THEN
        v_action := 'INSERT';
    ELSIF UPDATING THEN
        v_action := 'UPDATE';
    ELSE
        v_action := 'DELETE';
    END IF;
    
    INSERT INTO employees_audit (
        employee_id, action, action_date, user_name
    ) VALUES (
        NVL(:OLD.employee_id, :NEW.employee_id),
        v_action,
        SYSDATE,
        USER
    );
END;
/

Performance Optimization

Index Management

-- Create B-tree index
CREATE INDEX idx_employees_last_name ON employees(last_name);

-- Create bitmap index (suitable for low cardinality columns)
CREATE BITMAP INDEX idx_employees_department ON employees(department_id);

-- Create function-based index
CREATE INDEX idx_employees_upper_name ON employees(UPPER(last_name));

Execution Plan Analysis

-- View execution plan
EXPLAIN PLAN FOR
SELECT * FROM employees WHERE last_name = 'Smith';

SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY);

Statistics Collection

-- Collect table statistics
EXEC DBMS_STATS.GATHER_TABLE_STATS('HR', 'EMPLOYEES');

-- Collect schema statistics
EXEC DBMS_STATS.GATHER_SCHEMA_STATS('HR');

Backup and Recovery

RMAN Backup

# Connect to RMAN
rman target /

# Full database backup
BACKUP DATABASE;

# Incremental backup
BACKUP INCREMENTAL LEVEL 1 DATABASE;

# Archive log backup
BACKUP ARCHIVELOG ALL;

Data Pump Export/Import

# Export entire database
expdp system/password FULL=Y DIRECTORY=DATA_PUMP_DIR DUMPFILE=full_db.dmp

# Export specific schema
expdp hr/hr SCHEMAS=HR DIRECTORY=DATA_PUMP_DIR DUMPFILE=hr_schema.dmp

# Import data
impdp system/password DIRECTORY=DATA_PUMP_DIR DUMPFILE=hr_schema.dmp

High Availability Features

Real Application Clusters (RAC)

  • Multi-node cluster architecture
  • Shared storage configuration
  • Service load balancing
  • Automatic failover

Data Guard

  • Primary-standby database synchronization
  • Physical standby and logical standby
  • Automatic failover
  • Read-write separation

Monitoring and Management

Dynamic Performance Views

-- View session information
SELECT sid, serial#, username, status, machine, program
FROM v$session
WHERE username IS NOT NULL;

-- View lock information
SELECT session_id, lock_type, mode_held, mode_requested
FROM dba_locks;

-- View tablespace usage
SELECT tablespace_name, 
       ROUND(SUM(bytes)/1024/1024, 2) AS size_mb,
       ROUND(SUM(maxbytes)/1024/1024, 2) AS max_size_mb
FROM dba_data_files
GROUP BY tablespace_name;

AWR Reports

-- Generate AWR report
@?/rdbms/admin/awrrpt.sql

Oracle Database 26ai New Features

Oracle Database 26ai introduces AI-driven automation features:

  • Automatic SQL Tuning: AI analyzes query patterns and automatically optimizes
  • Predictive Maintenance: Predicts potential issues and provides early warnings
  • Intelligent Resource Management: Dynamically adjusts memory and CPU allocation
  • Enhanced Security Monitoring: AI-driven anomaly detection

Detailed new feature documentation should be referenced from Oracle's official website.

Best Practices

Security Configuration

  • Use strong password policies
  • Enable Transparent Data Encryption (TDE)
  • Configure fine-grained access control
  • Regularly audit database activities

Performance Optimization

  • Design table structures and indexes appropriately
  • Use bind variables to avoid hard parsing
  • Collect statistics regularly
  • Monitor and optimize slow queries

High Availability

  • Implement appropriate backup strategies
  • Configure Data Guard or RAC
  • Test recovery procedures regularly
  • Monitor system health status

Reference Documentation