Catalog / Oracle Database SQL Cheatsheet
Oracle Database SQL Cheatsheet
A quick reference guide to Oracle SQL, covering essential commands, functions, and concepts for database management and querying.
Basic SQL Commands
Data Retrieval
|
Retrieves data from one or more tables. Example:
|
|
Specifies the table(s) to retrieve data from. Example:
|
|
Filters the rows based on a specified condition. Example:
|
|
Sorts the result-set in ascending or descending order. Example:
|
|
Groups rows that have the same values in specified columns into summary rows. Example:
|
|
Filters the groups based on a specified condition (used with Example:
|
|
Returns only distinct (unique) values. Example:
|
Data Manipulation
|
Inserts new rows into a table. Example:
|
|
Modifies existing rows in a table. Example:
|
|
Deletes rows from a table. Example:
|
|
Combines Example:
|
Advanced SQL Concepts
Joins
|
Returns rows when there is a match in both tables. Example:
|
|
Returns all rows from the left table, and the matched rows from the right table. If there is no match, the result is NULL on the right side. Example:
|
|
Returns all rows from the right table, and the matched rows from the left table. If there is no match, the result is NULL on the left side. Example:
|
|
Returns all rows when there is a match in one of the tables. Example:
|
|
Returns the Cartesian product of the sets of rows from the joined tables. Example:
|
Subqueries
Definition |
A query nested inside another query. Example:
|
Types |
|
Set Operations
|
Combines the result-set of two or more Example:
|
|
Combines the result-set of two or more Example:
|
|
Returns the intersection of two Example:
|
|
Returns the difference between two Example:
|
Data Types and Functions
Common Data Types
|
Variable-length character string. Example: |
|
Numeric data type with precision Example: |
|
Stores date and time values. Example: |
|
Character Large Object; stores large blocks of text. Example: |
|
Binary Large Object; stores large binary data. Example: |
|
Stores date and time with fractional seconds. Example: |
String Functions
|
Converts a string to uppercase. Example: |
|
Converts a string to lowercase. Example: |
|
Extracts a substring from a string. Example: |
|
Returns the length of a string. Example: |
|
Removes leading and trailing spaces from a string. Example: |
|
Replaces occurrences of a substring with another substring. Example: |
Number Functions
|
Rounds a number to a specified number of decimal places. Example: |
|
Truncates a number to a specified number of decimal places. Example: |
|
Returns the remainder of a division operation. Example: |
|
Returns the smallest integer greater than or equal to a number. Example: |
|
Returns the largest integer less than or equal to a number. Example: |
Date Functions
|
Returns the current date and time. Example: |
|
Converts a date to a character string using a specified format. Example: |
|
Converts a character string to a date using a specified format. Example: |
|
Adds a specified number of months to a date. Example: |
|
Returns the number of months between two dates. Example: |
PL/SQL Basics
PL/SQL Structure
|
Variables and Data Types
Declaration |
Example:
|
Common Data Types |
|
Control Structures
IF Statement |
|
Looping Statements |
|
Example - FOR Loop |
|
Exception Handling
Syntax |
|
Common Exceptions |
|