These instructions apply to learners who have installed an...

12
These instructions apply to learners who have installed an Oracle database server and Oracle client such as the Oracle SQL Developer rather than the Oracle Database Appliance. http://www.oracle.com/technetwork/database/enterprise-edition/databaseappdev-vm-161299.html The database appliance includes an Oracle 12c server, preconfigured database, and Oracle SQL Developer client so you do not need to bother with these instructions. Connecting to a local Oracle database using the SQL Developer or another client is confusing to many learners. It is simple after it is setup, but can be confusing to setup. Before making a connection, you need to install the Oracle server and client. I assume that you have installed Oracle 12c standard edition and the Oracle SQL Developer. I think these notes apply to other Oracle server editions, but I have not tried them with other server editions. You must know the name (SID and Global Database Identifier) of the default database. This name should be ORCL unless you have changed it during the installation process. You must also know the administrative password for the default database. You specified this password during the installation process. If you do not know the password, you will not be able to connect to your default database. Here is a quick way to make a connection. For screen snapshots and details about creating a new user name, you should read the document about making connections to a local Oracle database. (The content is below after this page) You need to create a connection in the SQL Developer before you can execute SQL statements. After opening the SQL Developer, you should see the Connections pane. If you have made previous connections, you will see them in the Connections pane. You can click on the + (plus) icon to create a new connection. You can either create a new user or use an existing, privileged user (SYSTEM). Using the SYSTEM account is easier although you should not use the SYSTEM user on a shared server to create and query tables. Since you have a private server, you can use the SYSTEM user. Here are the property values that you need to provide in the window to create a new connection. The SID is the default database name provided in the configuration step of the installation process. Connection name: any name that you want User Name: SYSTEM Password: you need to use the administrative password that you provided in the configuration step in the installation process Hostname: localhost Port: 1521 SID: ORCL

Transcript of These instructions apply to learners who have installed an...

Page 1: These instructions apply to learners who have installed an ...eecs.csuohio.edu/~sschung/cis611/OracleLocalDatabaseConnections.pdfThe database appliance includes an Oracle 12c server,

These instructions apply to learners who have installed an Oracle database server and Oracle client such as the

Oracle SQL Developer rather than the Oracle Database Appliance.

http://www.oracle.com/technetwork/database/enterprise-edition/databaseappdev-vm-161299.html

The database appliance includes an Oracle 12c server, preconfigured database, and Oracle SQL Developer

client so you do not need to bother with these instructions.

Connecting to a local Oracle database using the SQL Developer or another client is confusing to many

learners. It is simple after it is setup, but can be confusing to setup.

Before making a connection, you need to install the Oracle server and client. I assume that you have installed

Oracle 12c standard edition and the Oracle SQL Developer. I think these notes apply to other Oracle server

editions, but I have not tried them with other server editions. You must know the name (SID and Global

Database Identifier) of the default database. This name should be ORCL unless you have changed it during the

installation process. You must also know the administrative password for the default database. You specified

this password during the installation process. If you do not know the password, you will not be able to connect

to your default database.

Here is a quick way to make a connection. For screen snapshots and details about creating a new user name,

you should read the document about making connections to a local Oracle database. (The content is below

after this page)

You need to create a connection in the SQL Developer before you can execute SQL statements. After opening

the SQL Developer, you should see the Connections pane. If you have made previous connections, you will

see them in the Connections pane. You can click on the + (plus) icon to create a new connection.

You can either create a new user or use an existing, privileged user (SYSTEM). Using the SYSTEM account is

easier although you should not use the SYSTEM user on a shared server to create and query tables. Since you

have a private server, you can use the SYSTEM user.

Here are the property values that you need to provide in the window to create a new connection. The SID is the

default database name provided in the configuration step of the installation process.

• Connection name: any name that you want

• User Name: SYSTEM

• Password: you need to use the administrative password that you provided in the configuration step in

the installation process

• Hostname: localhost

• Port: 1521

• SID: ORCL

Page 2: These instructions apply to learners who have installed an ...eecs.csuohio.edu/~sschung/cis611/OracleLocalDatabaseConnections.pdfThe database appliance includes an Oracle 12c server,

3/30/2016 Making Connections to a Local Database Page 2

You should save and test the connection. You should see a successful test. Select the save password check box

and exit the Connection window.

In the Connection pane, you should see a connection with the name that you provided. Select the + button to

