Wednesday 29 August 2012

Oracle PL/SQL Tutorial

Creating Procedure:

SQL> declare
  2  v_number NUMBER :=0;
  3  BEGIN
  4  v_number := v_number+10;
  5  end;
  6  /

PL/SQL procedure successfully completed.

SQL> save myfile.pls
Created file myfile.pls
SQL> clear buffer
buffer cleared
SQL> get myfile.pls
  1  declare
  2  v_number NUMBER :=0;
  3  BEGIN
  4  v_number := v_number+10;
  5* end;
SQL> /

PL/SQL procedure successfully completed.

SQL> start myfile.pls

PL/SQL procedure successfully completed.

SQL> @myfile.pld
SP2-0310: unable to open file "myfile.pld"
SQL> @myfile.pls

PL/SQL procedure successfully completed.

SQL> show error
No errors.
SQL> show errors
No errors.
SQL>

Thursday 16 August 2012

How to Change the DBID and the DBNAME by using NID



Introduction
============

The NID (New Database ID)is a new utility introduced with Oracle 9.2.  The NID
utility allows you to change only the DBNAME, or only the DBID or both 
DBNAME and DBID in the same command.

  1. If you change the DBID you must open the database with the RESETLOGS 
     option, which re-creates the online redo logs and resets their sequence
     to 1. 

  2. If you change the DBNAME without changing the DBID then this does not 
     require you to open with the RESETLOGS option, so database backups and
     archived logs are not invalidated.  You must change the DB_NAME initialization
     parameter after a database name change to reflect the new name.  Also, 
     you may have to re-create the Oracle password file.  If you restore an old
     backup of the control file (before the name change, then you should
     use the initialization parameter file and password file from before the 
     database name change.
 

Purpose
=======

It is useful to troubleshoot from the situation when duplicate database ID's
cause errors such as the following.

  RMAN-20002: target database already registered in recovery catalog 
       Cause: target database is already registered in the recovery catalog 
      Action: If the target database is really registered, there is no need to 
              register it again. Note that the recovery catalog enforces that 
              all databases have a unique DBID. If the new database was created
              by copying files from an existing database, it will have the same
              DBID as the original database and cannot be registered in the 
              same recovery catalog.

  RMAN-20011, 1, "target database incarnation is not current in recovery catalog"
  RMAN-20009, 1, "database incarnation already registered"

  -or-

  SQLPLUS> alter database mount standby database;
  alter database mount standby database
  *
  ORA-01102: cannot mount database in EXCLUSIVE mode


Restrictions and Usage Notes
============================

The DBNEWID utility has the following restrictions:

 - The utility is available only on the UNIX and Windows NT operating systems. 
 - The NID executable file should be owned and run by the Oracle owner because 
   it needs direct access to the datafiles and control files. 
 - If another user runs the utility, then set the user ID to the owner of the datafiles and control files. 
 - The DBNEWID utility must access the datafiles of the database directly through a local connection.
   Although DBNEWID can accept a net service name, it cannot change the DBID of a nonlocal database. 
 - To change the DBID of a database, the database must be mounted and must have been shut down consistently 
   prior to mounting. In the case of an Oracle Real Application Clusters database, the database must be
   mounted in NOPARALLEL mode. i.e set the init parameter CLUSTER_DATABASE=FALSE and then mount the database 
 - You must open the database with the RESETLOGS option after changing the DBID. 
 - Note that you do not have to open with the RESETLOGS option after changing only the database name. 
 - No other process should be running against the database when DBNEWID is executing. 
   If another session shuts down and starts the database, then DBNEWID aborts. 
 - All online datafiles should be consistent without needing recovery. 
 - Normal offline datafiles should be accessible and writable.
   If this is not the case, you must drop these files before invoking the DBNEWID utility. 
 - All read-only tablespaces must be accessible and made writable at the operating system level prior
   to invoking DBNEWID. If these tablespaces cannot be made writable (for example, they are on a CD-ROM),
   then you must unplug the tablespaces using the transportable tablespace feature and then plug them back
   in the database before invoking the DBNEWID utility (see the Oracle9i Database Administrator's Guide). 
 - You can only specify REVERT when changing only the DBID.
 

Change Only the DBID
====================

  1. Backup the database
  2. SHUTDOWN IMMEDIATE of the database
  3. STARTUP MOUNT
  4. Open one session and run NID with sysdba privileges
     % nid TARGET=SYS/password@test_db 
  5. Shutdown IMMEDIATE of the database
  6. Set the DB_NAME initialization parameter in the initialization parameter 
     file to the new database name 
  7. Create a new password file 
  8. Startup of the database with open resetlogs


Example:
========

1. C:\>set ORACLE_SID=TEST1BY
   C:\>sqlplus "/as sysdba"
   SQL*Plus: Release 9.2.0.1.0 - Production on Tue Dec 24 11:16:52 2002
   Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.
   Connected to an idle instance.

   SQL> startup pfile=D:\oracle\admin\TEST1BY\pfile\initTEST1BY.ora
   ORACLE instance started.

   Total System Global Area  135338868 bytes
   Fixed Size                   453492 bytes
   Variable Size             109051904 bytes
   Database Buffers           25165824 bytes
   Redo Buffers                 667648 bytes
   Database mounted.
   Database opened.

2. check the DBID before change 

   SQL> select dbid,name,open_mode,activation#,created from v$database;

         DBID NAME      OPEN_MODE  ACTIVATION# CREATED
   ---------- --------- ---------- ----------- ---------
   1395399949 TEST1BY   READ WRITE  1395404134 10-SEP-02


3. SQL> shutdown immediate;
   Database closed.
   Database dismounted.
   ORACLE instance shut down.

4. SQL> startup mount pfile=D:\oracle\admin\TEST1BY\pfile\initTEST1BY.ora
   ORACLE instance started.

   Total System Global Area  135338868 bytes
   Fixed Size                   453492 bytes
   Variable Size             109051904 bytes
   Database Buffers           25165824 bytes
   Redo Buffers                 667648 bytes
   Database mounted.
   SQL>exit

5. execute NID

   C:\>nid target=sys/oracle@TEST1BY

   DBNEWID: Release 9.2.0.1.0 - Production
   Copyright (c) 1995, 2002, Oracle Corporation.  All rights reserved.

   Connected to database TEST1BY (DBID=1395399949)

   Control Files in database:
     D:\ORACLE\BASE_TEST\TEST1BYCONTROL01.CTL

   Change database ID of database TEST1BY? (Y/[N]) => y

   Proceeding with operation
   Changing database ID from 1395399949 to 1397190693
   Control File D:\ORACLE\BASE_TEST\TEST1BYCONTROL01.CTL - modified
   Datafile D:\ORACLE\BASE_TEST\TEST1BY\SYSTEM01.DBF - dbid changed
   Datafile D:\ORACLE\BASE_TEST\TEST1BY\UNDOTBS01.DBF - dbid changed
   Datafile D:\ORACLE\BASE_TEST\TEST1BY\DRSYS01.DBF - dbid changed
   Datafile D:\ORACLE\BASE_TEST\TEST1BY\EXAMPLE01.DBF - dbid changed
   Datafile D:\ORACLE\BASE_TEST\TEST1BY\INDX01.DBF - dbid changed
   Datafile D:\ORACLE\BASE_TEST\TEST1BY\TOOLS01.DBF - dbid changed
   Datafile D:\ORACLE\BASE_TEST\TEST1BY\USERS01.DBF - dbid changed
   Datafile D:\ORACLE\BASE_TEST\TEST1BY\XDB01.DBF - dbid changed
   Control File D:\ORACLE\BASE_TEST\TEST1BYCONTROL01.CTL - dbid changed

   Database ID for database TEST1BY changed to 1397190693.
   All previous backups and archived redo logs for this database are unusable.
   Shut down database and open with RESETLOGS option.
   Succesfully changed database ID.
   DBNEWID - Completed succesfully.

6. SQL> shutdown immediate;
   ORA-01109: database not open
   Database dismounted.
   ORACLE instance shut down.

7. create the new passwordfile

8. SQL> startup mount pfile=D:\oracle\admin\TEST1BY\pfile\initTEST1BY.ora
   ORACLE instance started.

   Total System Global Area  135338868 bytes
   Fixed Size                   453492 bytes
   Variable Size             109051904 bytes
   Database Buffers           25165824 bytes
   Redo Buffers                 667648 bytes
   Database mounted.

9. SQL> alter database open resetlogs;
   Database altered.

10. check the new DBID

    SQL> select dbid,name,open_mode,activation#,created from v$database;

          DBID NAME      OPEN_MODE  ACTIVATION# CREATED
    ---------- --------- ---------- ----------- ---------
    1397190693 TEST1BY   READ WRITE  1397188261 10-SEP-02


NOTE: The NID change the OLD DBID 1395399949 to the NEW DBID 1397190693
  
        
Change Only the DBNAME
======================

  1. Backup the database
  2. SHUTDOWN IMMEDIATE of the database
  3. STARTUP MOUNT
  4. Open one session and run NID with sysdba privileges
     % nid TARGET=SYS/password@test_db DBNAME=test_db2 SETNAME=Y
     - the value of DBNAME is the new dbname of the database
     - SETNAME must be set to Y. The default is N and causes the 
       DBID to be changed also.
  5. shutdown IMMEDIATE of the database
  6. Set the DB_NAME initialization parameter in the initialization parameter
     file to the new database name
  7. Create a new password file 
  8. Startup of the database(without resetlogs)
 
          
Change Both DBID and DBNAME
===========================

  1. Backup of the database. 
  2. Shutdown IMMEDIATE of the database
  3. STARTUP MOUNT
  4. Open one session and run NID with sysdba privileges
     % nid TARGET=SYS/password@test_db DBNAME=test_db2
     - the value of DBNAME is the new dbname of the database
  5. After DBNEWID successfully changes the DBID,Shutdown IMMEDIATE of the database 
  6. Set the DB_NAME initialization parameter in the
     initialization parameter file to the new database name. 
  7. Create a new password file. 
  8. Startup of the database with open resetlogs
  

Example:
========

1. Shutdown the databse

   SQL> shutdown immediate;
   Database closed.
   Database dismounted.
   ORACLE instance shut down.

2. Mount the database

   SQL> startup mount pfile=d:\oracle\admin\test1by\pfile\inittest1by.ora
   ORACLE instance started.

   Total System Global Area  135338868 bytes
   Fixed Size                   453492 bytes
   Variable Size             109051904 bytes
   Database Buffers           25165824 bytes
   Redo Buffers                 667648 bytes
   Database mounted.
   startup mount

3. Run NID utility

   C:\>nid target=sys/oracle@test1 dbname=test1by logfile=d:\oracle\base_test\nid.log
  
   DBNEWID: Release 9.2.0.1.0 - Production
   Copyright (c) 1995, 2002, Oracle Corporation.  All rights reserved.

   Connected to database TEST1 (DBID=849281895)

   Control Files in database:
     D:\ORACLE\BASE_TEST\TEST1BYCONTROL01.CTL

   Changing database ID from 849281895 to 1395399949
   Changing database name from TEST1 to TEST1BY
   Control File D:\ORACLE\BASE_TEST\TEST1BYCONTROL01.CTL - modified
   Datafile D:\ORACLE\BASE_TEST\TEST1BY\SYSTEM01.DBF - dbid changed, wrote new name
   Datafile D:\ORACLE\BASE_TEST\TEST1BY\UNDOTBS01.DBF - dbid changed, wrote new name
   Datafile D:\ORACLE\BASE_TEST\TEST1BY\DRSYS01.DBF - dbid changed, wrote new name
   Datafile D:\ORACLE\BASE_TEST\TEST1BY\EXAMPLE01.DBF - dbid changed, wrote new name
   Datafile D:\ORACLE\BASE_TEST\TEST1BY\INDX01.DBF - dbid changed, wrote new name
   Datafile D:\ORACLE\BASE_TEST\TEST1BY\TOOLS01.DBF - dbid changed, wrote new name
   Datafile D:\ORACLE\BASE_TEST\TEST1BY\USERS01.DBF - dbid changed, wrote new name
   Datafile D:\ORACLE\BASE_TEST\TEST1BY\XDB01.DBF - dbid changed, wrote new name
   Control File D:\ORACLE\BASE_TEST\TEST1BYCONTROL01.CTL - dbid changed, wrote new name

   Database name changed to TEST1BY.
   Modify parameter file and generate a new password file before restarting.
   Database ID for database TEST1BY changed to 1395399949.
   All previous backups and archived redo logs for this database are unusable.
   Shut down database and open with RESETLOGS option.
   Succesfully changed database name and ID.
   DBNEWID - Completed succesfully.

4. Shutdown immediate of the database
 
5. Modfiy the file init.ora of the database
   change the parameter BD_NAME=TEST1 TO DBNAME=TEST1BY

6. create a new password file

   Usage: orapwd file=<fname> password=<password> entries=<users>
   where
    file - name of password file (mand),
    password - password for SYS (mand),
    entries - maximum number of distinct DBA and OPERs (opt),
   
7. mount the database

   SQL> startup mount pfile=d:\oracle\admin\test1by\pfile\inittest1by.ora
   ORACLE instance started.

   Total System Global Area  135338868 bytes
   Fixed Size                   453492 bytes
   Variable Size             109051904 bytes
   Database Buffers           25165824 bytes
   Redo Buffers                 667648 bytes
   Database mounted.

8. Open the databse with RESETLOGS
   SQL> alter database open resetlogs;
   Database altered.

9. check the dictionary view for the new DBID and DBNAME
   select dbid, name, open_mode, activation#, created from v$database;
 

Other Useful Information
========================

Except the parameters like LOGFILE=, APPEND, HELP, there is a specific option 
REVERT which allows us to go back on the steps of executing.  If the value of 
REVERT is YES that means that a failed change of DBID should be reverted but a 
successfully completed change of DBID cannot be reverted.  REVERT=YES is only 
valid when a DBID change failed.  Default value is NO.

In 10.2 and higher the database may automatically shut down after a change.
Do not be alarmed if this occurs.
 

Documentation
=============

Oracle9i Database Utilities Release 2 (9.2)

BACKUP SCENARIOS


Purpose

Describe various Backup and Recovery Scenarios.

Troubleshooting Steps


BACKUP SCENARIOS


a) Consistent backups

A consistent backup means that all data files and control files are consistent  to a point in time. I.e. they have the same SCN. This is the only method of  backup when the database is in NO Archive log mode.

b) Inconsistent backups

