Tuesday, October 14, 2008

Using Oracle sql*plus on windows

First we need generate a "Local Net Service Name" for the oracle service. This "Name" is just like alias. With this name, Oracle know how to find the database.

Using "Net Configuration Assistant" to generate "Local Net Service Name configuration".

Once the wizard is finished, it will create a entry in ORACLE_CLIENT_INSTALL_DIR\NETWORK\ADMIN\tnsnames.ora. For example:
# tnsnames.ora Network Configuration File: C:\oracle\product\10.2.0\client_2\network\admin\tnsnames.ora
# Generated by Oracle configuration tools.

ORCL_109 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.10.2.109)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = orcl)
)
)


Then open a command window and type
sqlplus username/password@ORCL_109

Then it will connect the oracle database.

If there are multiple clients installed on the windows, make sure the sqlplus you executed is in the same client with the tnsnames.ora

Run sql script in sqlplus

To execute a script file in SQLPlus, type @ and then the file name.

SQL > @{file}

For example, if your file was called script.sql, you'd type the following command at the SQL prompt:

SQL > @script.sql

The above command assumes that the file is in the current directory. (ie: the current directory is usually the directory that you were located in before you launched SQLPlus.)


If you need to execute a script file that is not in the current directory, you would type:

SQL > @{path}{file}

For example:

SQL > @/oracle/scripts/script.sql

This command would run a script file called script.sql that was located in the /oracle/scripts directory.

No comments:

Post a Comment