{"id":182,"date":"2009-06-24T11:14:25","date_gmt":"2009-06-24T05:44:25","guid":{"rendered":"http:\/\/www.oratraining.com\/blog\/?p=182"},"modified":"2009-06-24T11:14:25","modified_gmt":"2009-06-24T05:44:25","slug":"sq-quick-referenence","status":"publish","type":"post","link":"https:\/\/www.oratraining.com\/blog\/2009\/06\/sq-quick-referenence\/","title":{"rendered":"Oracle SQL Quick reference"},"content":{"rendered":"<p><strong>Oracle SQL Quick Reference<\/strong><strong> <\/strong><\/p>\n<p><strong>SELECT Query Statement<\/strong><\/p>\n<p>SELECT [DISTINCT] {*, column [alias],&#8230;}<\/p>\n<p>FROM table<\/p>\n<p>WHERE condition(s)]<\/p>\n<p>ORDER BY {column, exp, alias} [ASC|DESC]]<\/p>\n<p><strong><em>NOTE:<\/em><\/strong><em> <\/em><\/p>\n<p><em>Avoid using DISTINCT with large table as it first does sorting of all the rows and then eliminates duplicate rows, so need a full table scan and thus it&#8217;s very slow.<\/em><\/p>\n<p><em> <\/em><\/p>\n<p><em>ORDER BY is the last clause to get executed and thus could see all the column aliases; You can sort by a columns that is not in SELECT list; Default sorting order is Ascending (ASC)<\/em><\/p>\n<p><!--more--><\/p>\n<p><strong>Joins<\/strong><\/p>\n<p><strong>Oracle proprietary syntax for version 8i and earlier<\/strong><\/p>\n<p><strong>Cartesian Product<\/strong><\/p>\n<p>SELECT table1.*, table2.*,[&#8230;]<\/p>\n<p>FROM table1,table2[,&#8230;]<\/p>\n<p><strong> <\/strong><\/p>\n<p><strong>Equijoin(Simple joins or inner join)<\/strong><\/p>\n<p>SELECT table1.*,table2.*<\/p>\n<p>FROM table1,table2<\/p>\n<p>WHERE table1.column = table2.column<\/p>\n<p><strong> <\/strong><\/p>\n<p><strong>Non-Equijoin<\/strong><\/p>\n<p>SELECT table1.*, table2.*<\/p>\n<p>FROM table1, table2<\/p>\n<p>WHERE table1.column<\/p>\n<p>BETWEEN table2.column1 AND table2.column2<\/p>\n<p><strong> <\/strong><\/p>\n<p><strong>Outer join<\/strong><\/p>\n<p>SELECT table1.*,table2.*<\/p>\n<p>FROM table1,table2<\/p>\n<p>WHERE table1.column(+) = table2.column<\/p>\n<p>SELECT table1.*,table2.*<\/p>\n<p>FROM table1,table2<\/p>\n<p>WHERE table1.column = table2.column(+)<\/p>\n<p><strong> <\/strong><\/p>\n<p><strong>Self join<\/strong><\/p>\n<p>SELECT alias1.*,alias2.*<\/p>\n<p>FROM table1 alias1,table1 alias2<\/p>\n<p>WHERE alias1.column = alias2.column<\/p>\n<p><strong>SQL: 1999 compliant syntax for version 9i<\/strong><\/p>\n<p>SELECT table1.column, table2.column<\/p>\n<p>FROM table1<\/p>\n<p>[<strong>CROSS JOIN<\/strong> table2] |<\/p>\n<p>[<strong>NATURAL JOIN<\/strong> table2] |<\/p>\n<p>[<strong>JOIN<\/strong> table2 <strong>USING<\/strong> (column_name)] |<\/p>\n<p>[<strong>JOIN<\/strong> table2<\/p>\n<p><strong>ON<\/strong> (table1.column_name=table2.column_name)] |<\/p>\n<p>[<strong>LEFT<\/strong>|<strong>RIGHT<\/strong>|<strong>FULL<\/strong> <strong>OUTER<\/strong> <strong>JOIN<\/strong> table2<\/p>\n<p><strong>ON<\/strong> (table1.column_name=table2.column_name)];<\/p>\n<p><strong> <\/strong><\/p>\n<p><strong>Aggregation Selecting<\/strong><\/p>\n<p>SELECT [column,] group_function(column),&#8230;<\/p>\n<p>FROM table<\/p>\n<p>[WHERE condition]<\/p>\n<p>[GROUP BY group_by_expression]<\/p>\n<p>[HAVING group_condition]<\/p>\n<p>[ORDER BY column];<\/p>\n<p><strong> <\/strong><\/p>\n<p><strong>Group function<\/strong><\/p>\n<p>AVG([DISTINCT|ALL]n)<\/p>\n<p>COUNT(*|[DISTINCT|ALL]expr)<\/p>\n<p>MAX([DISTINCT|ALL]expr)<\/p>\n<p>MIN([DISTINCT|ALL]expr)<\/p>\n<p>STDDEV([DISTINCT|ALL]n)<\/p>\n<p>SUM([DISTINCT|ALL]n)<\/p>\n<p>VARIANCE([DISTINCT|ALL]n)<\/p>\n<p><strong> <\/strong><\/p>\n<p><strong>NOTE:<\/strong><\/p>\n<p><em>All columns in the SELECT list that are not in group functions must be in the GROUP BY clause; but GROUP BY column does not have to be in the SELECT list.<\/em><\/p>\n<p><em> <\/em><\/p>\n<p><em>You can not use group functions in the WHERE clause;You use the HAVING clause to restrict groups.<\/em><\/p>\n<p><em>All group functions except count(*) ignores null values. The NVL function forces group functions to include null values.<\/em><\/p>\n<p><strong> <\/strong><\/p>\n<p><strong>Subquery<\/strong><\/p>\n<p>SELECT select_list<\/p>\n<p>FROM table<\/p>\n<p>WHERE expr operator(SELECT \u00a0\u00a0 select_list<\/p>\n<p>FROM \u00a0\u00a0\u00a0\u00a0 table);<\/p>\n<p><strong>NOTE:<\/strong><\/p>\n<p><em>The subquery(inner query) executes once before the main query<\/em><\/p>\n<p><em> <\/em><\/p>\n<p><em>The result of the subquery is used by the main query(outer query)<\/em><\/p>\n<p><em> <\/em><\/p>\n<p><em>The ORDER BY clause in the subquery is not needed unless you are performing TOP-N analysis.<\/em><\/p>\n<p><strong>single-row comparison operators: <\/strong>Return only one row<\/p>\n<p>=\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &gt; \u00a0\u00a0\u00a0 &gt;= \u00a0\u00a0 &lt; \u00a0\u00a0\u00a0 &lt;= \u00a0\u00a0 &lt;&gt;<\/p>\n<p><strong>multiple-row comparison operators: <\/strong>Return more than one row<\/p>\n<p>IN \u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\u00a0ANY \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ALL<\/p>\n<p><strong> <\/strong><\/p>\n<p><strong>Multiple-column Subqueries<\/strong><\/p>\n<p>SELECT column, column, &#8230;<\/p>\n<p>FROM table<\/p>\n<p>WHERE (column, column, &#8230;) IN<\/p>\n<p>(SELECT column, column, &#8230;<\/p>\n<p>FROM table<\/p>\n<p>WHERE condition);<\/p>\n<p><strong>Data Manipulation Statements (DML)<\/strong><\/p>\n<p><strong>INSERT Statement(one row)<\/strong><\/p>\n<p>INSERT INTO table [ (column [,column&#8230;])]<\/p>\n<p>VALUES (value [,value&#8230;]);<\/p>\n<p><strong> <\/strong><\/p>\n<p><strong>INSERT Statement with Subquery<\/strong><\/p>\n<p>INSERT INTO table [ column(, column) ]<\/p>\n<p>subquery;<\/p>\n<p><strong> <\/strong><\/p>\n<p><strong>UPDATE Statement<\/strong><\/p>\n<p>UPDATE table<\/p>\n<p>SET column = value [, column = value,&#8230;]<\/p>\n<p>[WHERE condition];<\/p>\n<p><strong> <\/strong><\/p>\n<p><strong>Updating with Multiple-column Subquery<\/strong><\/p>\n<p>UPDATE table<\/p>\n<p>SET (column, column,&#8230;) =<\/p>\n<p>(SELECT column, column,&#8230;<\/p>\n<p>FROM table<\/p>\n<p>WHERE condition)<\/p>\n<p>WHERE condition;<\/p>\n<p><strong> <\/strong><\/p>\n<p><strong>Deleting Rows with DELETE Statement<\/strong><\/p>\n<p>DELETE [FROM] table<\/p>\n<p>[WHERE condition];<\/p>\n<p><strong> <\/strong><\/p>\n<p><strong>Deleting Rows Based on Another Table<\/strong><\/p>\n<p>DELETE FROM table<\/p>\n<p>WHERE column = (SELECT column<\/p>\n<p>FROM table<\/p>\n<p>WHERE condition);<\/p>\n<p><strong>MERGE statement<\/strong><\/p>\n<p>MERGE INTO table_name table_aliase<\/p>\n<p>USING (table|view|sub_query) alias<\/p>\n<p>ON (join condition)<\/p>\n<p>WHEN MATCHED THEN<\/p>\n<p>UPDATE SET<\/p>\n<p>col1 = col1_val,<\/p>\n<p>col2 = col2_val<\/p>\n<p>WHEN NOT MATCHED THEN<\/p>\n<p>INSERT (column_list)<\/p>\n<p>VALUES (column_values);<\/p>\n<p><strong>NOTE:<\/strong><\/p>\n<p>MERGE provides ability to conditionally update or insert data into a database table. It is useful in data warehousing applications. It avoids separate updates; increase performance and ease of use<\/p>\n<p><strong> <\/strong><\/p>\n<p><strong>Transaction Control Statements (TCL)<\/strong><\/p>\n<p>COMMIT;<\/p>\n<p>SAVEPOINT name;<\/p>\n<p>ROLLBACK [TO SAVEPOINT name];<\/p>\n<p><strong> <\/strong><\/p>\n<p><strong>Displaying table structure<\/strong><\/p>\n<p>DESC[RIBE] tablename<\/p>\n<p><strong>Data Definition Statemetns (DDL)<\/strong><\/p>\n<p><strong>CREATE TABLE Statement<\/strong><\/p>\n<p>CREATE TABLE [schema.]table<\/p>\n<p>(column datatype [DEFAULT expr] [,&#8230;]);<\/p>\n<p><strong> <\/strong><\/p>\n<p><strong>CREATE TABLE Statement with Subquery<\/strong><\/p>\n<p>CREATE TABLE [schema.]table<\/p>\n<p>[(column, column&#8230;)]<\/p>\n<p>AS subquery;<\/p>\n<p><strong>NOTE: <\/strong><\/p>\n<p><em>When a table is created using existing table except &#8220;NOT NULL&#8221; constraint, no other constraints are copied. If condition satisfied even rows are copied.<\/em><\/p>\n<p><em> <\/em><\/p>\n<p><strong> <\/strong><\/p>\n<p><strong>Datatype<\/strong><\/p>\n<p>VARCHAR2(size) \u00a0\u00a0 CHAR(size) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 NUMBER(p,s) \u00a0\u00a0\u00a0\u00a0\u00a0 DATE<\/p>\n<p>LONG \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0 CLOB \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 RAW \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 LONG RAW<\/p>\n<p>BLOB \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 BFILE\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ROWID<\/p>\n<p><strong> <\/strong><\/p>\n<p><strong>ALTER TABLE Statement <\/strong><\/p>\n<p><strong>Adding columns<\/strong><\/p>\n<p>ALTER TABLE table_name<\/p>\n<p>ADD (column datatype [DEFAULT expr]<\/p>\n<p>[, column datatype]&#8230;);<\/p>\n<p><strong> <\/strong><\/p>\n<p><strong>Changing a column&#8217;s type, size and default value of a Table<\/strong><\/p>\n<p>ALTER TABLE table_name<\/p>\n<p>MODIFY (column datatype [DEFAULT expr]<\/p>\n<p>[, column datatype]&#8230;);<\/p>\n<p><strong>RENAMING table column: <\/strong>Supported by 9.2 and higher version only<strong> <\/strong><\/p>\n<p>ALTER TABLE table_name<\/p>\n<p>RENAME column_name to new_column_name;<\/p>\n<p><strong> <\/strong><\/p>\n<p><strong>Dropping a column<\/strong><\/p>\n<p>ALTER TABLE table_name<\/p>\n<p>DROP (column);<\/p>\n<p><strong> <\/strong><\/p>\n<p><strong>Dropping a Table<\/strong><\/p>\n<p>DROP TABLE table_name;<\/p>\n<p><strong> <\/strong><\/p>\n<p><strong>Changing the Name of an Object<\/strong><\/p>\n<p>RENAME old_name TO new_name;<\/p>\n<p><strong> <\/strong><\/p>\n<p><strong>Trancating a Table<\/strong><\/p>\n<p>TRUNCATE TABLE table_name;<\/p>\n<p><strong> <\/strong><\/p>\n<p><strong>Adding Comments to a Table<\/strong><\/p>\n<p>COMMENT ON TABLE table_name | COLUMN table.column<\/p>\n<p>IS &#8216;text&#8217;;<\/p>\n<p><strong> <\/strong><\/p>\n<p><strong>Dropping a comment from a table<\/strong><\/p>\n<p>COMMENT ON TABLE table_name | COLUMN table.column IS &#8221; ;<\/p>\n<p><strong> <\/strong><\/p>\n<p><strong>Data Dictionary<\/strong><\/p>\n<p>ALL_OBJECTS \u00a0\u00a0\u00a0\u00a0\u00a0 USER_OBJECTS<\/p>\n<p>ALL_TABLES \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 USER_TABLES<\/p>\n<p>ALL_CATALOG \u00a0\u00a0\u00a0\u00a0\u00a0 USER_CATALOG or CAT<\/p>\n<p>ALL_COL_COMMENTS USER_COL_COMMENTS<\/p>\n<p>ALL_TAB_COMMENTS USER_TAB_COMMENTS<\/p>\n<p><strong> <\/strong><\/p>\n<p><strong>Defining Constraints<\/strong><\/p>\n<p>CREATE TABLE [schema.]table<\/p>\n<p>column datatype [DEFAULT expr][NOT NULL]<\/p>\n<p>[column_constraint],&#8230;<\/p>\n<p>[table_constraint][,&#8230;]);<\/p>\n<p><strong> <\/strong><\/p>\n<p><strong>Column constraint level<\/strong><\/p>\n<p>column [CONSTRAINT constraint_name] constraint_type,<\/p>\n<p><strong> <\/strong><\/p>\n<p><strong>Constraint_type<\/strong><\/p>\n<p>PRIMARY KEY REFERENCES table(column) UNIQUE<\/p>\n<p>CHECK (condition)<\/p>\n<p><strong> <\/strong><\/p>\n<p><strong>Table constraint level<\/strong>(except NOT NULL)<\/p>\n<p>column,&#8230;,[CONSTRAINT constraint_name]<\/p>\n<p>constraint_type (column,&#8230;),<\/p>\n<p><strong> <\/strong><\/p>\n<p><strong>NOT NULL Constraint (Only Column Level)<\/strong><\/p>\n<p>CONSTRAINT table[_column&#8230;]_nn NOT NULL &#8230;<\/p>\n<p><strong> <\/strong><\/p>\n<p><strong>UNIQUE Key Constraint<\/strong><\/p>\n<p>CONSTRAINT table[_column..]_uk UNIQUE (column[,&#8230;])<\/p>\n<p><strong> <\/strong><\/p>\n<p><strong>PRIMARY Key Constraint<\/strong><\/p>\n<p>CONSTRAINT table[_column..]_pk PRIMARY (column[,&#8230;])<\/p>\n<p><strong> <\/strong><\/p>\n<p><strong>NOTE: <\/strong><\/p>\n<p><em>PRIMARY Key defined on more than column called &#8216;Composite Primary Key&#8217; and to define composite primary key you need table level constraint as two columns are involved.<\/em><\/p>\n<p><strong> <\/strong><\/p>\n<p><strong>FOREIGN Key Constraint<\/strong><\/p>\n<p>CONSTRAINT table[_column..]_fk<\/p>\n<p>FOREIGN KEY (column[,&#8230;])<\/p>\n<p>REFERENCES table (column[,&#8230;])[ON DELETE CASCADE]<\/p>\n<p>[ON DELETE SET NULL];<\/p>\n<p><strong> <\/strong><\/p>\n<p><strong>CHECK constraint<\/strong><\/p>\n<p>CONSTRAINT table[_column..]_ck CHECK (condition)<\/p>\n<p><strong> <\/strong><\/p>\n<p><strong>Adding a Constraint<\/strong>(except NOT NULL)<\/p>\n<p>ALTER TABLE table_name<\/p>\n<p>ADD [CONSTRAINT constraint_name ] type (column);<\/p>\n<p><strong> <\/strong><\/p>\n<p><strong>Adding a NOT NULL constraint<\/strong><\/p>\n<p>ALTER TABLE table_name<\/p>\n<p>MODIFY (column datatype [DEFAULT expr]<\/p>\n<p>[CONSTRAINT constraint_name_nn] NOT NULL);<\/p>\n<p><strong> <\/strong><\/p>\n<p><strong>Dropping a Constraint<\/strong><\/p>\n<p>ALTER TABLE table_name<\/p>\n<p>DROP CONSTRAINT constraint_name;<\/p>\n<p>ALTER TABLE table_name<\/p>\n<p>DROP PRIMARY KEY | UNIQUE (column) |<\/p>\n<p>CONSTRAINT constraint_name [CASCADE];<\/p>\n<p><strong> <\/strong><\/p>\n<p><strong>Disabling Constraints<\/strong><\/p>\n<p>ALTER TABLE table_name<\/p>\n<p>DISABLE CONSTRAINT constraint_name [CASCADE];<\/p>\n<p><strong> <\/strong><\/p>\n<p><strong>Enabling Constraints<\/strong><\/p>\n<p>ALTER TABLE table_name<\/p>\n<p>ENABLE CONSTRAINT constraint_name;<\/p>\n<p><strong>NOTE:<\/strong><\/p>\n<p><em>A UNIQUE or PRIMARY KEY index is automatically created if you enable a UNIQUE key or PRIMARY KEY constraint.<\/em><\/p>\n<p><strong> <\/strong><\/p>\n<p><strong>Data Dictionary<\/strong><\/p>\n<p>ALL_CONSTRAINTS\u00a0\u00a0 \u00a0\u00a0\u00a0\u00a0 USER_CONSTRAINTS<\/p>\n<p>ALL_CONS_COLUMNS \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 USER_CONS_COLUMNS<\/p>\n<p><strong> <\/strong><\/p>\n<p><strong>View<\/strong><\/p>\n<p><strong>Creating or Modifying a View<\/strong><\/p>\n<p>CREATE [OR REPLACE] [FORCE|NOFORCE] VIEW view<\/p>\n<p>[(alias[, alias]&#8230;)]<\/p>\n<p>AS subquery<\/p>\n<p>[WITH CHECK OPTION [CONSTRAINT constraint_name]]<\/p>\n<p>[WITH READ ONLY [CONSTRAINT constraint_name]];<\/p>\n<p><strong>Top-N Analysis<\/strong><\/p>\n<p>SELECT [column_list], ROWNUM<\/p>\n<p>FROM \u00a0(SELECT [column_list]<\/p>\n<p>FROM table_name<\/p>\n<p>ORDER BY Top-N_column)<\/p>\n<p>WHERE ROWNUM &lt;= N;<\/p>\n<p><em> <\/em><\/p>\n<p><strong>Removing a View<\/strong><\/p>\n<p>DROP VIEW view;<\/p>\n<p><strong>SEQUENCE<\/strong><\/p>\n<p><strong>CREATE SEQUENCE Statement<\/strong><\/p>\n<p>CREATE SEQUENCE sequence<\/p>\n<p>[INCREMENT BY n]<\/p>\n<p>[START WITH n]<\/p>\n<p>[{MAXVALUE n| NOMAXVALUE}]<\/p>\n<p>[{MINVALUE n| NOMINVALUE}]<\/p>\n<p>[{CYCLE | NOCYCLE}]<\/p>\n<p>[{CACHE [n|20]| NOCACHE}];<\/p>\n<p><strong> <\/strong><\/p>\n<p><strong>Pseudocolumns<\/strong><\/p>\n<p>sequence.NEXTVAL \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 sequence.CURRVAL<\/p>\n<p><strong> <\/strong><\/p>\n<p><strong>Modifying a Sequence (No START WITH option)<\/strong><\/p>\n<p>ALTER SEQUENCE sequence<\/p>\n<p>[INCREMENT BY n]<\/p>\n<p>[{MAXVALUE n| NOMAXVALUE}]<\/p>\n<p>[{MINVALUE n| NOMINVALUE}]<\/p>\n<p>[{CYCLE | NOCYCLE}]<\/p>\n<p>[{CACHE [n|20]| NOCACHE}];<\/p>\n<p><strong> <\/strong><\/p>\n<p><strong>Removing a Sequence<\/strong><\/p>\n<p>DROP SEQUENCE sequence;<\/p>\n<p><strong> <\/strong><\/p>\n<p><strong>Index<\/strong><\/p>\n<p><strong>Creating an Index<\/strong><\/p>\n<p>CREATE INDEX index<\/p>\n<p>ON TABLE (column[,column]&#8230;);<\/p>\n<p><strong> <\/strong><\/p>\n<p><strong>Removing an Index<\/strong><\/p>\n<p>DROP INDEX index;<\/p>\n<p><strong> <\/strong><\/p>\n<p><strong>Synoym<\/strong><\/p>\n<p>CREATE [PUBLIC] SYNONYM synonym<\/p>\n<p>FOR object;<\/p>\n<p><strong>Removing Synonyms<\/strong><\/p>\n<p>DROP SYNONYM synonym;<\/p>\n<p><strong> <\/strong><\/p>\n<p><strong>Data Dictionary<\/strong><\/p>\n<p>ALL_VIEWS \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0 USER_VIEWS<\/p>\n<p>ALL_SEQUENCES \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0 USER_SEQUENCES<\/p>\n<p>ALL_INDEXES \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0 USER_INDEXES<\/p>\n<p>ALL_IND_COLUMNS \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0 USER_IND_COLUMNS<\/p>\n<p><strong> <\/strong><\/p>\n<p><strong>System Privileges (DBA)\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 User System Privileges<\/strong><\/p>\n<p>CREATE USER \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 CREATE SESION<\/p>\n<p>DROP USER \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 CREATE TABLE<\/p>\n<p>DROP ANY TABLE \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 CREATE SEQUENCE<\/p>\n<p>BACKUP ANY TABLE \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 CREATE VIEW<\/p>\n<p>CREATE PROCEDURE<\/p>\n<p><strong>Creating Users<\/strong><\/p>\n<p>CREATE USER user<\/p>\n<p>IDENTIFIED BY password;<\/p>\n<p><strong> <\/strong><\/p>\n<p><strong>Creating Roles<\/strong><\/p>\n<p>CREATE ROLE role;<\/p>\n<p><strong>Granting System Privileges<\/strong><\/p>\n<p>GRANT privelges[,&#8230;] TO user[,&#8230;];<\/p>\n<p>GRANT privelges TO role;<\/p>\n<p>GRANT role TO user[,&#8230;];<\/p>\n<p><strong> <\/strong><\/p>\n<p><strong>Changing Password<\/strong><\/p>\n<p>ALTER USER user IDENTIFIED BY new_password;<\/p>\n<p><strong> <\/strong><\/p>\n<p><strong>Dropping Users<\/strong><\/p>\n<p>DROP USER user [CASCADE];<\/p>\n<p><strong> <\/strong><\/p>\n<p><strong>Dropping Roles<\/strong><\/p>\n<p>DROP ROLE role;<\/p>\n<p><strong> <\/strong><\/p>\n<p><strong>Object Privileges<\/strong><\/p>\n<p>Object \u00a0\u00a0\u00a0\u00a0 Table\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 View\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Sequence\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Procedure<\/p>\n<p>ALTER \u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\u00a0X \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0X<\/p>\n<p>DELETE \u00a0\u00a0\u00a0\u00a0 \u00a0\u00a0X \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0X<\/p>\n<p>EXECUTE \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0X<\/p>\n<p>INDEX \u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\u00a0X<\/p>\n<p>INSERT \u00a0\u00a0\u00a0\u00a0 \u00a0\u00a0X \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0X<\/p>\n<p>REFERENCES \u00a0\u00a0X<\/p>\n<p>SELECT\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0 X \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0X \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0X<\/p>\n<p>UPDATE \u00a0\u00a0\u00a0\u00a0 \u00a0\u00a0X \u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0X<\/p>\n<p><strong> <\/strong><\/p>\n<p><strong>Object Privileges<\/strong><\/p>\n<p>GRAND object_priv [(column)]<\/p>\n<p>ON object<\/p>\n<p>TO {user|role|PUBLIC}<\/p>\n<p>[WITH GRANT OPTION];<\/p>\n<p><strong> <\/strong><\/p>\n<p><strong>Revoking Object Privileges<\/strong><\/p>\n<p>REVOKE {privilege [,privilege&#8230;] | ALL}<\/p>\n<p>ON object<\/p>\n<p>FROM {user[,user&#8230;]|role|PUBLIC}<\/p>\n<p>[CASCADE CONSTRAINTS];<\/p>\n<p><strong> <\/strong><\/p>\n<p><strong>Data Dictionary<\/strong><\/p>\n<p>ROLE_SYS_PRIVS<\/p>\n<p>ROLE_TAB_PRIVS \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 USER_ROLE_PRIVS<\/p>\n<p>USER_TAB_PRIVS_MADE \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 USER_TAB_PRIVS_RECD<\/p>\n<p>USER_COL_PRIVS_MADE \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 USER_COL_PRIVS_RECD<\/p>\n<p><strong> <\/strong><\/p>\n<p><strong>Database Links<\/strong><\/p>\n<p>CREATE [PUBLIC] DATABASE LINK link_name<\/p>\n<p>[CONNECT TO user_name IDENTIFIED BY password]<\/p>\n<p>USING connection_string;<\/p>\n<p><strong> <\/strong><\/p>\n<p><strong>Single-Row Functions<\/strong><\/p>\n<p><strong>Character Functions<\/strong><\/p>\n<p>LOWER(column|expression)<\/p>\n<p>UPPER(column|expression)<\/p>\n<p>INITCAP(column|expression)<\/p>\n<p>INSTR(column|expression,m)<\/p>\n<p>CONCAT(column1|expression1,column2|expression2}<\/p>\n<p>SUBSTR(column|expression,m,[n])<\/p>\n<p>LENGTH(column|expression)<\/p>\n<p>LPAD(column|expression,n,&#8217;string&#8217;)<\/p>\n<p>RPAD(column|expression,n,&#8217;string&#8217;)<\/p>\n<p>TRIM(&#8216;character&#8217; FROM column|expression)<\/p>\n<p>REPLACE(&#8216;string1&#8217;, &#8216;string_to_replace&#8217;,[replacement_string])<\/p>\n<p><strong> <\/strong><\/p>\n<p><strong>Number Functions<\/strong><\/p>\n<p>MOD(m,n)<\/p>\n<p>ROUND(column|expression,n)<\/p>\n<p>TRUNC(column|expression,n)<\/p>\n<p><strong> <\/strong><\/p>\n<p><strong>Date Functions<\/strong><\/p>\n<p>MONTHS_BETWEEN(date1,date2)<\/p>\n<p>ADD_MONTHS(date,n)<\/p>\n<p>NEXT_DAY(date,&#8217;char&#8217;)<\/p>\n<p>LAST_DAY(date)<\/p>\n<p>ROUND(date[,&#8217;fmt&#8217;])<\/p>\n<p>TRUNC(date[,&#8217;fmt&#8217;])<\/p>\n<p><em>Arithmetic with Dates<\/em><\/p>\n<ul type=\"disc\">\n<li>Add or subtract a number to or from a date for a resultant date value<\/li>\n<li>Subtract two dates to find the number of days between those dates<\/li>\n<li>Add hours to a date by dividing the number of hours by 24<\/li>\n<\/ul>\n<p><strong> <\/strong><\/p>\n<p><strong>Conversion Functions<\/strong><\/p>\n<p>TO_CHAR(number|date[,&#8217;fmt&#8217;])<\/p>\n<p>TO_NUMBER(char[,&#8217;fmt&#8217;])<\/p>\n<p>TO_DATE(char[,&#8217;fmt&#8217;])<\/p>\n<p>NVL(expr1,expr2)<\/p>\n<p>NVL2(expr1,expr2,expr3)<\/p>\n<p>NULLIF(expr1,expr2)<\/p>\n<p>COALESCE(expr1,expr2,&#8230;,exprn)<\/p>\n<p><strong>Conditional Expressions: <\/strong>Provide the use of IF-THEN-ELSE logic within a SQL statement.<\/p>\n<p>DECODE(col|expr,search1,result1<\/p>\n<p>[,search2,result2,&#8230;,]<\/p>\n<p>[,default])<\/p>\n<p>CASE expr WHEN comparision_expr1 THEN return_expr1<\/p>\n<p>[WHEN comparision_expr2 THEN return_expr2<\/p>\n<p>WHEN comparision_exprn THEN return_exprn<\/p>\n<p>ELSE else_expr]<\/p>\n<p>END<\/p>\n<p><em>Nesting Functions<\/em><\/p>\n<ul>\n<li>Single-row functions can be nested to any level<\/li>\n<li>Nested functions are evaluated from deepest level to the least deep level<\/li>\n<li>In below example, functions F1, F2 and then F3 gets executed<\/li>\n<\/ul>\n<p>F3(F2(F1(col,arg1),arg2),arg3)<\/p>\n<p><strong>Operators<\/strong><\/p>\n<p>Arithmetic \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 *\u00a0\u00a0\u00a0\u00a0 \/\u00a0\u00a0\u00a0\u00a0 +\u00a0\u00a0\u00a0\u00a0 &#8211;<\/p>\n<p>Comparison \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = \u00a0\u00a0\u00a0 &gt; \u00a0\u00a0\u00a0 &gt;= \u00a0\u00a0 &lt; \u00a0\u00a0\u00a0 &lt;= \u00a0\u00a0 &lt;&gt; or ^= or ~= or !=<\/p>\n<p>BETWEEN&#8230;AND&#8230;, IN(set), LIKE, IS NULL<\/p>\n<p>Concatenation\u00a0\u00a0\u00a0\u00a0 ||<\/p>\n<p>Logical \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 AND \u00a0 OR \u00a0\u00a0 NOT<\/p>\n<p><strong>Rules of Precedence<\/strong><\/p>\n<p>Order Evaluated \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Operator<\/p>\n<ul>\n<li>1 Arithmetic operators &#8211; multiplication and division(* \/)<\/li>\n<li>2 Arithmetic operators &#8211; Addition, subtraction and Concatenation operator ( + &#8211; || )<\/li>\n<li>3 Comparison conditions<\/li>\n<li>4 IS [NOT] NULL, LIKE, [NOT] IN<\/li>\n<li>5 [NOT] BETWEEN<\/li>\n<li>6 NOT logical condition; ** Exponentiation<\/li>\n<li>7 AND logical condition<\/li>\n<li>8 OR logical condition<\/li>\n<\/ul>\n<p><strong>Notes<\/strong><\/p>\n<ul>\n<li>1) Use <strong>ESCAPE<\/strong> identifier to search for the actual % and _ symbols (Here, % denotes zero or many characters and _ denotes one character in search condition )<\/li>\n<\/ul>\n<p>Example: Get employee list having underscore (_) in last_name string<\/p>\n<p>SELECT last_name<\/p>\n<p>FROM EMPLOYEE<\/p>\n<p>WHERE last_name LIKE &#8216;%_%&#8217; ESCAPE &#8221;;<\/p>\n<ul>\n<li>2) <strong>DUAL<\/strong> is a dummy table you can use to view results from functions and calculations<\/li>\n<li>3) <strong>SYSDATE<\/strong> is a function that returns: Date and Time<\/li>\n<li>4) Inline view is a subquery with an alias that you can use within a SQL statement. A named subquery in the FROM clause of the main query is an example of an inline view. It is not a schema object.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Oracle SQL Quick Reference SELECT Query Statement SELECT [DISTINCT] {*, column [alias],&#8230;} FROM table WHERE condition(s)] ORDER BY {column, exp, alias} [ASC|DESC]] NOTE: Avoid using DISTINCT with large table as it first does sorting of all the rows and then eliminates duplicate rows, so need a full table scan and thus it&#8217;s very slow. ORDER [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[4,15],"tags":[54,72,196,107,111,119,128,132,135,140],"class_list":["post-182","post","type-post","status-publish","format-standard","hentry","category-oracle","category-oracle-sql","tag-commands","tag-guide","tag-oracle","tag-plsql","tag-quick-reference","tag-reference","tag-sql","tag-sqlplus","tag-syntax","tag-tutorial"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.oratraining.com\/blog\/wp-json\/wp\/v2\/posts\/182","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.oratraining.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.oratraining.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.oratraining.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.oratraining.com\/blog\/wp-json\/wp\/v2\/comments?post=182"}],"version-history":[{"count":0,"href":"https:\/\/www.oratraining.com\/blog\/wp-json\/wp\/v2\/posts\/182\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.oratraining.com\/blog\/wp-json\/wp\/v2\/media?parent=182"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.oratraining.com\/blog\/wp-json\/wp\/v2\/categories?post=182"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.oratraining.com\/blog\/wp-json\/wp\/v2\/tags?post=182"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}