An Inconsistent backup is possible only when the database is in Archivelog mode.  You must apply redo logs to the data files, in order to restore the database to a consistent state.  Inconsistant backups can be taken using RMANwhen the database is open.
Inconsistant backups can also be taken using other OS tools provided the tablespaces (or database) is put into backup mode.
ie: SQL> alter tablespace data begin backup;
    SQL> alter database begin backup; (version 10 and above only)

c) Database Archive mode

The database can run in either Archivelog mode or noarchivelog mode.  When you first create the database, you specify if it is to be in Archivelog  mode. Then in the init.ora file you set the parameter log_archive_start=true  so that archiving will start automatically on startup.
If the database has not been created with Archivelog mode enabled, you can  issue the command whilst the database is mounted, not open.

SQL> alter database Archivelog;.
SQL> log archive start
SQL> alter database open;
SQL> archive log list

This command will show you the log mode and if automatic archival is set.

d) Backup Methods

Essentially, there are two backup methods, hot and cold, also known as online and offline, respectively. A cold backup is one taken when the database is shutdown. The database must be shutdown cleanly.  A hot backup is on taken when the database is running. Commands for a hot backup:

For non RMAN backups:

1. Have the database in archivelog mode (see above)
2. SQL> archive log list
--This will show what the oldest online log sequence is. As a precaution, always keep the all archived log files starting from the oldest online log sequence.
3. SQL> Alter tablespace tablespace_name BEGIN BACKUP;
or SQL> alter database begin backup (for v10 and above).
4. --Using an OS command, backup the datafile(s) of this tablespace.
5. SQL> Alter tablespace tablespace_name END BACKUP
--- repeat step 3, 4, 5 for each tablespace.
or SQL> alter database end backup; for version 10 and above
6. SQL> archive log list
---do this again to obtain the current log sequence. You will want to make sure you have a copy of this redo log file.
7. So to force an archived log, issue
SQL> ALTER SYSTEM SWITCH LOGFILE
A better way to force this would be:
SQL> alter system archive log current;
8. SQL> archive log list
This is done again to check if the log file had been archived and to find the latest archived sequence number.
9. Backup all archived log files determined from steps 2 and 8.
10. Back up the control file:
SQL> Alter database backup controlfile to 'filename'

