Archive for the ‘Oracle SQL’ Category

SQL optimization using Oracle Hints

ORACLE HINT REFERENCE       PARALLEL Scanning full table with parallel degree of 8. Parallel always assumes full table scan. SELECT /*+ FULL(hr_emp) PARALLEL(hr_emp, 8 ) */ last_name FROM employees hr_emp;   PARALLEL_INDEX The PARALLEL_INDEX hint instructs the optimizer to use the specified number of concurrent servers to parallelize index range scans for partitioned [...]

Continue reading »

Finding time for Specific SCN

  SELECT CURRENT_SCN FROM V$DATABASE; To get the current SCN SELECT DBMS_FLASHBACK.GET_SYSTEM_CHANGE_NUMBER FROM DUAL 1.1 ORA_ROWSCN Is a pseudocolumn of any table that is not fixed or external. It represents the SCN of the most recent change to a given row, that is, the latest COMMIT operation for the row. For example: SELECT ora_rowscn, last_name, [...]

Continue reading »

Custom Script to Identify Invalid Packages

Identifying Invalid Objects SELECT owner, object_type, object_name, status FROM dba_objects WHERE status = ‘INVALID’ ORDER BY owner, object_type, object_name; Manual Approach ALTER PACKAGE my_package COMPILE; ALTER PACKAGE my_package COMPILE BODY; ALTER PROCEDURE my_procedure COMPILE; ALTER FUNCTION my_function COMPILE; ALTER TRIGGER my_trigger COMPILE; ALTER VIEW my_view COMPILE; DBMS_DDL EXEC DBMS_DDL.alter_compile(‘PACKAGE’, ‘MY_SCHEMA’, ‘MY_PACKAGE’); EXEC DBMS_DDL.alter_compile(‘PACKAGE BODY’,’MY_SCHEMA’,’MY_PACKAGE’); EXEC [...]

Continue reading »

String Functions:INSTR,SUBSTR, REPLACE,TRANSLATE

Built-in functions/operators available for manipulating Strings The most useful ones are LENGTH, SUBSTR, INSTR, and ||: LENGTH(str) returns the length of str in characters. SUBSTR(str,m,n) returns a portion of str, beginning at character m, n characters long. If n is omitted, all characters to the end of str will be returned. INSTR(str1,str2,n,m) searches str1 beginning [...]

Continue reading »

Constraints

Several types of Oracle constraints can be applied to Oracle tables to enforce data integrity, including: Oracle "Check" Constraint: This constraint validates incoming columns at row insert time. For example, rather than having an application verify that all occurrences of region are North, South, East, or West, an Oracle check constraint can be added to [...]

Continue reading »

SQL CASE Statement

he syntax for the case statement is: CASE  [ expression ]   WHEN condition_1 THEN result_1   WHEN condition_2 THEN result_2   …   WHEN condition_n THEN result_n   ELSE result END expression is optional. It is the value that you are comparing to the list of conditions. (ie: condition_1, condition_2, … condition_n)   select [...]

Continue reading »

Managing Tables

Creating a Table The CREATE TABLE command is used to create relational tables or object tables. Relational table: This is the basic structure to hold user data. Object table: Is a table that uses an object type for a column definition. An object table is a table that is explicitly defined to hold the object [...]

Continue reading »

Recursive Calls

Recursive calls is a call(sql statement) that must be completed before the completion of user’s SQL statement. Basically, recursive calls are generated by Oracle internal sql statements to maintain changes to tables for internal processing. Reasons for Recursive Calls Recursive calls can be generated due to following reasons: Dictionary cache is too small resulting in [...]

Continue reading »

Oracle SQL Execution Steps

All Oracle SQL statements must be processed the first time that they execute (unless they are cached in the library cache). and SQL execution steps include: A syntax check – Are all keywords present "select . . . from", etc . . A semantic check against the dictionary – Are all table names spelled correctly, [...]

Continue reading »

Follow

Get every new post delivered to your Inbox.