Posts

Showing posts from January, 2013

Collections in Oracle PL/SQL

Oracle uses collections in PL/SQL the same way other languages use arrays. Oracle provides three basic collections, each with an assortment of methods. Index-By Tables (Associative Arrays) Nested Table Varrays Collection Methods Multiset Operations Multidimensional Collections Related articles. Associative Arrays in Oracle 9i Bulk Binds (BULK COLLECT & FORALL) and Record Processing in Oracle Index-By Tables (Associative Arrays) The first type of collection is known as index-by tables. These behave in the same way as arrays except that have no upper bounds, allowing them to constantly extend. As the name implies, the collection is indexed using  BINARY_INTEGER  values, which do not need to be consecutive. The collection is extended by assigning values to an element using an index value that does not currently exist. SET SERVEROUTPUT ON SIZE 1000000 DECLARE TYPE table_type IS TABLE OF NUMBER(10) INDEX BY BINARY_INTEGER; v_tab table_type; v_idx NU

Database Triggers Overview

The  CREATE TRIGGER  statement has a lot of permutations, but the vast majority of the questions I'm asked relate to basic DML triggers. Of those, the majority are related to people misunderstanding the order of the timing points and how they are affected by bulk-bind operations and exceptions. This article represents the bare minimum you should understand about triggers before you consider writing one. DML Triggers The Basics Timing Points Bulk Binds How Exceptions Affect Timing Points Mutating Table Exceptions Compound Triggers Should you use triggers at all? (Facts, Thoughts and Opinions) Non-DML (Event) Triggers Enabling/Disabling Triggers Related articles. Mutating Table Exceptions Trigger Enhancements in Oracle Database 11g Release 1 Cross-Edition Triggers: Edition-Based Redefinition in Oracle Database 11g Release 2 DML Triggers The Basics For a full syntax description of the  CREATE TRIGGER  statement, check out the documentation shown  here .

Autonomous Transactions

Autonomous transactions allow you to leave the context of the calling transaction, perform an independant transaction, and return to the calling transaction without affecting it's state. The autonomous transaction has no link to the calling transaction, so only commited data can be shared by both transactions. The following types of PL/SQL blocks can be defined as autonomous transactions: Stored procedures and functions. Local procedures and functions defined in a PL/SQL declaration block. Packaged procedures and functions. Type methods. Top-level anonymous blocks. The easiest way to understand autonomous transactions is to see them in action. To do this, we create a test table and populate it with two rows. Notice that the data is not commited. CREATE TABLE at_test ( id NUMBER NOT NULL, description VARCHAR2(50) NOT NULL ); INSERT INTO at_test (id, description) VALUES (1, 'Description for 1'); INSERT INTO at_test (id, description) VALUES

Inventory Transactions Useful Information

/*In oracle Applications, the hierarchy of org's is given below.      Set of Books => Legal Entities => Operating Units => Inventory Organization.      The Set of Books is defined in the General Ledger application setups, Legal Entity    is defined in the HR while the Operating Units and Inventory Organization    (organization) are defined in the Inventory App.      In Inventory, the items are stored in different subinventories, locations etc.    We can find what are all the subinventories that are available in the systems.    Generally we define subinventories corresponding to an inventory organization    and one inventory organization will have several subinventories associated    with it.(setup=>subinventories) */   SELECT secondary_inventory_name,description, organization_id,location_id ,a.* FROM   mtl_secondary_inventories a WHERE  secondary_inventory_name LIKE 'MY%'   --select * from mtl_physical_inventories , mtl_physical_subinventori