For RMAN backups:
see Note.<>  RMAN - Sample Backup Scripts 10g
or the appropriate RMAN documentation.

e) Incremental backups

These are backups that are taken on blocks that have been modified since the last backup. These are useful as they don't take up as much space and time. There are two kinds of incremental backups Cumulative and Non cumulative.

Cumulative incremental backups include all blocks that were changed since the  last backup at a lower level. This one reduces the work during restoration as  only one backup contains all the changed blocks.
Noncumulative only includes blocks that were changed since the previous backup  at the same or lower level.

Using rman, you issue the command "backup incremental level n"

Oracle v9 and below RMAN will back up empty blocks, oracle v10.2 RMAN will not back up empty blocks

f) Support scenarios

When the database crashes, you now have a backup. You restore the backup and
then recover the database. Also, don't forget to take a backup of the control
file whenever there is a schema change.

RECOVERY SCENARIOS

Note: All online datafiles must be at the same point in time when completing recovery;

There are several kinds of recovery you can perform, depending on the type of  failure and the kind of backup you have. Essentially, if you are not running in archive log mode, then you can only recover the cold backup of the database and you will lose any new data and changes made since that backup was taken. If, however, the database is in Archivelog mode you will be able to restore the database up to the time of failure. There are three basic types of recovery:

