Tuesday, May 28, 2013

Global Temporary Tables in Oracle

Global temporary table exists solely for your session or whose data persists for the duration of your transaction.

When you create a temporary table, you can specify whether
- it should last for the duration of your session (on commit preserve rows)
- or whether its rows should be deleted when the transaction completes (on commit delete rows)

Unlike a permanent table, a temporary table does not automatically allocate space when it is created. Space will be dynamically allocated for the table as rows are inserted:

create global temporary table EMP
(
    EMPNO NUMBER(4),
    ENAME VARCHAR2(9),
    SALARY NUMBER
)
on commit preserve rows;

 Global temporary tables are very useful in optimizing a oracle transaction basically a large PL/SQL block, where we need to hold a large set of data temporary.




Tuesday, May 21, 2013

Create External Table from CSV File

Follow these simple Steps 
 
1) Create a Directory
2) Grant Read/Write Permission to that Directory
3) Place your CSV file in that directory at OS Level
4) Create EXTERNAL Table

For Example: 
 
1) create or replace directory MYCSV as 'E:\test'; 
 Note: E:\test has to be physical location on disk.
 
2) grant read, write on directory MYCSV to scott;

3) Put your csv file on E:\test at OS level

4) create table ext_table
   (
     ENAME VARCHAR2(10),
     DNAME VARCHAR2(14),
     JOB VARCHAR2(9)
   )
   organization external
   (
     type ORACLE_LOADER
     default directory MY_DIR
     access parameters 
     (
       records delimited by newline
       fields terminated by "~"
     )
     location ('testfile.csv')
   )
   reject limit unlimited;

   
To create this CSV File you may use following command

set pagesize 0 newpage 0 feedback off

select ENAME || '~' || DNAME || '~' || JOB from SCOTT.EMP, SCOTT.DEPT 
WHERE EMP.DEPTNO=DEPT.DEPTNO;

spool E:\test\testfile.csv
/
spool off


Oracle Default Username and Password

Here is the complete List of Default username and passwords

User Name Default Password Script (in $ORACLE_HOME) Additional Information
ANONYMOUS ANONYMOUS /rdbms/admin/catqm.sql Allows HTTP access to Oracle XML DB.
APEX_PUBLIC_USER APEX_PUBLIC_USER /apex/apexins.sql The Oracle Database Application Express account
BI CHANGE_ON_INSTALL / BI /demo/schema/bus_intelligence/bi_main.sql Sample Schema
CTXSYS CHANGE_ON_INSTALL / CTXSYS /ctx/admin/ctxsys.sql To administer Oracle Text
DBSNMP DBSNMP /rdbms/admin/catsnmp.sql Used by the Management Agent of OEM to monitor and manage DB
DIP DIP /rdbms/admin/catdip.sql for Oracle Internet Directory-enabled Oracle Label Security
EXFSYS EXFSYS /rdbms/admin/exfsys.sql Used internally and enables us to build complex PL/SQL rules and expressions
FLOWS_FILES FLOWS_FILES /apex/apexins.sql Owns objects created during installation of Oracle Database Application Express
HR CHANGE_ON_INSTALL / HR /demo/schema/human_resources/hr_main.sql Sample Schema
IX CHANGE_ON_INSTALL / IX /demo/schema/info_exchange/ix_main.sql Sample Schema
MDDATA MDDATA /md/admin/catmd.sql Used by Oracle Spatial Feature
MDSYS MDSYS /ord/admin/ordinst.sql The Oracle Spatial and Oracle Multimedia Locator administrator account
MGMT_VIEW MGMT_VIEW /sysman/admin/emdrep/bin/RepManager Used by Oracle Enterprise Manager Database Control
OE CHANGE_ON_INSTALL / OE /demo/schema/order_entry/oe_main.sql Sample Schema
OLAPSYS MANAGER / OLAPSYS /olap/admin/amdsys.sql Owns the OLAP Catalog, has been deprecated
ORACLE_OCM ORACLE_OCM /rdbms/admin/catocm.sql Associate the configuration information of Database instance with OracleMetaLink
ORDPLUGINS ORDPLUGINS /ord/admin/ordinst.sql Enables Oracle Database to store, manage and retrieve heterogeneous media data
ORDSYS ORDSYS /ord/admin/ordinst.sql Oracle Multimedia administrator account
OUTLN OUTLN /rdbms/admin/sql.bsq (after recovery) Provides plan stability prevents certain db environment changes from affecting performance characteristics
OWBSYS OWBSYS /owb/UnifiedRepos/cat_owb.sql For administrating the Oracle Warehouse Builder repository
PM CHANGE_ON_INSTALL / PM /demo/schema/product_media/pm_main.sql Sample Schema
SCOTT TIGER /rdbms/admin/utlsampl.sql Sample Schema
SH CHANGE_ON_INSTALL / SH /demo/schema/sales_history/sh_main.sql Sample Schema
SI_INFORMTN_SCHEMA SI_INFORMTN_SCHEMA /ord/admin/ordinst.sql Stores the information views for the SQL/MM Still Image Standard
SPATIAL_CSW_ADMIN_USR SPATIAL_CSW_ADMIN_USR /md/admin/sdocswpv.sql Used by Oracle Spatial CSW Cache Manager to load record-type metadata andrecord instances
SPATIAL_WFS_ADMIN_USR SPATIAL_CSW_ADMIN_USR /md/admin/sdowfspv.sql Used by Oracle Spatial WFS Cache Manager to load all feature type metadata and feature instances
SYS CHANGE_ON_INSTALL /rdbms/admin/sql.bsq (after recovery) An account used to perform database administration tasks
SYSMAN OEM_TEMP /rdbms/admin/sql.bsq (after recovery) The account used to perform Oracle Enterprise Manager administration tasks
SYSTEM MANAGER /rdbms/admin/sql.bsq (after recovery) Default generic database administrator account
WMSYS WMSYS /rdbms/admin/owmctab.plb Used to store the metadata information for Oracle Workspace Manager.
XDB CHANGE_ON_INSTALL / XDB /rdbms/admin/catqm.sql Provides high-performance XML storage and retrieval
XS$NULL
/rdbms/admin/sql.bsq (after recovery) Represents the absence of a user in a session


