You are on page 1of 7

Bulk collect Bulk collect is used to fetch bulk records from oracle table. It used to improve the performance.

When we use bulk collect, the PLSQL engine tells SQL engine to retrieve data at once. By using context switches SQL engine gives datas to PLSQL engine. By the way the retrieval of records is increased. To fetch limited number of records, we should use Limit key word in fetch statement. To insert fetched data into PLSQL table we use FORALL..SAVE EXCEPTION keyword. SAVE EXCEPTION used to stored errors. To find total errors: SQL%BULK_EXCEPTIONS.COUNT To find place where error occurred: SQL%BULK_EXCEPTIONS(i).ERROR_INDEX To find error number: SQL%BULK_EXCEPTIONS(i).ERROR_CODE Ref_Cursor A REF CURSOR is a data type which used to store a result of a query. We can call multiple select queries in a ref cursor. So its also called as dynamic cursor. Normally we pass ref cursor as out parameter in a procedure or function. We define refcursor as out parameter as sys_refcursor. While define as bind variable we declare as refcursor. There are two types of refcursor; Week refcursor Strong refcursor Week refcursor used to store result of a query alone. Strong refcursor can used to store query result and can return it. Strong Ref cursor: CREATE OR REPLACE PACKAGE PKG AS TYPE TNAME IS REF CURSOR RETURN DEPARTMENTS%ROWTYPE; END PKG; / Advantages of packages Package is used for over loading. When we use multiple procedures in a same name is called over loading. Server read whole packages to memory at once. It increases the performance. Once we execute Packages data are retrieved from oracle memory and save it in shared pool area. After that data are retrieved from pool area. By the way we can improve performance of data retrieval. We can use global variable, cursors and user defined exceptions in package specifications. Pragma Autonomous_Transaction PRAGMA's are directives for the Oracle PL/SQL compiler. It is a independent transaction. Pragma Autonomous_Transaction instructs the compiler to treat the following PLSQL block as autonomous (independent) from whatever transaction calls it. If any changes made to the database in the autonomous transaction are independent of the main transaction and are either committed or rolled back without affecting the main transaction. Pragma Exception_Init If we know oracle error number and dont know error message, we can create our own valid error message with help of Pragma Exception_Init Difference between Cursor and Ref_Cursor

S.No 1 2 3 4 5. 6 7 8 9

CURSORS It is SQL private work area We cannot print directly It has attributes We cannot pass a cursor as an argument It uses open and close keywords It has two types Implicit, Explicit It is static cursor Implicit cursor declared by oracle itself It should be assigned to another variable

REFCURSOR It is a data type We can print directly It doesnt have attributes We can pass a refcursor as an argument It uses only open keywords It has only one type It is dynamic cursor We externally need to declare refcursor No need of assigning to another variable

Materialized View It is a database object which used to store a query result in a variable. Usually it used to generate a snap shot for a remote database. Without primary key constraint we cannot create Mview It has 3 types Materialized view with aggregates Materialized view contain only Joins Nested materialized view Create materialized view log on T1; It is created for using refresh fast method. CREATE MATERIALIZED VIEW MV1 REFRESH FORCE AS SELECT * FROM S1; On demand: EXEC DBMS_MVIEW.REFRESH (MV1) It s used to refresh the Mview, When any insert operation in Base Table. For update It is used to do Insert Operation in materialized view. Refresh type 1. Refresh fast 2. Refresh force 3. Refresh complete 4. Never Refresh modes Refresh on commit When Mviews created by joins we go for refresh on commit mode Refresh on demand

Difference between Procedure and Function S.No PROCEDURES FUNCTIONS 1 2 3 4 5 6 It used to perform a repeated action It can accept arguments and can return value We cannot call a procedure in SQL statement Normally used for execute business logic It is pre-compiled execution plan We can use EXEC command to run a procedure It used to compute values It can accept argument and must return value We can call a function in SQL statement Normally used for computations It is not pre-compiled execution plan We cannot use EXEC command to run a function