1. Online Block Recovery.

This is performed automatically by Oracle.(pmon) Occurs when a process dies  while changing a buffer. Oracle will reconstruct the buffer using the online  redo logs and writes it to disk.

2. Thread Recovery.

This is also performed automatically by Oracle. Occurs when an instance  crashes while having the database open. Oracle applies all the redo changes  in the thread that occurred since the last time the thread was checkpointed.

3. Media Recovery.

This is required when a data file is restored from backup. The checkpoint count in the data files here are not equal to the check point count in the  control file.

Now let's explain a little about Redo vs Undo.

Redo information is recorded so that all commands that took place can be  repeated during recovery. Undo information is recorded so that you can undo changes made by the current transaction but were not committed. The Redo Logs  are used to Roll Forward the changes made, both committed and non- committed  changes. Then from the Undo segments, the undo information is used to
rollback the uncommitted changes.

Media Failure and Recovery in Noarchivelog Mode

In this case, your only option is to restore a backup of your Oracle files. The files you need are all datafiles, and control files.  You only need to restore the password file or parameter files if they are lost or are corrupted.

Media Failure and Recovery in Archivelog Mode

In this case, there are several kinds of recovery you can perform, depending on what has been lost. The three basic kinds of recovery are:

1. Recover database - here you use the recover database command and the database must be closed and mounted. Oracle will recover all datafiles that are online.

2. Recover tablespace - use the recover tablespace command. The database can be open but the tablespace must be offline.

3. Recover datafile - use the recover datafile command. The database can be  open but the specified datafile must be offline.

Note: You must have all archived logs since the backup you restored from,  or else you will not have a complete recovery.

a) Point in Time recovery:

A typical scenario is that you dropped a table at say noon, and want to recover it. You will have to restore the appropriate datafiles and do a point-in-time  recovery to a time just before noon.

Note: you will lose any transactions that occurred after noon.  After you have recovered until noon, you must open the database with resetlogs. This is necessary to reset the log numbers, which will protect the database  from having the redo logs that weren't used be applied.

The four incomplete recovery scenarios all work the same:

Recover database until time '1999-12-01:12:00:00';
Recover database until cancel; (you type in cancel to stop)
Recover database until change n;
Recover database until cancel using backup controlfile;

Note: When performing an incomplete recovery, the datafiles must be online. Do a select * from v$recover_file to find out if there are any files  which are offline. If you were to perform a recovery on a database which has  tablespaces offline, and they had not been taken offline in a normal state, you will lose them when you issue the open resetlogs command. This is because the data file needs recovery from a point before the resetlogs option was used.

b) Recovery without control file

If you have lost the current control file, or the current control file is  inconsistent with files that you need to recover, you need to recover either by using a backup control file command or create a new control file. You can also recreate the control file based on the current one using the  'SQL> backup control file to trace' command which will create a script for you to  run to create a new one.  Recover database using backup control file command must be used when using a  control file other that the current. The database must then be opened with
resetlogs option.

c) Recovery of missing datafile with rollback segments

The tricky part here is if you are performing online recovery. Otherwise you  can just use the recover datafile command. Now, if you are performing an  online recovery, you will need to create a new undo tablespace to be used.  Once the old tablespace has been recovered it can be dropped once any uncommitted  transactions have rolled back.

d) Recovery of missing datafile without undo segments

