Create Temporary Table in Oracle

To create a table named test with column col1 type varchar2 length 10, col2 type number. col3 type clob we can use CREATE TABLE statement as,
CREATE TABLE TEST(col1 VARCHAR2(10), col2 NUMBER, col3 CLOB);
Now if I insert data into the table the data is visible and accessible to all users. In many cases it is needed the data inside a table will be reside temporarily. In that case we can use temporary tables. Temporary tables are useful in applications where a result set is to be buffered. To create temporary table we have to issue CREATE GLOBAL TEMPORARY clause.
Temporary table can be of two types based on ON COMMIT clause settings.
1)ON COMMIT DELETE ROWS specifies temporary table would be transaction specific. Data persist within table up to transaction ending time. If you end the transaction the database truncates the table (delete all rows). Suppose if you issue commit or run ddl then data inside the temporary table will be lost. It is by default option.
Example:
(i)This statement creates a temporary table that is transaction specific:
CREATE GLOBAL TEMPORARY TABLE test_temp(col1 number, col2 number) ON COMMIT DELETE ROWS;
Table created.
(ii)Insert row in to the temporary table.
insert into test_temp values(3,7);
1 row created.
(iii)Look at the data in the table.
select * from test_temp;
COL1 COL2
———- ———-
3 7
(iv)Issue Commit.
commit;
Commit complete.
(v)Now look at the data in the temporary table. As I created transaction specific temporary table(on commit delete rows) so data is lost after commit.
SQL> select * from test_temp;
no rows selected
2)ON COMMIT PRESERVE ROWS specifies temporary table would be session specific. Data persist within table up to session ending time. If you end the session the database truncates the table (delete all rows). Suppose you type exit in SQL*Plus then data inside the temporary table will be lost.
Example of Session Specific Temporary Tables:
1)Create Session Specific Temporary Table test_temp2.
CREATE GLOBAL TEMPORARY TABLE test_temp2 (col1 number, col2 number)
ON COMMIT PRESERVE ROWS;
(ii)Insert data into it and look at data both before commit and after commit.
insert into test_temp2 values(3,7);
1 row created.
SQL>select * from test_temp2;
COL1 COL2
———- ———-
3 7
(iii) commit;
Commit Complete
(iv)select * from test_temp2;
COL1 COL2
———- ———-
3 7

(iv)End the Session.
exit;


Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 – Production
With the Partitioning, OLAP and Data Mining options
(v)Connect in a new session and look at data again.
$ sqlplus apps/[email protected]
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 – Production
With the Partitioning, OLAP and Data Mining options

SQL> select * from test_temp2;
no rows selected

This is how Global Temporary Tables are used.
Feature of Temporary Table
1.Indexes can be created on temporary tables. They are also temporary and the data in the index has the same session or transaction scope as the data in the underlying table.
2.Unlike permanent tables, temporary tables and their indexes do not automatically allocate a segment when they are created. Instead, segments are allocated when the first INSERT (or CREATE TABLE AS SELECT) is performed. This means that if a SELECT, UPDATE, or DELETE is performed before the first INSERT, the table appears to be empty.
3.DDL operations (except TRUNCATE) are allowed on an existing temporary table only if no session is currently bound to that temporary table.
4.If you rollback a transaction, the data you entered is lost, although the table definition persists.
5.A transaction-specific temporary table allows only one transaction at a time. If there are several autonomous transactions in a single transaction scope, each autonomous transaction can use the table only as soon as the previous one commits.
6.Because the data in a temporary table is, by definition, temporary, backup and recovery of temporary table data is not available in the event of a system failure.
7.It is good to know about that temporary table itself is not temporary, the data within it is temporary.
Restriction of Temporary Table
1.Temporary tables cannot be partitioned, clustered, or index organized.
2.You cannot specify any foreign key constraints on temporary tables.
3.Temporary tables cannot contain columns of nested table.
4.You cannot specify the following clauses of the LOB_storage_clause: TABLESPACE, storage_clause, or logging_clause.
5.Parallel DML and parallel queries are not supported for temporary tables. Parallel hints are ignored. Specification of the parallel_clause returns an error.
6.You cannot specify the segment_attributes_clause, nested_table_col_properties, or parallel_clause.
7.Distributed transactions are not supported for temporary tables.

