Showing posts with label Tools. Show all posts
Showing posts with label Tools. Show all posts

Friday, August 15, 2008

How to load data using external table into oracle database

Using SQL*Loader we can load data from flat data file to oracle database which is described in How to load data using sql*loader into oracle database. The external tables feature is a complement to existing SQL*Loader functionality.

In the following section, I will show with an example of how you can load data using external table.

1)Prepare your data file.
This file is where my input data is which will be loaded to database table. Here my datafile data.dat.txt is as follows,
045 Faruk
012 Arju
022 Momin

2)Create the database directory where data file resides.
This data file is not oracle data file rather it is the file where data resides. This oracle database directory is just a operating system path synonym. This directory is the logical path of physical datafile path. As my data file is in the directory c:\oracle\data\ so I create the directory as

SQL> create directory exter_dir as 'E:\oracle\work';

Directory created.

Note that user must have grant create any directory privilege. If other user create the directory then current user must have read access to the directory.
SQL> GRANT READ ON DIRECTORY exter_dir TO Arju;
Here current user is Arju. So execute above statement with a user that have privilege.

3)Prepare the original Table: You should ignore this step if your desired table already exist in your database. If not exist then create a new one. I created as,

SQL> create table std_name (id varchar2(10), name varchar2(20));
Table created.

4)Create the external table: I created the external table as,
SQL> create table external_tab(id char(4),
name char(10))
organization external
(default directory exter_dir
ACCESS parameters
(records delimited by newline
fields (id char(4), name char(10)
)
)
location ('data.dat.txt')
);


Table created.

Here "organizational external" indicates this one is external table.
"default directory" indicates the name of the directory where data file resides.
"location" indicates the name of the data file.

In this phase data from the data file is loaded into the external table. You can check whether it is successfully load or not by issuing,
SQL> select * from external_tab;
ID NAME
---- ----------
045 Faruk
012 Arju
022 Momin

5) Load the data from the external table to database table:
Load data from external_tab into the table std_name by,

SQL> insert into std_name select * from external_tab;
3 rows created.

SQL> commit;
Commit complete
.

6)Test the data.
SQL> select * from std_name;

ID NAME
---------- --------------------
045 Faruk
012 Arju
022 Momin

Tuesday, August 12, 2008

Various Tools for Installing, Configuring Oracle RAC

1)Oracle Universal Installer (OUI)- After configuring the pre-installation tasks of the nodes OUI installs the Oracle Clusterware and the Oracle Database software with Oracle RAC. It also can install oracle software on the other nodes using a network connection.

2)Cluster Verification Utility (CVU)- The CVU is a command-line tool. It is very useful to check the nodes for preinstallation as well as postinstallation requirements of the cluster environment. In fact OUI runs the CVU after the Oracle Clusterware installation to verify the environment.

3)Oracle Enterprise Manager- With EM it is easy to configure RAC environments. It has both the Database Control and Grid Control graphical user interfaces (GUIs).

4)Server Control (SRVCTL)- SRVCTL is a command-line interface that you can use to manage an Oracle RAC database from a single point. Using SRVCTL you can start or stop or manage any instance on the cluster.

5)Cluster Ready Services Control (CRSCTL)- CRSCTL is a command-line tool that you can use to manage Oracle Clusterware. You can use CRSCTL to start and stop Oracle Clusterware and to determine the current status of your Oracle Clusterware installation.

6)Oracle Interface Configuration Tool (OIFCFG)- OIFCFG is a command-line tool which you can use to allocate and de-allocate network interfaces to components. You can use OIFCFG to direct components to use specific network interfaces and to retrieve component configuration information.

7)OCR Configuration Tool (OCRCONFIG)- OCRCONFIG is a command-line tool for OCR administration. You can also use the OCRCHECK and OCRDUMP utilities to troubleshoot configuration problems that affect the OCR.

Sunday, July 20, 2008

How to Load or copy data from SQL Server or excel to Oracle

If you want any software and automatic conversion to migrate non oracle database to oracle then you can use Oracle SQL Developer Migration Workbench which can be used to migrate Microsoft Access, Microsoft SQL Server, MySQL and Sybase databases to Oracle.