Cursors Cursor is a SQL private work area used to fetch a data from table. It opens an area in oracle memory when we define a cursor. We define a cursor in declaration part and execute in side body. We have to explicitly close a cursor inside a PLSQL block Two types: Implicit / Explicit Implicit: When we call SQL statements it automatically declared. Explicit: It is user defined cursor to return more number of values There are 4 attributes called FOUND, NOT FOUND, IS NULL, ROWCOUNT SQL loader SQL*Loader loads data from external files into tables of an Oracle database. It has a powerful data parsing engine that puts little limitation on the format of the data in the data file. You can use SQL*Loader to do the following: Load data across a network. This means that you can run the SQL*Loader client on a different system from the one that is running the SQL*Loader server. Load data from multiple data files during the same load session. Load data into multiple tables during the same load session. Specify the character set of the data. Selectively load data (you can load records based on the records' values). Manipulate the data before loading it, using SQL functions. Generate unique sequential key values in specified columns. Use the operating system's file system to access the data files Load data from disk, tape, or named pipe. Generate sophisticated error reports, which greatly aid troubleshooting. Load arbitrarily complex object-relational data. Use secondary data files for loading LOBs and collections.

Collections A collection is an ordered group of elements, all of the same type. It is a general concept that encompasses lists, arrays, and other familiar datatypes. Each element has a unique subscript that determines its position in the collection. PL/SQL offers these collection types: Index-by tables, also known as associative arrays, let you look up elements using arbitrary numbers and strings for subscript values. (They are similar to hash tables in other programming languages.) Nested tables hold an arbitrary number of elements. They use sequential numbers as subscripts. You can define equivalent SQL types, allowing nested tables to be stored in database tables and manipulated through SQL. Varrays (short for variable-size arrays) hold a fixed number of elements (although you can change the number of elements at runtime). They use sequential numbers as subscripts. You can define equivalent SQL types, allowing varrays to be stored in database tables. They can be stored and retrieved through SQL, but with less flexibility than nested tables. Although collections can have only one dimension, you can model multi-dimensional arrays by creating collections whose elements are also collections. To use collections in an application, you define one or more PL/SQL types, then define variables of those types. You can define collection types in a procedure, function, or package. You can pass collection variables as parameters, to move data between client-side applications and stored subprograms. To look up data that is more complex than single values, you can store PL/SQL records or SQL object types in collections. Nested tables and Varrays can also be attributes of object types. PL/SQL Table When we need to save multiple records with same data type in a single variable we can use PL/SQL collections. Here PL/SQL TABLE is one type of collection. This doesnt have limit. We can save unlimited records in PL/SQL table. Its also called as associative array or Table or index_by_table. Varray Varray is another type of PLSQL collection, which used to store multiple records with same data types in a variable. This accepts limited number of records. When we define varray, we should define limit of records. SQL query tuning Query rewrite Index for null columns Hints Explain plan Mviews Global temporary table Analytical functions Use with clause Never do calculation on indexed column

DBMS_Profiler This is a built-in package which allows us to turn on execution profiling in a session. When we run a code, oracle uses tables to keep track of detailed information about how long each line in the code took execute. Then we can run queries on these tables or much preferred use screens in products like TOAD or SQL navigator to present the data in a clear, graphical fashion. To start profiler: DBMS_PROFILER. START_PROFILER To stop profiler: DBMS_PROFILER.STOP_PROFILER To find the result of analysis, PLSQL_PROFILER_DATA PLSQL_PROFILER_RUNS PLSQL_PROFILER_UNITS DBMS_TRACE PLSQL_TRCAE_RUNS PLSQL_TRCAE_EVENTS PLSQL_TRCAE_RUNNUMBER DBMS_UTILITY.GET_TIME This is built in packages which used to calculate the elapsed time of our code down to the hundredth of a second. The scripts offer an interface to the function that allows us to use timers (Based on DBMS_UTILITY.GET_TIME) in your code. Execute Immediate It is dynamic SQL used to execute DDL statement in PLSQL block. UTL_MAIL It is a Utility which is used to send a mail from oracle to any user. UTL_SMTP Same like as UTL_MAIL which was used in previous versions then UTL_MAIL. External Tables Import IMP Export EXP DATAPUMP External tables External tables are created using the SQL CREATE TABLE...ORGANIZATION EXTERNAL statement. When you create an external table, you specify the following attributes: TYPE - specifies the type of external table. The two available types are the ORACLE_LOADER type and the ORACLE_DATAPUMP type. Each type of external table is supported by its own access driver. The ORACLE_LOADER access driver is the default. It can perform only data loads, and the data must come from text data files. Loads from external tables to internal tables are done by reading from the external tables' text-only data files. The ORACLE_DATAPUMP access driver can perform both loads and unloads. The data must come from binary dump files. Loads to internal tables from external tables are done by fetching from the binary dump files. Unloads from internal tables to external tables are done by populating the external tables' binary dump files. DEFAULT DIRECTORY - specifies the default location of files that are read or written by external tables. The location is specified with a directory object, not a directory path. See Location of Datafiles and Output Files for more information.

ACCESS PARAMETERS - describe the external data source and implements the type of external table that was specified. Each type of external table has its own access driver that provides access parameters unique to that type of external table. See Access Parameters. LOCATION - specifies the location of the external data. The location is specified as a list of directory objects and filenames. If the directory object is not specified, then the default directory object is used as the file location. Hints Indexes Triggers UTL_FILE DBMS_SQL Explain plan/Execution Plan Analytical Function With clause Difference between 10g and 11g Regular Expression Function Reverse Key Index Cluster / non cluster index Table Partition Global Temporary Table Views and MViews Joins V$SQL V$SQLtext V$SQL plan DBMS_DDL DBMS_DEBUG Difference between analytical function and aggregate function Parallel hints and Ordered Hints Nested Loops Hash join Sort merge join For all .Save Exception SQL loader Conventional path & Direct Path Pseudo Columns Dbms_trace Dbms_utility AWR TKprof Table normalization Table hierarchy Different between 2 tier and 3 tier application Modes of SQL loader Types of refresh in Mviews 1) Complete 2) Fast 3) Force 4) Never Modes of refresh in Mviews 1) On commit 2) On demand

You might also like