There are three ways to recover in this scenario, as mentioned above.
1. recover database;
2. recover datafile 'c:\orant\database\usr1orcl.ora';
3. recover tablespace user_data;

e) Recovery with missing online redo logs

Missing online redo logs means that somehow you have lost your redo logs before  they had a chance to archived. This means that crash recovery cannot be  performed, so media recovery is required instead. All datafiles will need to be restored and rolled forwarded until the last available archived log file is applied. This is thus an incomplete recovery, and as such, the recover
database command is necessary.

As always, when an incomplete recovery is performed, you must open the database with resetlogs.
Note: the best way to avoid this kind of a loss, is to mirror your online log files.

f) Recovery with missing archived redo logs

If your archives are missing, the only way to recover the database is to restore from your latest backup. You will have lost any uncommitted
transactions which were recorded in the archived redo logs. Again, this is why  Oracle strongly suggests mirroring your online redo logs and duplicating copies  of the archives.

g) Recovery with resetlogs option

Reset log option should be the last resort, however, as we have seen from above, it may be required due to incomplete recoveries. (recover using a backup control file, or a point in time recovery). It is imperative that you backup up the database immediately after you have opened the database with reset logs.  It is possible to recover through a resetlogs, and made easier with Oracle V10, but easier
to restore from the backup taken after the resetlogs

h) Recovery with corrupted undo segments.

If an undo segment is corrupted, and contains uncommitted system data you may not be able to open the database.

The best alternative in this situation is to recover the corrupt block using the RMAN blockrecover command next best would be to restore the datafile from backup and do a complete recovery.

If a backup does not exist and If the database is able to open (non system object) The first step is to find out what object is causing the rollback to appear corrupted. If we can determine that, we can drop that object.

So, how do we find out if it's actually a bad object?

1. Make sure that all tablespaces are online and all datafiles are online. This can be checked through via the v$recover_file view.

2. Put the following in the init.ora:
event = "10015 trace name context forever, level 10"

This event will generate a trace file that will reveal information about the  transaction Oracle is trying to roll back and most importantly, what object  Oracle is trying to apply the undo to.

Note: In Oracle v9 and above this information can be found in the alert log.

Stop and start the database.

3. Check in the directory that is specified by the user_dump_dest parameter (in the init.ora or show parameter command) for a trace file that was  generated at startup time.

4. In the trace file, there should be a message similar to: error recovery tx(#,#) object #.

TX(#,#) refers to transaction information.
The object # is the same as the object_id in sys.dba_objects.

5. Use the following query to find out what object Oracle is trying to perform recovery on.

select owner, object_name, object_type, status
from dba_objects where object_id = <object #>;

6. Drop the offending object so the undo can be released. An export or relying on a backup may be necessary to restore the object after the corrupted undo segment is released.

i) Recovery with System Clock change.

You can end up with duplicate timestamps in the datafiles when a system clock  changes. This usually occurs when daylight saving comes into or out of the picture. In this case, rather than a point in time recovery, recover to a specify log or SCN

j) Recovery with missing System tablespace.

The only option is to restore from a backup.

k) Media Recovery of offline tablespace

When a tablespace is offline, you cannot recover datafiles belonging to this  tablespace using recover database command. The reason is because a recover database command will only recover online datafiles. Since the tablespace is  offline, it thinks the datafiles are offline as well, so even if you recover database and roll forward, the datafiles in this tablespace will not be touched.  Instead, you need to perform a recover tablespace command. Alternatively, you  could restored the datafiles from a cold backup, mount the database and select  from the v$datafile view to see if any of the datafiles are offline. If they are, bring them online, and then you can perform a recover database command.

l) Recovery of Read-Only tablespaces

If you have a current control file, then recovery of read only tablespaces is  no different than recovering read-write files. The issues with read-only tablespaces arise if you have to use a backup control file. If the tablespace is in read-only mode, and hasn't changed to read-write since the last backup, then you will be able to media recovery using a backup control file by taking the tablespace offline. The reason here is that when you are using the backup control file, you must open the database with resetlogs. And we know that Oracle wont let you read files from before a resetlogs was done. However, there is an exception with read-only tablespaces. You will be able to take the datafiles online after you have opened the database.

When you have tablespaces that switch modes and you don't have a current control file, you should use a backup control file that recognizes the tablespace in  read-write mode. If you don't have a backup control file, you can create a new  one using the create controlfile command.  Basically, the point here is that you should take a backup of the control file every time you switch a tablespaces mode.

Thursday 9 August 2012

Oracle Apps Sys Admin - Users and Responsibilities

Securing attributes are used by Oracle HTML-based applications to allow rows (records) of data to be visible to specified users or responsibilities based on the specific data (attribute values) contained in the row. You may assign one or more values for any of the securing attributes assigned to the user. If a securing attribute is assigned to both a responsibility and to a user, but the user does not have a value for that securing attribute, no information is returned for that attribute.
For example, to allow a user in the ADMIN responsibility to see rows containing a CUSTOMER_ID value of 1000, assign the securing attribute of CUSTOMER_ID to the ADMIN responsibility. Then give the user a security attribute CUSTOMER_ID value of 1000.
When the user logs into the Admin responsibility, the only customer data they have access to has a CUSTOMER_ID value of 1000.

Fields

Attribute : Select an attribute you want used to determine which records this user can access. You can select from any of the attributes assigned to the user's responsibility.
Value : Enter the value for the attribute you want used to determine which records this user can access.

