Oracle SQL Tips
Oracle SQL Tips
Oracle SQL Tips
Alter
Application:
Adding a column:
Example
Example
Example
ALTER TABLE cd
ADD CONSTRAINT cd_cd_id_pk PRIMARY KEY(cd_id);
Example
ALTER TABLE cd
ADD CONSTRAINT cd_cd_id_fk REFERENCES cd(cd_id); Create
Application:
Application:
Example
Example
Application:
Insert record
Example
Modify
Application:
Example:
ALTER project MODIFY (name varchar2(50))
Rename
Application:
Renames a table.
Rename table
Example:
SELECT Statement
Example
Column Alias
Creates an alias for the database column. SELECT column name "alias name" FROM table
Example
Order By
Example
COUNT
Example
SELECT count(*) FROM projects
AVG
Example
SUM
Example
MIN
Example
MAX
Example
Distinct
Example
Example
SELECT total+5 FROM project
Example
SELECT project_name FROM projects WHERE project_date > '02-FEB-00' AND project_cost <
150.00
LIKE or =
Example LIKE
Use when applying wildcards on VARCHAR2 datatypes. SELECT name FROM project WHERE name LIKE
'JONES%'
Example =
Use when knowing the exact search parameter in your WHERE cluase. SELECT cost FROM project WHERE
cost = 150.00 SQL Plus
Commands
Most of the commands listed here also require a FULL path name to carry out the desired task.
Save FILENAME
Saves a file.
Get FILENAME
Opens a file.
Start FILENAME
Executes a file.
@FILENAME
Executes a file.
Edit FILENAME
Spool FILENAME
Spools out to a file.
Exit
Disc
Connect
Formatting Columns
Apply these techniques to alter the way your data is displayed in a columnar format.
Examples
COLUMN name
Clear Settings
Describe
Example
DESCR project