List All Usernames
List All Usernames
CREATE SESSION
CREATE TABLE
DROP TABLE
UNLIMITED TABLESPACE
CREATE USER
Managing Tablespace - You may/should create tablespace for each user so that they do not need to share the same
file space.
Example tablespace script.
CREATE TABLESPACE lhoward
DATAFILE 'C:\oracle\lhoward\lhoward.dbf' SIZE 30M;
Defining Data
Data Types:
CHAR
VARCHAR2
NCHAR
NUMBER
DATE
BLOB
CLOB
BFILE
NCLOB
Contraint Types
Primary Key
Foreign Key
Check Condition
Not Null
Unique
DESCRIBE table_name;
Create a sequence
CREATE SEQUENCE sequence_name
[INCREMENT BY number]
[START WITH start_value]
[MAXVALUE max_value]
[MINVALUE min_value]
[CYCLE]
[ORDER]
Drop a Sequence
DROP SEQUENCE sequence_name;
Pseudocolumns CURRVAL Most recent sequence number
Managing Data
Add a new record to a table (references all columns)
INSERT INTO table_name
VALUES(col1_value, col2_value, ...);
Alternate syntax for adding new record (puts data only into names columns)
INSERT INTO table_name (col-x_name, col-y_name, ...)
VALUES(col-x_value, col-y_value, ...);
Retrieving Data
Special Tables
Objects
Tables
Indexes
Views
Sequences
Users
Constraints
Cons_Columns
Ind_Columns
Tab_Columns
DUAL
Basic Join
SELECT display_fields
FROM table1, table2
WHERE table1_foreign_key=table2_primary_key AND
other_field_conditions;
Numeric Functions
Convert a date string into an internal date where date_format specifies format of string date.
TO_DATE(string_date, date_format)
Return the mod of number in the indicated base
MOD(number, base)
Raise number to the indicated exponent
POWER(number, exponent)
Round number to the indicated precision (number of decimal places)
ROUND(number precision)
Truncate number to the indicated precision (number of decimal places)
TRUNC(number, precision)
CEIL Ceiling
FLOOR Floor
String Functions
CONCAT(string1, string2)
LPAD(string, num_chars, pad_char)
RPAD(string, num_chars, pad_char)
LTRIM(string, search_string)
RTRIM(string, search_string)
REPLACE(string, search_string, replacement_string)
SUBSTR(string, start_posn, length)
Date Functions
ADD_Months(date, num_months_to_add)
LAST_DAY(date) - Last day of month as date
MONTHS_BETWEEN(date1, date2) - returns decimal difference in months
CREATE TABLE temp AS SELECT fname, minit, lname, ssn, bdate, address, sex, superssn, dno FROM employee;
where the <format> string can be formed from over 40 options. Some of the more popular ones
include:
Like YY, but the two digits are ``rounded'' to a year in the range 1950 to 2049. Thus, 06 is
RR
considered 2006 instead of 1906, for example.
AM (or
Meridian indicator
PM)