Monday, May 6, 2013

Documents that may help you get a job



I have 4 documents that may help you get a job.

1) A checklist with 160 items.
The items are divided into these categories:
• Marketing yourself
• Keeping track of the places you submit your resume to
• Preparing for the interview
• Immediately before the interview
• During the interview
• Immediately after the interview
• After a rejection letter
• After a offer letter
• Business cards and signature block for all correspondence

2) an outline of important things to say and do at the interview.
A document to take to the interview. There are 63 items on this outline. The items are divided into these categories:
• Tell me about yourself
• The top 3 points you want to make sure you get across.
• What makes me different:•
• Job related questions to ask at the beginning of the interview. For example:
• Job related questions to ask at the end of the interview. For example:
• My Strengths:
• My Weaknesses:
• Future employment goals
• Gap in work
• Elevator speech

3) An excel spreadsheet used to keep track of:
• The places you have applied for work at
• Each time you have communicated with those places.
• What was said and if it was an email, phone call, in person interview, phone interview etc.
• The phone number, address etc. of the head hunters and employers

4) A document is all about cover letters.
Fallow up letters, letters of introduction, post interview letter, post rejection latter etc


Thursday, April 25, 2013

Setting Up AUTOTRACE in SQL*Plus



AUTOTRACE in SQL*Plus:

SQL*Plus provides an AUTOTRACE facility that allows us to see the execution plans of the queries we’ve executed and the resources they used. The report is generated after successful SQL DML.There is more than one way to configure the AUTOTRACE facility,
But the following is a recommended route:

1. Access cd $ORACLE_HOME/rdbms/admin.
2. Log into SQL*Plus as any user with CREATE TABLE and CREATE PUBLIC
SYNONYM privileges.
3. Run @UTLXPLAN to create a PLAN_TABLE for use by AUTOTRACE.
4. Run CREATE PUBLIC SYNONYM PLAN_TABLE FOR PLAN_TABLE, so that everyone
can access this table without specifying a schema.
5. Run GRANT ALL ON PLAN_TABLE TO PUBLIC, so that everyone can use this
table.
6. Exit SQL*Plus and change directories as follows:
cd $ORACLE_HOME/sqlplus/admin.
7. Log into SQL*Plus as a SYSDBA.
8. Run @PLUSTRCE.
9. Run GRANT PLUSTRACE TO PUBLIC.
You can test your setup by enabling AUTOTRACE and executing a simple query:
SQL> set AUTOTRACE traceonly
SQL> select * from emp, dept
2 where emp.deptno=dept.deptno;

14 rows selected.

Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT Optimizer=CHOOSE
1 0 MERGE JOIN
Setting Up
xxii
2 1 SORT (JOIN)
3 2 TABLE ACCESS (FULL) OF 'DEPT'
4 1 SORT (JOIN)
5 4 TABLE ACCESS (FULL) OF 'EMP'

Statistics
----------------------------------------------------------
0 recursive calls
8 db block gets
2 consistent gets
0 physical reads
0 redo size
2144 bytes sent via SQL*Net to client
425 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
2 sorts (memory)
0 sorts (disk)

14 rows processed

SQL> set AUTOTRACE off


Wednesday, April 24, 2013

Arithmetic Expressions in SQL



=> What is Arithmetic in SQL?
  
   Arithmetic in SQL includes

    + Addition
    -  Subtraction
    * Multiplication
    / Division

 We use arithmetic operators in any clause of a SQL statement except the from clause 

=> Using arithmetic expressions in select statement

 For example assume if we want to calculate salary increase by 400 you will write below select statement

SELECT EMPNO, DEPT, SAL, SAL+400
FROM EMP;


EMPNO    SAL     SAL+400
-------    ---------- ----------
   7369        800        1200
   7499       1600       2000
   7521       1250       1650
   7566       2975       3375
   7654       1250       1650
   7698       2850       3250
   7782       2450       2850

=>Rules of Precedence:

In SQL statements, arithmetic expressions are evaluated according to a standard order of operations.
Multiplication and division take priority over addition and subtraction.
If operators within an expression are of the same priority then the expression is evaluated from left to right.

=> Using Parentheses:

We use parentheses to change the order of evolution.    

EXAMPLE:

4*(5+5)=40

(5+5) Evaluate first
4*     Evaluate second

=>Arithmetic Expression with NULL Values

If we perform arithmetic on null values, the result is NULL

 EXAMPLE

10+NULL=NULL
10- NULL=NULL
NULL*10=NULL
NULL/10=NULL
10+0=10
10-0=10
0*10=10
0/10=10