About Hierarchical Trees
The hierarchical tree displays data in the form of a standard navigator.
We can populate a hierarchical tree with values contained in a Record Group or Query Text.
At runtime, you can programmatically add, remove, modify, or evaluate elements in a hierarchical tree.
The amount of data displayed at any one time depends upon the expansion of individual data nodes.
Triggers
Following Triggers are Provided by Form Builder exclusively for hierarchical tree Items.
1.       When-Tree-Node-Activated
2.       When-Tree-Node-Expanded
3.       When-Tree-Node-Selected
Built-ins
Following built-in subprograms are used to add, remove, modify, or evaluate elements in a hierarchical tree Items.
All built-ins are located in the FTREE built-in package.
1.       Add_Tree_Data
2.       Add_Tree_Node
3.       Delete_Tree_Node
4.       Find_Tree_Node
5.       Get_Tree_Node_Parent
6.       Get_Tree_Selection
7.       Populate_Group_From_Tree
8.       Populate_Tree
9.       Set_Tree_Selection
Now, we will see, how to Develop a form Using Hierarchical Tree Item for Oracle Application.
Objectives :
1.       Create the Hierarchical Tree Item in a Non-Database Block.
2.       Populate the Data to the Hierarchical Tree Item Using Record Group at Runtime.
3.       Create a Database Block to Display the Data(s) based on the Element Navigating on the Hierarchical Tree Item.
Database Objects Required to Develop this Form :
 
Find the Attachment contains the Script to Create Database Objects & Sample Data’s to be Inserted.
In the Canvas Tool Palette we can I find the Hierarchical Tree.
Note : Hierarchical Tree Item Should be in a separate Block as a Individual Item.
There are 2 ways to populate a hierarchical tree :
1.       Record Group
2.       Query Text
The record Group query should be in the specified structure., which requires 5 Columns.
SELECT STATUS, LEVEL, LABEL, ICON, VALUE FROM TABLE;
STATUS à Indicates the initiate status of the Node (Normally Value is 1).
LEVEL  à This is a specific pseudo-column Derived from “CONNECT BY”.
LABEL  à This is the visible label of the Node.
ICON   à That contains the icon name of the Node (can be NULL).
VALUE  à That contains the value of the Node.
Below is the Query used in the Record Group to Populate the Data in the Hierarchical Tree Item.
SELECT 1, LEVEL, ENAME, NULL, TO_CHAR(EMPNO) APPS.EMP CONNECT BY PRIOR EMP.EMPNO = EMP.MGR;
Object Navigator :
 
 
Canvas Design :
 
 
At Run Time :

Kindly have a look on the Below Triggers :

1. WHEN-NEW-FORM-INSTANCE (Form Level)
2. WHEN-TREE-NODE-SELECTED (Item Level)

I hope this will be Useful for custom Developments.

This is our requirement.

SCHEMA NAME : XXCUST
TOP NAME : XXCUST_TOP
Application : XXCUST Custom Application
Data Group : Standard
Request Group : XXCUST Request Group
Menu : XXCUST_CUSTOM_MENU
Responsibility : XXCUST Custom

Assumptions:
APPL_TOP: /d01/oracle/VIS/apps/apps_st/appl
Instance Name: VIS
Server OS: linux

There are 14 simple steps to achieve this.
1) Make the directory structure for your custom application files.
cd $APPL_TOP
mkdir XXCUST
mkdir XXCUST/12.0.0
mkdir XXCUST/12.0.0/admin
mkdir XXCUST/12.0.0/admin/sql
mkdir XXCUST/12.0.0/admin/odf
mkdir XXCUST/12.0.0/sql
mkdir XXCUST/12.0.0/bin
mkdir XXCUST/12.0.0/reports
mkdir XXCUST/12.0.0/reports/US
mkdir XXCUST/12.0.0/forms
mkdir XXCUST/12.0.0/forms/US
mkdir XXCUST/12.0.0/lib
mkdir XXCUST/12.0.0/out
mkdir XXCUST/12.0.0/log

2) Add the custom module into the environment
cd $APPL_TOP
echo “XXCUST_TOP=/d01/oracle/VIS/apps/apps_st/appl/XXCUST/12.0.0” >customVIS_linux.env
echo “export XXCUST_TOP ” >> customVIS_linux.env
Source the environment file (/d01/oracle/VIS/apps/apps_st/appl/APPSVIS_linux.env )
Make entry to the application context file
vi $INST_TOP/appl/admin/VIS_linux.xml
/d01/oracle/VIS/apps/apps_st/appl/XXCUST/12.0.0
cd $INST_TOP/admin/install
sh adgentopfile.sh

3) create tablespace XXCUST datafile ‘/d01/oracle/VIS/db/apps_st/data/XXCUST01.dbf’
size 500M