open the connection. After a minute or so, you should see the list of object categories in this database. You can

type SQL statements into the SQL Worksheet and execute statement using run script button. The results of a

SQL statement execution will appear below in the Script Output tab.

Making Connections to a Local Oracle Database This document provides instructions about connecting to a local Oracle database after

installing the Oracle server standard edition. Installation videos do not seem to cover these

details. Learners sometimes can get stuck after installing Oracle, not knowing how to connect

and use a local Oracle database. This document demonstrates creating a connection to a local

database using the SQL Developer and then using the connection to execute SQL statements.

Database Configuration after Oracle Installation

At the end of the installation process, Oracle creates a default database on the host

machine using the Database Configuration Assistant. The most important information that you

provide is the administrative password. You must remember the administrative password to

connect to the default database using the Oracle SQL Developer.

The Database Configuration Assistant generates a message similar to Figure 1 after

completing the Database Configuration Assistant. The message indicates that the default

database has ORCL as the Global Database Name and System Identifier (SID). The message also

indicates that you can use two predefined accounts to connect to the standard database, SYS and

SYSTEM. Oracle has no default passwords for the SYSTEM and SYS accounts. You must use

the administrative password that you specified during the configuration process.

Page 3: These instructions apply to learners who have installed an ...eecs.csuohio.edu/~sschung/cis611/OracleLocalDatabaseConnections.pdfThe database appliance includes an Oracle 12c server,

3/30/2016 Making Connections to a Local Database Page 3

Figure 1: Summary Window for the Database Configuration Assistant

Oracle SQL Developer

You need to download the Oracle SQL Developer from the Oracle Technology Network