Creation of Responsibility

Navigation – System Administrator ->Security -> Responsibility -> Define

Figure 5. Create Responsibility Navigation
Follow the above the navigation path and click on Define. You will see following screen in front of you.
Figure 6. Create Responsibility

Fields

Responsibility Name - If you have multiple responsibilities, a pop-up window includes this name after you sign on.
Application - This application name does not prevent the user of this responsibility from accessing other applications' forms and functions if you define the menu to access other applications.
Responsibility Key - This is a unique name for a responsibility that is used by loader programs. Loaders are concurrent programs used to "load" such information as messages, user profiles and user profile values into your Oracle Applications tables. To help ensure that your responsibility key is unique throughout your system, begin each Responsibility Key name with the application short name associated with this responsibility.
Effective Dates From/To - Enter the start/end dates on which the responsibility becomes active/inactive. The default value for the start date is the current date, and if you do not enter an end date, the responsibility is valid indefinitely.
You cannot delete a responsibility because its information helps to provide an audit trail. You can deactivate a responsibility at any time by setting the end date to the current date. If you wish to reactivate the responsibility, change the end date to a date after the current date, or clear the end date.
Available From - A responsibility may be associated with only one applications system. Select between Oracle Self-Service Web Applications or Oracle Applications.
Data Group - Name/Application The data group defines the pairing of application and ORACLE username. Select the application whose ORACLE username forms connect to when you choose this responsibility. The ORACLE username determines the database tables and table privileges accessible by your responsibility. Transaction managers can only process requests from responsibilities assigned the same data group as the transaction manager.
Menu - The menu whose name you enter must already be defined with Oracle Applications.
Web Host Name - If your Web Server resides on a different machine from your database, you must designate the host name (URL) here. Otherwise, the Web Host Name defaults to the current database host server.
Web Agent Name - Enter the PL/SQL Agent Name for the database used by this responsibility. If you do not specify an Agent Name, the responsibility defaults to the agent name current at log-on.
Request Group Name/Application - If you do not assign a request security group to this responsibility, a user with this responsibility cannot run requests, request sets, or concurrent programs from the Submit Requests window, except for request sets owned by the user. The user can access requests from a Submit Requests window you customize with a request group code through menu parameters.

Menu Exclusions Block

Define function and menu exclusion rules to restrict the application functionality accessible to a responsibility.
Type : Select either Function or Menu as the type of exclusion rule to apply against this responsibility.
  • When you exclude a function from a responsibility, all occurrences of that function throughout the responsibility's menu structure are excluded.
  • When you exclude a menu, all of its menu entries, that is, all the functions and menus of functions that it selects are excluded.
Name : Select the name of the function or menu you wish to exclude from this responsibility. The function or menu you specify must already be defined in Oracle Applications.

Figure 7. Create Responsibility Excluded Items
Excluded Items : Use the List of Values to select valid attributes. You can assign any number of Excluded Attributes to a responsibility

Figure 8. Create Responsibility Securing Attributes

Frequently Asked Questions

1. What is the significance of securing attributes while creating users?
2. What is the significance of securing attributes while creating responsibilities?
3. What is the significance of Menu Exclusions in responsibility?
4. What is Excluded Items in Responsibility?
5. How do I assign a responsibility to a user?
6. What is data group in a responsibility?
7. What is the significance of Request Group in the responsibility?

Create a user in Oracle Apps 11i

Creation of User

Navigation – System Administrator ->Security -> User -> Define

Figure 1. Create User Navigation
Follow the above the navigation path and click on Define. You will see following screen in front of you.
Figure 2. Create User

Fields

UserName
Give the username in this field.
Password
Enter desired password twice in this field. You would be required to change the password when you login first time with this username.
Description
Provide brief description of the user in this field.
Password Expiration
Days No. of Days after which the password will expire for the user.
Accesses No. of Accesses after which the password will expire for the user.
None The password will never expire
Person
You can attach employee to this user. This is used for HRMS applications
Customer
To attach customer to this user.
Supplier
To attach supplier to this user.
Email
Provide email address for the user. Its use to send notifications to the user through oracle applications.
Fax
Fax number for the user.
Effective Dates
From and To dates between which the user would be active.
Responsibilities
List of responsibilities assigned to the user.
Figure 3. Create User Indirect Responsibilities
Figure 4. Create User Securing Attributes


Oracle Financials Interview Questions – Answers Included

Oracle Financials Interview Questions – Answers Included