However you wish to load a table sample data from non-oracle to oracle database. You may wish to do the task manually. Below is the manual procedure by which you can load data to oracle. It explain also if you have data in a flat file then how you can can able to load it into your oracle database.

Though at first time it may seem to you a difficult one but in this post I will try to make it easy. The steps involved to copy SQL Server data to an oracle database is given below. However this procedure is also applied if you want to import data from an excel flat file to an oracle database.

Step 1: Export Data to a CSV file:

You have to proceed table by table if you want to copy data from SQL Server database to Oracle.
For each table data you have to export data to a flat file and convert it to a CSV file.

Don't bother with .CSV or name CSV extension. It is nothing just abbreviate form of Comma Separated Values. If you save a normal text file with the comma between the record parts then that file is a CSV file.

You can directly export data in a CSV file from SQL SERVER database or just export data to a flat file and then convert it to a CSV file.

Export data to a flat file is discussed in http://arjudba.blogspot.com/2008/05/how-to-export-data-to-flat-file.html. Now open this file with excel and from excel file you can easily convert to a CSV file. To do it just open the excel file and >click file manu and >select save as. A pop up window will be displayed. Go to Save as Type section and select .CSV extention and click on save button. You now have got the .CSV file and you have finished step 1.

It will be more easily if you can directly export data to a CSV format. Easily you can do by separating column value of the table with an extension.

Like, you want to copy or load emp table from sql server to oracle.
SQL> desc emp;
Name Null? Type
----------------------------------------- -------- ----------------------------
EMP_NO NUMBER
EMP_NAME VARCHAR2(10)
DEPT_NO NUMBER
SQL> select emp_no ||','||emp_name ||','||dept_no from emp;

EMP_NO||','||EMP_NAME||','||DEPT_NO
--------------------------------------------------------------------------------
1,ddd,10
2,aaa,11
3,bbb,10


Save the output to a emp.csv file.

Step 2: Create a Control file:
In this are emp.csv is called datafile where data of the table to be loaded exists. Never mix with datafile of oracle with this emp.csv. This one is SQL*Loader datafile and oracle datafile are of .dbf extension. After successfully creating data file create a control file. Also don't mix this control file with database control file. This control file instructs SQL*loader how to load data.

Here is the control file. In my other posts of my blog I will go detail with it.

LOAD DATA
INFILE '/export/home/oracle/emp.dat'
INTO TABLE emp
FIELDS TERMINATED BY ','
(emp_no CHAR(2), emp_name CHAR(10), dept_no CHAR(2))

Note that whether datatype is number or varchar2 in control file it is specified as CHAR.
I save the control file as emp.ctl


Step3: Go to oracle database and create the emp table.

I created as below.
CREATE TABLE ARJU.EMP
( EMP_NO NUMBER,
EMP_NAME VARCHAR2(10),
DEPT_NO NUMBER
)TABLESPACE USER_TBS;
Table created.

Step 4: Invoke SQL*Loader and load data.
Copy datafile, control file to the oracle database and invoke sqlldr to load data.
$sqlldr arju/a control=/export/home/oracle/emp.ctl

SQL*Loader: Release 10.2.0.1.0 - Production on Sun Jul 20 06:21:28 2008

Copyright (c) 1982, 2005, Oracle. All rights reserved.

Commit point reached - logical record count 3
Let's check logfile if any error.
bash-3.00$ cat emp.log

SQL*Loader: Release 10.2.0.1.0 - Production on Sun Jul 20 06:21:28 2008

Copyright (c) 1982, 2005, Oracle. All rights reserved.

Control File: /export/home/oracle/emp.ctl
Data File: /export/home/oracle/emp.dat
Bad File: /export/home/oracle/emp.bad
.
.

Total logical records skipped: 0
Total logical records read: 3
Total logical records rejected: 0
Total logical records discarded: 0

Step 5: See the data from database and You are done:
SQL> select * from emp;


EMP_NO EMP_NAME DEPT_NO
---------- ---------- ----------
1 ddd 10
2 aaa 11
3 bbb 10