4) create user XXCUST identified by XXCUST
default tablespace XXCUST
temporary tablespace temp
quota unlimited on XXCUST;
grant connect, resource to XXCUST;

5) Register your Oracle Schema.
Login to Applications with System Administrator responsibility
Navigate to Application–>Register
Application = XXCUST Custom Application
Short Name = XXCUST
Basepath = XXCUST_TOP
Description = XXCUST Custom Application

6) Register Oracle User
Naviate to Security–>Oracle–>Register
Database User Name = XXCUST
Password = XXCUST
Privilege = Enabled
Install Group = 0
Description = XXCUST Custom Application User

7) Add Application to a Data Group
Navigate to Security–>Oracle–>DataGroup

8) Create custom request group
This will act as a placeholder for any custom reports we wish to make available for the Custom Responsibility (which is defined at a later stage)
Navigate to Security–>responsibility–>Request
Group = XXCUST Request Group
Application = XXCUST Custom
Code = XXCUST
Description = XXCUST Custom Requests
At this statge, We are not going to define any requests, but you can add request in the later point of time if its required.

9) Create custom menu
This will act as a placeholder for any menu items we wish to make available for the Custom Responsibility (which is defined at a later stage).
Navigate to Application–>Menu
Menu = XXCUST_CUSTOM_MENU
User Menu Name = XXCUST Custom Application Menu
Menu Type =
Description = XXCUST Custom Application Menu
Seq = 100
Prompt = View Requests
Submenu =
Function = View All Concurrent Requests
Description = View Requests
Seq = 110
Prompt = Run Requests
Submenu =
Function = Requests: Submit
Description = Submit Requests
10) Create new responsibility. Navigate to Security–>Responsibility–>Define

Responsibility Name = XXCUST Custom
Application = XXCUST Custom
Responsibility Key = XXCUSTRESP
Description = XXCUST Custom Responsibility
Available From = Oracle Applications
Data Group Name = Standard
Data Group Application = XXCUST Custom Application
Menu = XXCUST Custom Application Menu
Request Group Name = XXCUST Request Group
11) Add responsibility to user
Navigate to Security–>User–>Define
Add XXCUST Custom responsibility to users as required.

12) Other considerations
You are now ready to create your database Objects, custom Reports, Forms, Packages, etc
Create the source code files in the XXCUST_TOP directory appropriate for the type of object. For example forms would be located in $XXCUST_TOP/forms/US or
package source code in $XXCUST_TOP/admin/sql for example.
Database Objects, such as tables, indexes and sequences should be created in the XXCUST schema, and then you need to
   a) Grant all privilege from each custom data object to the APPS schema.
      For example : logged in as XXCUST user
      grant all privileges on XX_TABLE to apps;
   b) Create a synonym in APPS for each custom data object
      For example : logged in as APPS user
      create synonym XX_TABLE for XXCUST.XX_TABLE;

13) Login to sysadmin, Application Developer Responsibility
In the backend compile your form
su – applmgr
cd $AU_TOP/forms/US
cp TEMPLATE.fmb XXSAMPLE.fmb
frmcmp_batch Userid=apps/apps module=XXSAMPLE.fmb output_file=/d01/oracle/VIS/apps/apps_st/appl/XXCUST/12.0.0/forms/US/XXSAMPLE.fmx compile_all=special  batch=yes
Application > Form (Register the form)
Application > Menu (Attach the function to a menu)
Open new session, source environment file, and stop middle tier services, run autoconfig
Open new session, source environment file, check for custom top in topfile.txt in $APPL_TOP/admin, start the middle tier services.
   cd $ADMIN_SCRIPTS_HOME
   sh adstpall.sh apps/apps
   sh adautocfg.sh
   sh adstrtal.sh apps/apps
   cat $APPL_TOP/admin/topfile.txt
   You can find the entry as lke this, XXCUST /d01/oracle/VIS/apps/apps_st/appl
14) Menu that is added to a particular responsibility is given to specific user
Security > User >
Attach our custom responsibility to the user.
Common Errors and Solution:
1. Function not available to this responsibility. Change responsibility or contact your system administrator.
Solution
Restart the forms server
cd $ADMIN_SCRIPTS_HOME
sh adstpall.sh apps/apps
sh adstrtal.sh apps/apps

This post will cover brief overview of steps required to configure Oracle Inventory.

There are some required, optional steps and for some steps you have to check some pre defined system default values that weather it suits your business needs or change them. Perform optional steps only if you are using that business functions.

Later on I will post about optional steps.

