IPA
IPA/block-7
Oracle Database is a powerful and complex RDBMS, offering a wide range of features for efficient data management. This cheat sheet provides a quick reference to essential commands and operations.
sql sqlplus username/password@hostname:port/SID
bashconn username/password@hostname:port/SID
sql SELECT * FROM table_name;
sql SELECT column1, column2 FROM table_name;
sql INSERT INTO table_name (column1, column2) VALUES (value1, value2);
sql UPDATE table_name SET column1 = value1 WHERE condition;
sql DELETE FROM table_name WHERE condition;
Create Database
sql CREATE DATABASE database_name;
Drop Database
sql DROP DATABASE database_name;
Create Table
sql CREATE TABLE table_name (
column1 datatype CONSTRAINT,
column2 datatype CONSTRAINT,
...
);
Drop Table
sql DROP TABLE table_name;
Primary Key
sql ALTER TABLE table_name ADD CONSTRAINT pk_name PRIMARY KEY (column);
Foreign Key
sql ALTER TABLE table_name ADD CONSTRAINT fk_name FOREIGN KEY (column) REFERENCES other_table (other_column);
Unique Key
sql ALTER TABLE table_name ADD CONSTRAINT unique_name UNIQUE (column);
Create Index
sql CREATE INDEX index_name ON table_name (column);
Drop Index
sql DROP INDEX index_name;
Create View
sql CREATE VIEW view_name AS
SELECT column1, column2
FROM table_name
WHERE condition;
Drop View
sql DROP VIEW view_name;
Begin Transaction
sql BEGIN;
Commit
sql COMMIT;
Rollback
sql ROLLBACK;
Anonymous Block
sql DECLARE
variable_name datatype;
BEGIN
-- PL/SQL statements
EXCEPTION
WHEN exception_name THEN
-- exception handling
END;
Stored Procedure
sql CREATE OR REPLACE PROCEDURE procedure_name IS
BEGIN
-- PL/SQL statements
END procedure_name;
Stored Function
sql CREATE OR REPLACE FUNCTION function_name RETURN datatype IS
BEGIN
-- PL/SQL statements
RETURN value;
END function_name;
Trigger
sql CREATE OR REPLACE TRIGGER trigger_name
BEFORE INSERT OR UPDATE OR DELETE ON table_name
FOR EACH ROW
BEGIN
-- PL/SQL statements
END trigger_name;
Create User
sql CREATE USER username IDENTIFIED BY password;
Grant Privileges
sql GRANT privilege TO username;
Create Role
sql CREATE ROLE role_name;
Grant Role
sql GRANT role_name TO username;
Show Tables
sql SELECT table_name FROM all_tables;
Describe Table
sql DESC table_name;
Show Users
sql SELECT username FROM all_users;
Show Current User
sql SELECT user FROM dual;
String Functions
sql UPPER(string);
LOWER(string);
SUBSTR(string, start_position, length);
Numeric Functions
sqlROUND(number, decimal_places); TRUNC(number, decimal_places);
Date Functions
sql SYSDATE;
TO_DATE('YYYY-MM-DD', 'format');
This cheat sheet provides a quick reference to commonly used commands and operations in Oracle Database, helping you manage and manipulate your data efficiently.
Tidak ada komentar
Posting Komentar