Below is a list of 25 Important questions that is asked in almost every financials technical interview question. I have also included some of the functional questions that are asked.Answers are included.
Qns: What is Flex field? What are different types of Flex field?
Ans: Flex field is used to capture information of your Organisations.
Qns: Difference between KFF and DFF.
KFF
Unique identifier
Stored in segment Column
DFF
Is used to capture additional information
Stored in attribute Column
Qns: How many KFF are in GL. AP , AR.
Ans:
Module KFF
GL Accounting FF
AP No KFF
AR Sales tax Location FF
Territory Flexfield.
Qns: What is symbol of DFF in the Forms?
Ans: Square Bracket [ ].
Qns: What is structure of KFF in the Accounting Flexfields.
Ans: Company
Cost center
Account
Product
Future use.
Qns: How many segments are in AFF.
Ans: max 30 segments and min two.
Qns: What are flexfield Qualifiers.
Ans: Flexfield Qualifiers is used to identify the segments. Various types of flexfield qualifiers are listed below:
a) Balancing Segment Qualifier.
b) Cost Center segment Qualifier.
c) Natural Account Segment Qualifier.
d) Intercompany Segment Qualifier.
Qns: What is Dynamic Insertions?
Ans: u can create Code Combinations at run time.
Qns: In which table Code Cominations id is stored.
Ans: GL_CODE_COMBINATIONS.
Qns: In which table flex values are stored.
Ans: 1. fnd_ flex_Values
2. fnd_ flex_Values_tl
Qns: What is set of Books and in which table set of book is stored.
Ans : Set of Books is a Financial Reporting entity which Consist of three C.
a) Chart Of Accounts
b) Currency
c) Calendar.
Set of Books is stored in GL_SETS_OF_BOOKS
Qns: In which table Currency and Period Type Name are stored.
Currency – FND_CURRENCIES
Period – GL_PERIOD_STATUSES
Qns: In which table Segment Values are stored and concatenated values are stored.
Ans: 1. GL_CODE_COMBINATIONS
2. GL_CODE_COMBINATIONS_KFV.
Qns: What are different types of Currency.
Ans: Functional Currency
Foreign currency.
Qns: What are different types of Calendars .
Ans: Different types of Calendars are listed below
a) Fiscal
b) Accounting
Qns: How will you attach set of Books to the Responsibility?
Ans: through Profile. GL SETS OF Books Name.
Qns: What is Profile and what are different types of Profiles.
Ans: Profile: Profile is the changeable option that affects the way your application runs. There are two types of profile.
1. System defined
2. User defined
Qns: What are different Profiles Level available in oracle apps.
Ans: Below are the Profiles Level available in oracle apps
1. Site(Lowest level)
2. Application
3. Responsibility
4. User.
Qns: Write Name of some Profile options.
Ans:
1. GL Sets of Books Name
2. GL sets of Books id
3. MO:Operating unit (multi org).
4. HR:User type.
Qns: What is cycle of GL.?
Ans: In simple and layman words-
1. Open the period
2. Create Journal Enteries
3. Post the Journals.
Qns: In Which tables Journal entries created.
Ans: Important tables are-
1. Batch: GL_JE_BATCHES
2. Header: GL_JE_HEADERS
3. Lines : GL_JE_LINES
Qns: After Posting data goes in which tables.
Ans: GL_BALANCES.( Column Period_net_cr, period_net_dr).
Qns: What are Important tables in GL.
Ans:
1. GL_JE_BATCHES
2. GL_JE_HEADERS
3. GL_JE_LINES
4. GL_BALANCES
5. GL_SETS_OF_BOOKS
6. GL_CODE_COMBINATIONS
7. GL_PERIOD_STATUES
8. GL_INTERFACE
Qns: In which table Supplier information's is stored.
Ans: Supplier information can be found in following tables
1. PO_VENDORS
2. PO_VENDOR_SITES_ALL
3. PO_VENDOR_CONTACTS
Qns: What is difference org_id and Organization_id.
Ans: Org_id is for operating unit and organization_id is for inventory organization.

Create User and Privillages

CREATE USER nageswar IDENTIFIED BY  nageswar DEFAULT TABLESPACE data_ts QUOTA 100M ON test_ts QUOTA 500K ON data_ts TEMPORARY TABLESPACE temp_ts PROFILE manager; 

GRANT connect TO nageswar;

ORDER MANAGEMENT: interview questions and answers

ORDER MANAGEMENT: interview questions and answers

ORDER MANAGEMENT:

1)    What are the Base Tables and Interface Tables for Order Management?
       Interface Tables    : OE_HEADERS_IFACE_ALL, OE_LINES_IFACE_ALL
                  OE_PRICE_ADJS_IFACE_ALL, OE_ACTIONS_IFACE_ALL
                  OE_CREDITS_IFACE_ALL (Order holds like credit check holds etc)
       Base Tables    : OE_ORDER_HEADERS_ALL: Order Header Information
  OE_ORDER_LINES_ALL: Items Information
              OE_PRICE_ADJUSTMENTS: Discounts Information
  OE_SALES_CREDITS: Sales Representative Credits.
Shipping Tables :WSH_NEW_DELIVERIES, WSH_DELIVERY_DETAILS,  WSH_DELIVERY_ASSIGNMENTS, WSH_DELIVERIES.
              
2)    What is Order Import and What are the Setup's involved in Order Import?
A)    Order Import is an open interface that consists of open interface tables and a set of API’s. It imports New, updated, or changed sales orders from other applications such as Legacy systems. Order Import features include validations, Defaulting, Processing Constraints checks, Applying and releasing of order holds, scheduling of shipments, then ultimately inserting, updating or deleting orders from the OM base tables. Order management checks all the data during the import process to ensure its  validity with OM. Valid Transactions are then converted into orders with lines, reservations ,price adjustments,  and sales credits in the OM base tables.
B)    Setups:
•    Setup every aspect of order management that we want to use with imported orders, including customers, pricing, items, and bills.
•    Define and enable the order import sources using the order import source window.