Before defining inventory items configuring item flexfield is necessary. On basis of your requirement specific no of segments with fixed length are defined. Once you define the structure of your flexfield and any applicable value sets, you must freeze and compile your flexfield definition.

For step by step demonstration look at..
Steps to Configure System Item Flexfield


Step-2. Define flexfield of item categories.
Before defining items must design and configure your Item Categories Flexfield as all items need to be assigned with categories. After defining compile the flexfield definition to enable the Categories Flexfield pop-up window. Multiple structures for Item Categories Flexfield can be defined.

For step by step demonstration look at..
Steps to Configure Item Categories Flexfield
Step-3.Define flexfield of item catalog group.
If you do not use catalog group still at least one segment must be enabled.
to group items according to certain descriptive elements, Item Catalog Group Flexfield need to be configured. Defining and Compiling the flexfield definition enables the Item Catalog Group Flexfield pop-up

Step-4. Define flexfield of stock locators.
In order to keep track record of locators for inventory items stock locators need to be

configured. e.g. bin, row indicators. Must compile stock locator flexfield even locator control is not implemented

Step-5. Define flexfield of account aliases.
If you want to define logical references to frequently used account number and combinations and use them as transaction source types,you need to configure your account aliases flexfield and define account aliases.

Step-6. Define flexfield of sales orders.
Sales order flexfield must be configured if items will be shipped from inventory.


Step-7. Define Organization Calendar.
If you want to predict needs of your material or to plan material requirement then you can configure workday calendar for this.Work day calendar provide lot of flexibility in terms of shifts, pattern for working days also you can configure exceptions.

For step by step demonstration look at..
How to Define Work Day Calendar.

Step-8. Define organizations.
Organization define different entities in company which may have different manufacturing facilities, warehouses, distribution centers, and branch offices.
Step-9. Setup Change Organizations.
This setup enables you to change organization you define in oracle inventory.using the Change Organization window you can log out and log back in to Oracle Inventory.


Step-10. Define Inventory Relations.

For inter company relations between two operating units (typically the Shipping and Selling organizations) in a multi-organization environment, you must define the relationship in the Intercompany Relations window.

Step-11. Define unit of measure classes.
 All items having similar characteristics fall under same UOM class like Kilogram or Length.

Step-12. Define Sub inventories.

Sub inventory groups inventory logically or physically, at least one sub inventory must be assigned to each organization.

Step-13. Define Item attribute controls.
Attributes are detail information about items.Each attribute is maintained at master level or organization level.If an attribute is defined as master level then it can only be updated at item master level and attributes maintained at item/organization level can only be updated at this level only.
Step-14. Define Categories.

Categories are defined to manage items having same characteristics.

Step-15. Define Category Set and default Category Set.
Sets are defined to further group categories more functionally.Also define at least one default category set.

Step-16. Define statuses.
Statuses are defined to restrict or enable item for different functional areas.
Step-17. Define Cost Types.
Some predefined types are already defined but you can also define your own cost type.
Step-18. Define Accounting Periods.
Periods are defined in oracle General Ledger and in oracle inventory can be opened using inventory periods.

Step-19. Set profile options.

A database link is a path through which a remote user in another database can connect to any other database. Once created the database link exists as an object in the user schema.

Type of DB Links
There are 3 types of DB links. They are as follows:

1. PRIVATE: When the DB links is created, it is created under Private mode as default. The Private DBLINK is only available to the user who has created it. It is not possible for a user to grant access on a private DBLINK to other users.

2. PUBLIC: The Public DBLINK is available to all the users and all users can have the access without any restrictions.

3. SHARED: Shared database link uses share the server connection to support database link connection. If there are multiple concurrent database link access into a remote database, shared database link can be used to reduce the number of server connections required. Without the shared clause each database link connection requires a separate connection to the remote database.

Types of Logins:
In dblink we can use 2 types of login. They are as follows:

1. DEFAULT LOGIN: The User name and Password is same in both the databases.
Syntax
======
CREATE [PUBLIC] DATABASE LINK CONNECT TO CURRENT_USER USING
Code: (Text)
Create public database link daslink connect to current_user using ‘ORCL’


2. EXPLICIT LOGIN: The User Name and Password is different in both the databases.
Syntax
======
CREATE [PUBLIC|SHARED] DATABASE LINK CONNECT TOIDENTIFIED BY USING
Code: (text)
CREATE PUBLIC DATABASE LINK DDLNK CONNECT TO SCOTT IDENTIFIED BY TIGER USING ‘ORCL’

Note: To create the public DBLINK the user must have create public database link system privileges.