site (http://www.oracle.com/technetwork/developer-tools/sql-developer/downloads/index.html).

There is no cost to use the Oracle SQL Developer although you must have a TechNet account.

Creating the Initial Connection

Creating the initial connection to the default database is crucial. After starting the SQL

Developer, you will see the New Gallery window in Figure 2 if you have not previously created

connections. You should select Connections and click the Ok button. An empty window will

appear for creating a connection as shown in Figure 3.

If you have already created connections, you will see the Connections tab as shown in

Figure 3 instead of the New Gallery window. You will only see the connections that you have

already created, not the connections shown in Figure 4. After clicking the + button, the

New/Select Database Connection window opens (Figure 3).

Page 4: These instructions apply to learners who have installed an ...eecs.csuohio.edu/~sschung/cis611/OracleLocalDatabaseConnections.pdfThe database appliance includes an Oracle 12c server,

3/30/2016 Making Connections to a Local Database Page 4

Figure 2: New Gallery Window showing Connections Item

Figure 3: Empty Connection Window

Page 5: These instructions apply to learners who have installed an ...eecs.csuohio.edu/~sschung/cis611/OracleLocalDatabaseConnections.pdfThe database appliance includes an Oracle 12c server,

3/30/2016 Making Connections to a Local Database Page 5

Figure 4: The Connections Tab in the SQL Developer

(Note: You will not see these connections.)

For your initial connection, you should use the SYS account and the administrative

password that you gave in the configuration process. Complete the properties as described in the

following list. Figure 5 shows the completed connection. After you have specified the properties,

you should use the Test button to try the connection. You should see a successful connection.

Click the Save button to save your connection.

• You can choose any name for the connection.

• For the user name, you should type “SYS AS SYSDBA”

• You should use the administrative password that you specified in the configuration

process. Check the Save Password check box.

• The host name is “localhost” because you are connecting to a database on your own

machine.

Page 6: These instructions apply to learners who have installed an ...eecs.csuohio.edu/~sschung/cis611/OracleLocalDatabaseConnections.pdfThe database appliance includes an Oracle 12c server,

3/30/2016 Making Connections to a Local Database Page 6

• The port is 1521.

• The SID is “ORCL”, the database name specified in the configuration process.

Figure 5: Completed Database Connection Window

After completing the connection properties, you can use the connection. To open a

connection, you should right click the connection name in the Connection tab and select the

Connect item. If you are still inside the Connection window, you can click the Connect button.

You will be prompted for the user name and password if you did not enter the password in the

connection properties. After the connection is made, you will see a list of object types in your

connection as shown in Figure 6. After you create objects, you will see them when you select the

object type.

Page 7: These instructions apply to learners who have installed an ...eecs.csuohio.edu/~sschung/cis611/OracleLocalDatabaseConnections.pdfThe database appliance includes an Oracle 12c server,

3/30/2016 Making Connections to a Local Database Page 7

Figure 6: List of Object Types for an Open Connection

Creating another User

Because connecting with SYS AS SYSDBA is highly privileged, I recommend that you

create another user for your work in this course and specialization. In the SQL Worksheet, you

should enter the ALTER SESSION command as shown in Figure 7. You should execute the

command using the Run Script button ( ). In the Script Output pane, you should see a message

that the ALTER SESSION executed. If the ALTER SESSION command executes with an error,

you should skip to the last section in this tutorial. Make sure that you typed the statement

correctly before giving up.

Page 8: These instructions apply to learners who have installed an ...eecs.csuohio.edu/~sschung/cis611/OracleLocalDatabaseConnections.pdfThe database appliance includes an Oracle 12c server,

3/30/2016 Making Connections to a Local Database Page 8

Figure 7: ALTER SESSION Command in the SQL Worksheet

You will then create a new user and grant the DBA role to the new user. You should right

click on the Other Users icon at the bottom of the object list (Figure 6) and select Create User …

You should enter a user name such as LocalUser1 as shown in Figure 8. You also need to create

a password for the new user and select the default tablespace (USERS) and temporary tablespace

(TEMP). In the Roles tab (Figure 9), you should select DBA. The generated SQL code should

appear as shown in Figure 10 if you select the SQL tab. Click the Apply button and close the

window.

Figure 8: Create/Edit User Window

Page 9: These instructions apply to learners who have installed an ...eecs.csuohio.edu/~sschung/cis611/OracleLocalDatabaseConnections.pdfThe database appliance includes an Oracle 12c server,

3/30/2016 Making Connections to a Local Database Page 9

Figure 9: Selecting DBA Role for the New User

Figure 10: Generated SQL Code for the New User

Page 10: These instructions apply to learners who have installed an ...eecs.csuohio.edu/~sschung/cis611/OracleLocalDatabaseConnections.pdfThe database appliance includes an Oracle 12c server,

3/30/2016 Making Connections to a Local Database Page 10

Close the current connection by right clicking on the connection name (Figure 6) and

selecting Disconnect. You should click the + button to create a new connection for the user that

you previously created. You should enter property values as shown in Figure 11. You can enter a

different value for the Connection Name if you want. You need to enter the password that you

gave in Figure 8. Note that you need to use a service name (pdborcl) instead of the ORCL SID

used for your SYS AS SYSDBA connection. You should test and save the connection. You

should use this connection to create and populate tables and write SELECT statements using

your tables as indicated in ungraded exercises and graded assignments.

Figure 11: Database Connection for the New User

Alternative for Failed ALTER SESSION Statement

If the ALTER SESSION statement does not work (Figure 7), you should create another

connection using SYSTEM as the user name. You should use SYSTEM as the user name, not

SYSTEM as SYSDBA. You should use the same administrative password that you provided in

the configuration process. You should use the other connection properties as shown in Figure 5.

You can use this connection to create and populate tables and write SELECT statements using

your tables as indicated in ungraded exercises and graded assignments in the course.

Page 11: These instructions apply to learners who have installed an ...eecs.csuohio.edu/~sschung/cis611/OracleLocalDatabaseConnections.pdfThe database appliance includes an Oracle 12c server,

3/30/2016 Making Connections to a Local Database Page 11

Opening and Using a Connection

After creating and testing a connection, you are ready to use it to execute SQL

statements. To open a connection, you should the connection name in the Connections pane

expand by clicking on the plus symbol by the connection name. You will see a list of object

types for the open connection as depicted in Figure 12. After you create tables, you can see them

by expanding the Tables icon in the object list.

Figure 12: List of Object Types for an Open Connection

You can create and execute SQL statement using the Worksheet. Type a statement and

click on the Run Script button ( ) as depicted in Figure 13. The results are displayed in the

Script Output tab below the Worksheet. You can execute any SQL statement such as CREATE

Page 12: These instructions apply to learners who have installed an ...eecs.csuohio.edu/~sschung/cis611/OracleLocalDatabaseConnections.pdfThe database appliance includes an Oracle 12c server,

3/30/2016 Making Connections to a Local Database Page 12

TABLE and INSERT statements required in Module 3 and SELECT statements required in

Modules 4 and 5.

Figure 13: SQL SELECT Statement Executed in the Worksheet