3)    Explain the Order Cycle?
i)    Enter the Sales Order
ii)    Book the Sales Order(SO will not be processed until booked(Inventory confirmation))
iii)    Release sales order(Pickslip Report is generated and Deliveries are created)
(Deliveries – details about the delivery. Belongs to shipping module (wsh_deliveries, wsh_new_deliveries, wsh_delivery_assignments etc)  they explain how many items are being shipped and such details.
iv)    Transaction Move Order (creates reservations determines the source and transfers the inventory into the staging areas)
v)    Launch Pick Release (
vi)    Ship Confirm (Shipping Documents(Pickslip report, Performa Invoice, Shipping Lables))
4)  Explain the Order to Cash Flow?
I.    Enter the Sales Order
II.    Book the Sales Order (SO will not be processed until booked (Inventory confirmation))
III.    Release sales order (Pick slip Report is generated and Deliveries are created)
   (Deliveries – details about the delivery. Belongs to shipping module (wsh_deliveries, wsh_new_deliveries, wsh_delivery_assignments etc) they explain how many items are being shipped and such details.
IV.    Transaction Move Order (Selects the serial number of the product which has to be moved/ shipped)
V.    Launch Pick Release
VI.    Ship Confirm (Shipping Documents (Pick slip report, Performa Invoice, Shipping Labels))
VII.    Auto Invoice  (Creation of Invoice in Accounts Receivable Module)
VIII.    Autolockbox ( Appling Receipts to Invoices In AR)
IX.    Transfer to General Ledger ( Populates GL interface tables)
X.    Journal Import ( Populates GL base tables)
XI.    Posting ( Account Balances Updated).

5.  What are the Process Constraints?
A. Process Constraints prevent users from adding updating, deleting, splitting lines and canceling     order or return information beyond certain points in the order cycle. Oracle has provided certain process constraints which prevent data integrity violations.
    Process constraints are defined for entities and attributes. Entities include regions on the sales order window such as order, line, order price adjustments,    line price adjustments, order sales credits and line sales credits. Attributes include individual fields (of a particular entity) such as warehouse, shit to location, or agreement.
6.  What are Validation Templates?   
A) Validation Templates are used to define the validation conditions in process constraints. A validation template names a conditions and defines the semantic of how to validate that condition. These are used in processing constraints framework to specify the constraining conditions for a given constraint. These conditions are based on
•    Where the entity is in its work flow.
•    The state of attributes on an entity.
•    Any other validation condition that cannot be modeled using the above condition.
 
7.  What are different types of Holds?
•    GSA(General Services Administration) Violation Hold(Ensures that specific customers always get better pricing for example  Govt. Customers)
•    Credit Checking Hold( Used for credit checking feature Ex: Credit Limit)
•    Configurator Validation Hold ( Cause: If we invalidate a configuration after booking)
8. What is Document Sequence?
A) Document sequence is defined to automatically generate numbers for your orders or returns as you enter them. Single / multiple document sequences can be defined for different order types.
Document sequences can be defined as three types Automatic (Does not ensure that the numbers are contiguous), Gapless (Ensures that the numbering is contiguous), Manual Numbering. Order Management validates that the number specified is unique for order type.
9. What are Defaulting Rules?
A) A defaulting rule is a value that OM automatically places in an order field of the sales order window. Defaulting rules reduce the amount of information one must enter. A defaulting rule is a collection of defaulting sources for objects and their attributes.
It involves the following steps
•    Defaulting Conditions  - Conditions for Defaulting
•    Sequence – Priority for search
•    Source – Entity ,Attribute, Value
•    Defaulting source/Value
10. When an order cannot be cancelled?
A) An order cannot be cancelled if,
•    It has been closed
•    It has already been cancelled
•    A work order is open for an ATO line
•    Any part of the line has been shipped or invoiced
•    Any return line has been returned or credited.
11. When an order cannot be deleted?
A) you cannot delete an order line until there is a need for  recording  reason.
12. What is order type?
A) An order type is the classification of order. It controls the order work flow activity, order number sequence, credit check point and transaction type. Order Type is associated to a work flow process which drives the processing of the order.
13. What are primary and secondary price lists?
A) Every order is associated to a price list as each item on the order ought to have a price. A price list is contains basic list information and one or more pricing lines, pricing attributes, qualifiers, and secondary price lists. The price list that is primarily associated to an order is termed as Primary price list.
The pricing engine uses a Secondary Price list if it cannot determine the price of the item ordered in the Primary price list.
14. What is pick slip? Types?
A) It is an internal shipping document that pickers use to locate items to ship for an order.
•    Standard Pick Slip – Each order will have its own pick slip with in each picking batch.
•    Consolidated Pickslip – Pick slip will have all the orders released in the each picking batch.
15. What is packing slip?
A) It is an external shipping document that accompanies the shipment itemizing the contents of the shipment.

16. What are picking rules?
A) Picking rules define the sources and prioritization of sub inventories, lots, revisions and locators when the item is pick released by order management. They are user defined set of rules to define the priorities order management must use when picking items from finished goods inventory to ship to a customer.
17. Where do you find the order status column?
A) In the base tables, Order Status is maintained both at the header and line level. The field that maintains the Order status is FLOW_STATUS_CODE. This field is available in both the OE_ORDER_HEADERS_ALL and OE_ORDER_LINES_ALL.
18. When the order import program is run it validates and the errors occurred can be seen in?
A) Responsibility: Order Management Super User
     Navigation: Order, Returns > Import Orders > Corrections

Script to update salespersons customer site wise in oracle apps R12

SELECT * FROM HZ_PARTIES WHERE PARTY_NAME LIKE 'DEENA VISION%'; SELECT * FROM HZ_CUST_ACCOUNTS_ALL WHERE PARTY_ID =94043 ; SE...