26
เอกสารประกอบการบรรยายวิชา ระบบการจัดการฐานข้อมูล อ.ดร. สมคิด สุทธิธารธวัช ม.ราชภัฏพระนคร 1 Chapter 4 Introducing Oracle Database XE 11g R2 SOMKID SOOTITANTAWAT: Database Management Systems Oracle Database Express Edition 11g Release 2 (11.2) for Windows x32 September 2011 Oracle Database 11g Express Edition (Oracle Database XE) is a free version of the world's most capable relational database. Oracle Database XE is easy to install, easy to manage, and easy to develop with. With Oracle Database XE, you use an intuitive, browser-based interface to administer the database, create tables, views, and other database objects, import, export, and view table data, run queries and SQL scripts, and generate reports. 2 Oracle Database XE is a great starter database for: Developers working on PHP, Java, .NET, XML, and Open Source applications DBAs who need a free, starter database for training and deployment Independent Software Vendors (ISVs) and hardware vendors who want a starter database to distribute free of charge SOMKID SOOTITANTAWAT: Database Management Systems 3 Oracle Database XE is a great starter database for: Educational institutions and students who need a free database for their curriculum With Oracle Database XE, you can now develop and deploy applications with a powerful, proven, industry- leading infrastructure, and then upgrade when necessary without costly and complex migrations. Oracle Database XE can be installed on any size host machine with any number of CPUs (one database per machine), but XE will store up to 11GB of user data, use up to 1GB of memory, and use one CPU on the host machine. SOMKID SOOTITANTAWAT: Database Management Systems 4

Chapter 4 · Chapter 4 Introducing Oracle ... queries and SQL scripts, and generate reports. 2 Oracle Database XE is a great ... Oracle 11g XE Install

  • Upload
    tranthu

  • View
    246

  • Download
    8

Embed Size (px)

Citation preview

Page 1: Chapter 4 · Chapter 4 Introducing Oracle ... queries and SQL scripts, and generate reports. 2 Oracle Database XE is a great ... Oracle 11g XE Install

เอกสารประกอบการบรรยายวชา ระบบการจดการฐานขอมล

อ.ดร. สมคด สทธธารธวช ม.ราชภฏพระนคร 1

Chapter 4

Introducing Oracle Database XE 11g R2

SOMKID SOOTITANTAWAT: Database Management Systems

Oracle Database Express Edition 11g Release 2 (11.2)for Windows x32

September 2011 Oracle Database 11g Express Edition (Oracle Database

XE) is a free version of the world's most capable relational database. Oracle Database XE is easy to install, easy to manage, and easy to develop with. With Oracle Database XE, you use an intuitive, browser-based interface to administer the database, create tables, views, and other database objects, import, export, and view table data, run queries and SQL scripts, and generate reports.

2

Oracle Database XE is a great starter database for:

Developers working on PHP, Java, .NET, XML, and Open Source applications

DBAs who need a free, starter database for training and deployment

Independent Software Vendors (ISVs) and hardware vendors who want a starter database to distribute free of charge

SOMKID SOOTITANTAWAT: Database Management Systems 3

Oracle Database XE is a great starter database for: Educational institutions and students who need a

free database for their curriculum With Oracle Database XE, you can now develop and

deploy applications with a powerful, proven, industry-leading infrastructure, and then upgrade when necessary without costly and complex migrations.

Oracle Database XE can be installed on any size host machine with any number of CPUs (one database per machine), but XE will store up to 11GB of user data, use up to 1GB of memory, and use one CPU on the host machine.

SOMKID SOOTITANTAWAT: Database Management Systems 4

Page 2: Chapter 4 · Chapter 4 Introducing Oracle ... queries and SQL scripts, and generate reports. 2 Oracle Database XE is a great ... Oracle 11g XE Install

เอกสารประกอบการบรรยายวชา ระบบการจดการฐานขอมล

อ.ดร. สมคด สทธธารธวช ม.ราชภฏพระนคร 2

XE also has limitations:

The maximum database size is 11 GB. The maximum amount of RAM XE can use is 1

GB. Only one instance of Oracle XE can be

installed on a single computer. XE uses only a single CPU so it does not

distribute operations between several CPUs.

SOMKID SOOTITANTAWAT: Database Management Systems 5

Oracle Database 11g Editions Comparison Chart

Compare the features of Oracle® Database 11g Standard Edition One, Standard Edition, Enterprise Edition and the previous version, Oracle Database 10g Express Edition.

PDF file

SOMKID SOOTITANTAWAT: Database Management Systems 6

Oracle 11g XE Install When you download the software from Oracle, you’ll

need an account and you’ll need to accept the license agreement.

1. You’re prompted to accept the license agreement and can’t proceed without doing it.

SOMKID SOOTITANTAWAT: Database Management Systems 7

Oracle 11g XE Install (Con.) 2. After accepting the license agreement you can

download the software.

3. Unlike, the Oracle 10g XE MSI file, you’ve downloaded a compressed (OracleXE112_Win32.zip) file, and you’ll need to explode the zip file and write it to a directory. When you write it to a directory, it looks like the following and you double click on the setup.msi file.

SOMKID SOOTITANTAWAT: Database Management Systems 8

Page 3: Chapter 4 · Chapter 4 Introducing Oracle ... queries and SQL scripts, and generate reports. 2 Oracle Database XE is a great ... Oracle 11g XE Install

เอกสารประกอบการบรรยายวชา ระบบการจดการฐานขอมล

อ.ดร. สมคด สทธธารธวช ม.ราชภฏพระนคร 3

Oracle 11g XE Install (Con.)

SOMKID SOOTITANTAWAT: Database Management Systems 9

It’s recommended that you right click on the setup.msi program and run it as the Administrator. If you’ve not disabled Microsoft User Access Controls (UAC), I’d do that first.

Oracle 11g XE Install (Con.)

SOMKID SOOTITANTAWAT: Database Management Systems 10

4. After launching the setup.msi file, you see the Install Shield wizard screen while the file loads, like this:

Oracle 11g XE Install (Con.)

SOMKID SOOTITANTAWAT: Database Management Systems 11

After launching the setup.msi file, and loading the MSI file, you see the first dialog box of the installation. Click the Next button to start the installation.

Oracle 11g XE Install (Con.)

SOMKID SOOTITANTAWAT: Database Management Systems 12

5. The second dialog box is the license for the installation. Click the I accept the terms in the license agreement. radio button and then the Next button.

Page 4: Chapter 4 · Chapter 4 Introducing Oracle ... queries and SQL scripts, and generate reports. 2 Oracle Database XE is a great ... Oracle 11g XE Install

เอกสารประกอบการบรรยายวชา ระบบการจดการฐานขอมล

อ.ดร. สมคด สทธธารธวช ม.ราชภฏพระนคร 4

Oracle 11g XE Install (Con.)

SOMKID SOOTITANTAWAT: Database Management Systems 13

6. The third dialog box lets you accept the default location or provide an override location. If you accept the default location, click the Next button to continue.

Oracle 11g XE Install (Con.)

SOMKID SOOTITANTAWAT: Database Management Systems 14

7. The fourth dialog box lets you specify the TNS, MTS, and HTTP Ports. The default values are shown in the following screen shot but I’ve change my TNS port to 1621, which you’ll see later. Click the Next button to continue.

Oracle 11g XE Install (Con.)

SOMKID SOOTITANTAWAT: Database Management Systems 15

8. The fifth dialog box lets you enter the password for the SYS and SYSTEM users. You must enter it twice and naturally they must match each other. Click the Next button to continue.

Oracle 11g XE Install (Con.)

SOMKID SOOTITANTAWAT: Database Management Systems 16

9. The sixth dialog box lets you see the configuration options you’ve chosen. Note that this installation is using a TNS port of 1621 rather than the default of 1521. Click the Next button to continue.

Page 5: Chapter 4 · Chapter 4 Introducing Oracle ... queries and SQL scripts, and generate reports. 2 Oracle Database XE is a great ... Oracle 11g XE Install

เอกสารประกอบการบรรยายวชา ระบบการจดการฐานขอมล

อ.ดร. สมคด สทธธารธวช ม.ราชภฏพระนคร 5

Oracle 11g XE Install (Con.)

SOMKID SOOTITANTAWAT: Database Management Systems 17

10. The seventh dialog box lets you see the progress bar, take a break it can run for two or three minutes. Click the Next button to continue.

Oracle 11g XE Install (Con.)

SOMKID SOOTITANTAWAT: Database Management Systems 18

11. The last dialog box lets you see that you’ve installed the product. Click the Finish button to complete the installation.

ตดตงกบ Windows XP right click ทต ว setup.exe กด properties กด tab "Compatibility" เลอก Run this program in

compatibility mode for เลอกเปน windows XP กด ok แลว run setup.exe ใหม

SOMKID SOOTITANTAWAT: Database Management Systems 19

So What Was Installed After the installation has ended, let’s have

a look at the things that were installed. Services Programs

SOMKID SOOTITANTAWAT: Database Management Systems 20

Page 6: Chapter 4 · Chapter 4 Introducing Oracle ... queries and SQL scripts, and generate reports. 2 Oracle Database XE is a great ... Oracle 11g XE Install

เอกสารประกอบการบรรยายวชา ระบบการจดการฐานขอมล

อ.ดร. สมคด สทธธารธวช ม.ราชภฏพระนคร 6

Services If you open the computer management and have a look

at the services installed, you’ll find five new services.

SOMKID SOOTITANTAWAT: Database Management Systems 21

Service ประเภทของการเปดใชงาน ในแบบทเปน Automatic ซงหมายถง เมอปด เปดเครองขนมาใหมทกครงจะมการเปดใชงาน Oracle

Service แบบอตโนมตทกครง สงผลใหเครองทางานชาลงตอนเปดเครอง

Services (Cons.) OracleServiceXE

This is the actual database engine.เมอ Service น ถกเปดใชงาน ทาใหเราสามารถใช

งานขอมลของฐานขอมลได ไมวาจะเปนการเรยกดขอมล

การเพม ลบ แกไขขอมลในฐานขอมล ชอ Service ลงทาย

ดวย XE โดยท XE คอชอฐานขอมล

SOMKID SOOTITANTAWAT: Database Management Systems 22

Services (Cons.) OracleXETNSListener

This service is responsible for listening to incoming connections and passing successful connections to the database engine. Note that if this service is down, you won’t be able to connect to the database remotely. Existing connections won't be affected.

Service น ถกเปดใชงานจะทาใหเครองลกขายสามารถ

ตอเชอมเขามาใชงานระบบจดการฐานขอมลได

SOMKID SOOTITANTAWAT: Database Management Systems 23

Services (Cons.) โดยปกต เครองมการตดตง Oracle จะตองมการ

เปด Oracle Services 2 ตวน เพอทาใหผใชงาน

สามารถใชโปรแกรม เชน SQL Plus, SQL

Developer หรอ โปรแกรมอนๆ ตดตอเขามาใช

งานขอมลในฐานขอมลได

SOMKID SOOTITANTAWAT: Database Management Systems 24

Page 7: Chapter 4 · Chapter 4 Introducing Oracle ... queries and SQL scripts, and generate reports. 2 Oracle Database XE is a great ... Oracle 11g XE Install

เอกสารประกอบการบรรยายวชา ระบบการจดการฐานขอมล

อ.ดร. สมคด สทธธารธวช ม.ราชภฏพระนคร 7

Configuring Oracle Startup Options

Control Panel > Administrative Tools > Services

OR My Computer > Manage > Service and

Application > Services

SOMKID SOOTITANTAWAT: Database Management Systems 25

Configuring Oracle Startup Options

SOMKID SOOTITANTAWAT: Database Management Systems 26

Configuring Oracle Startup Options

SOMKID SOOTITANTAWAT: Database Management Systems 27

ทดสอบเชอมตอเขาไปยง Oracle

เปดหนาจอ Command ใชคาสง

C:\SQLPLUS system/oracle

C:\SQLPLUS / as sysdba

C:\sqlplus sys/oracle as sysdba

SOMKID SOOTITANTAWAT: Database Management Systems 28

Admin User :

system

Admin User: sys

Page 8: Chapter 4 · Chapter 4 Introducing Oracle ... queries and SQL scripts, and generate reports. 2 Oracle Database XE is a great ... Oracle 11g XE Install

เอกสารประกอบการบรรยายวชา ระบบการจดการฐานขอมล

อ.ดร. สมคด สทธธารธวช ม.ราชภฏพระนคร 8

ทดสอบเชอมตอเขาไปยง Oracle

SOMKID SOOTITANTAWAT: Database Management Systems 29

ทดสอบเชอมตอเขาไปยง Oracle

SOMKID SOOTITANTAWAT: Database Management Systems 30

ทดสอบเชอมตอเขาไปยง Oracle

SOMKID SOOTITANTAWAT: Database Management Systems 31

ออกจาก SQL PLUS

SQL > EXIT

SOMKID SOOTITANTAWAT: Database Management Systems 32

Page 9: Chapter 4 · Chapter 4 Introducing Oracle ... queries and SQL scripts, and generate reports. 2 Oracle Database XE is a great ... Oracle 11g XE Install

เอกสารประกอบการบรรยายวชา ระบบการจดการฐานขอมล

อ.ดร. สมคด สทธธารธวช ม.ราชภฏพระนคร 9

Programs In start menu, few new programs are added. Actually,

most of these programs are batch scripts:

SOMKID SOOTITANTAWAT: Database Management Systems 33

SQL Plus เปนโปรแกรมทมมาพรอมกบการตดตง Oracle

SQL Plus ถกใชเปนตวกลางใหเราสามารถใชคาสง

SQL เพอทางานกบ Oracle ได

SOMKID SOOTITANTAWAT: Database Management Systems 34

Programs (Cons.)

SOMKID SOOTITANTAWAT: Database Management Systems 35

Programs (Cons.) Get Started opens a web site used for investigating

storage, the amount of disk space used by tablespaces or drill to segments

current sessions and basic information about the sessions such as client and application information and active SQL statement

parameters show current initialization parameter values.

SOMKID SOOTITANTAWAT: Database Management Systems 36

Page 10: Chapter 4 · Chapter 4 Introducing Oracle ... queries and SQL scripts, and generate reports. 2 Oracle Database XE is a great ... Oracle 11g XE Install

เอกสารประกอบการบรรยายวชา ระบบการจดการฐานขอมล

อ.ดร. สมคด สทธธารธวช ม.ราชภฏพระนคร 10

37SOMKID SOOTITANTAWAT: Database Management Systems

You’ve now installed Oracle Database 11g Express Edition. You can start the command line by

typing sqlplus system/password in command shell or

the Get Started option in your Program Menus, as shown below.

You should see this console when you launch Get Started or manually type

http://localhost:8080/apex.

SOMKID SOOTITANTAWAT: Database Management Systems 38

The Database home page is a Web browser-based interface for performing

various database administration operations, including the following: Monitoring database storage Monitoring database sessions Viewing database initialization parameters

The Oracle Database XEhome page appears:

SOMKID SOOTITANTAWAT: Database Management Systems 39

แนะนา User ทเกดจากการตดตง Oracle

Admin User :เชอมตอเขาใชงาน Oracle ไดทนท หลงตดตงเสรจลง

system

sys

Normal User :เชอมตอเขาใชงาน Oracle ไมได

ตองให Admin user ใชคาสงปลดลอคใหกอน

SOMKID SOOTITANTAWAT: Database Management Systems 40

Page 11: Chapter 4 · Chapter 4 Introducing Oracle ... queries and SQL scripts, and generate reports. 2 Oracle Database XE is a great ... Oracle 11g XE Install

เอกสารประกอบการบรรยายวชา ระบบการจดการฐานขอมล

อ.ดร. สมคด สทธธารธวช ม.ราชภฏพระนคร 11

เรมตนใชงาน SQL Plus กอนอน ใหแกไขการแสดงตวอกษรใหเปนภาษาองกฤษ

C:\REGEDIT

SOMKID SOOTITANTAWAT: Database Management Systems 41

เรมตนใชงาน SQL Plus คลกเลอก HKEY_LOCAL_MACHINE > SOFTWARE >

ORACLE

คลกคาวา KEY_XE

ทางดานขวา จะมรายชอตวแปรแสดงขนมา จะพบวาตวแปร

NLS_LANG มคาเปน THAI_THAILAND.TH8TISASCII

SOMKID SOOTITANTAWAT: Database Management Systems 42

เรมตนใชงาน SQL Plus (ตอ)

SOMKID SOOTITANTAWAT: Database Management Systems 43

เรมตนใชงาน SQL Plus (ตอ)

ให Double click ตรงตวแปร NLS_LANG

ใหเปลยนคาใน

ชอง Value data:

เปน AMERICAN_AMERICA.TH8TISASCII

คลก OK

ไปท เมน File > ExitSOMKID SOOTITANTAWAT: Database Management Systems 44

Page 12: Chapter 4 · Chapter 4 Introducing Oracle ... queries and SQL scripts, and generate reports. 2 Oracle Database XE is a great ... Oracle 11g XE Install

เอกสารประกอบการบรรยายวชา ระบบการจดการฐานขอมล

อ.ดร. สมคด สทธธารธวช ม.ราชภฏพระนคร 12

เรมตนใชงาน SQL Plus (ตอ)

C:\>SQLPLUS system/oracle

SOMKID SOOTITANTAWAT: Database Management Systems 45

เรมตนใชงาน SQL Plus (ตอ)

All Programs > Oracle Database 11g Express

Edition > Run SQL Command Line

SQL> connect system/oracle

SOMKID SOOTITANTAWAT: Database Management Systems 46

SQL>select * from V$VERSION;

SOMKID SOOTITANTAWAT: Database Management Systems 47

Unlock User:hr Using the SQL Plus 1. Display the SQL command prompt window. 2. Connect as the SYSTEM user:

Type: connect Enter user-name: system Enter password: <password-for-system>

3. Enter the following statement to unlock the HR account:

SQL> ALTER USER hr ACCOUNT UNLOCK; 4. Enter a statement in the following form to specify the

password that you want for the HR user:SQL> ALTER USER hr IDENTIFIED BY <hr-password>;

SOMKID SOOTITANTAWAT: Database Management Systems 48

Page 13: Chapter 4 · Chapter 4 Introducing Oracle ... queries and SQL scripts, and generate reports. 2 Oracle Database XE is a great ... Oracle 11g XE Install

เอกสารประกอบการบรรยายวชา ระบบการจดการฐานขอมล

อ.ดร. สมคด สทธธารธวช ม.ราชภฏพระนคร 13

Unlock User:hr Using the SQL Plus (ตอ)

SOMKID SOOTITANTAWAT: Database Management Systems 49

Unlock User:hr Using the SQL Plus (ตอ)

ทดสอบการ connect ดวย user ทปลดลอค

SQL > connect hr/oracle;

SOMKID SOOTITANTAWAT: Database Management Systems 50

hr ม Objects อะไรบาง SQL >

connect

hr/oracle;

SQL >

select *

from tab;

ม 8 Objects

SOMKID SOOTITANTAWAT: Database Management Systems 51

Creating a Database User You must create at least one database user

that you will use to create database objects.

A database user is a type of database object: a user is associated with a database schema, you connect to the database as a database user, and the database user is the owner of any database objects (tables and so on) that you create in the schema associated with the user.

SOMKID SOOTITANTAWAT: Database Management Systems 52

Page 14: Chapter 4 · Chapter 4 Introducing Oracle ... queries and SQL scripts, and generate reports. 2 Oracle Database XE is a great ... Oracle 11g XE Install

เอกสารประกอบการบรรยายวชา ระบบการจดการฐานขอมล

อ.ดร. สมคด สทธธารธวช ม.ราชภฏพระนคร 14

Creating a Database User For example, to create a database user named chris.

Follow these steps, using the command line: 1. Run SQL Command Line. 2. Connect as the SYSTEM user:

Type: connect Enter user-name: system Enter password: <password-for-system>

SQL>connect system/oracle; 3. Create the user. For example, enter a statement in

the following form:SQL> create user chris identified by <password-for-chris>;

SOMKID SOOTITANTAWAT: Database Management Systems 53

Creating a Database User (Cons.) 4. Grant the user the necessary privileges. For

example:SQL> grant connect, resource to chris;

5. Optionally, exit SQL*Plus (which also closes the command window):

SQL> exit

SOMKID SOOTITANTAWAT: Database Management Systems 54

Creating a Database User (Cons.)

SOMKID SOOTITANTAWAT: Database Management Systems 55

ทดสอบการเชอมตอ

SQL > connect chris/oracle;

SOMKID SOOTITANTAWAT: Database Management Systems 56

ไมสามารถแสดงรปนได ในขณะน

Page 15: Chapter 4 · Chapter 4 Introducing Oracle ... queries and SQL scripts, and generate reports. 2 Oracle Database XE is a great ... Oracle 11g XE Install

เอกสารประกอบการบรรยายวชา ระบบการจดการฐานขอมล

อ.ดร. สมคด สทธธารธวช ม.ราชภฏพระนคร 15

รปแบบคาสงในการกาหนดผใช

CREATE USER <username>

IDENTIFIED BY PASSWORD

[DEFAULT TABLESPACES <tablespace_name>

[TEMPORARY TABLESPACE <tablespace_name>

[QUOTA <integer K|M> ON <tablespace_name>]

[Account Status <LOCK|UNLOCK>]

[PASSWORD EXPIRE];57

อ.สมคด สทธธารธวช : เอกสารประกอบรายวชา ระบบการจดการฐานขอมล

การสราง User โดยใชคาสงผานทาง SQL-Plusรายละเอยดในการสราง user คาทกาหนด

User ชอของ user

Password รหสผานของ user

DEFAULT TABLESPACE ก าหนด tablespace ทใชเปน default สาหรบ user ใช

งาน

Temporary Tablespaces ก าหนด tablespace สาหรบการท างานทใชพนทช วคราว

Tablespaces Quota ระบเนอทบน Tablespace

Account Status เปนการระบวา user ทสราง สามารถใชงานไดทนทเลย

หรอไม

PassWord Expire ก าหนดใหรหสผานหมดอาย ท าให user ตองเปลยน

รหสผานเมอลอกอนเขาสระบบ58 อ.สมคด สทธธารธวช : เอกสารประกอบรายวชา ระบบการจดการฐานขอมล

ตวอยางการสราง user

59

SQL > CREATE USER ZOMKID IDENTIFIED BY WHITE

DEFAULT TABLESPACE COMPANY

TEMPORARY TABLESPACE TEMP

QUOTA 5 M ON COMPANY

ACCOUNT UNLOCK;

QUOTA ถาไมกาหนด หมายถง UNLIMITED

อ.สมคด สทธธารธวช : เอกสารประกอบรายวชา ระบบการจดการฐานขอมล

ตวอยางคาสงในการกาหนดผใช

CREATE USER ZOMKID

IDENTIFIED BY ZOMKID123

DEFAULT TABLESPACES USER_APP

TEMPORARY TABLESPACE TEMP

QUOTA 10M ON USER_APP

PASSWORD EXPIRE;

ตองการกาหนดชอผ ใชเปน zomkid มรหสผานคอ zomkid123 โควตา 10M และกาหนดให Default Tablespace ชอ User_App และ Temporary Tablespace คอ

TEMP

60

อ.สมคด สทธธารธวช : เอกสารประกอบรายวชา ระบบการจดการฐานขอมล

Page 16: Chapter 4 · Chapter 4 Introducing Oracle ... queries and SQL scripts, and generate reports. 2 Oracle Database XE is a great ... Oracle 11g XE Install

เอกสารประกอบการบรรยายวชา ระบบการจดการฐานขอมล

อ.ดร. สมคด สทธธารธวช ม.ราชภฏพระนคร 16

คาสงลบ user

SOMKID SOOTITANTAWAT: Database Management Systems 61

DROP

เปนคาส งทใชเพอยกเลกสงทเราไดท าการ

CREATE ไปแลว เชน การสราง USER ดวย

คาส ง CREATE เราสามารถลบ USER น นออก

ดวยคาส ง DROP USER โดยการพมพค าวา

DROP USER <user_name>;

คาสงลบ user

SOMKID SOOTITANTAWAT: Database Management Systems 62

ตวอยาง DROP USER kapook1;

ถาตองการลบผ ใชกรณทผ ใชมการสรางตาราง

และไดใสขอมลลงในตารางไวแลว จะใชค าส ง

ดงน

DROP USER <user_name> CASCADE;

DROP USER kapook1 CASCADE;

Oracle SQL Developer for 32-bit Windows

SOMKID SOOTITANTAWAT: Database Management Systems 63

SQL Developer You now want to be able to create and work with

database objects (tables, views, procedures, functions, and so on) in the database that you installed. To do this, you can use Oracle SQL Developer.

SQL Developer is a graphical tool that enables you to browse, create, edit, and delete (drop) database objects; run SQL statements and scripts; edit and debug PL/SQL code; unload (export) and load (import) data; migrate third-party databases to Oracle; and view metadata and data.

SOMKID SOOTITANTAWAT: Database Management Systems 64

Page 17: Chapter 4 · Chapter 4 Introducing Oracle ... queries and SQL scripts, and generate reports. 2 Oracle Database XE is a great ... Oracle 11g XE Install

เอกสารประกอบการบรรยายวชา ระบบการจดการฐานขอมล

อ.ดร. สมคด สทธธารธวช ม.ราชภฏพระนคร 17

SQL Developer (Cons.) The instructions in this guide use SQL Developer for

getting started with database development.

SQL Developer is not packaged with Oracle Database Express Edition, but it is easy to download and install SQL Developer. Much of the Express Edition documentation assumes that you have installed SQL Developer.

SOMKID SOOTITANTAWAT: Database Management Systems 65

Download

SOMKID SOOTITANTAWAT: Database Management Systems 66

Download

SOMKID SOOTITANTAWAT: Database Management Systems 67

Start SQL Developer: To start SQL Developer, go to the sqldeveloper

directory under the SQL Developer installation directory (for example, on a Windows system this might be C:\Program Files\sqldeveloper), and do one of the following:

On Windows systems, double-click sqldeveloper.exe

SOMKID SOOTITANTAWAT: Database Management Systems 68

Page 18: Chapter 4 · Chapter 4 Introducing Oracle ... queries and SQL scripts, and generate reports. 2 Oracle Database XE is a great ... Oracle 11g XE Install

เอกสารประกอบการบรรยายวชา ระบบการจดการฐานขอมล

อ.ดร. สมคด สทธธารธวช ม.ราชภฏพระนคร 18

Start SQL Developer:

SOMKID SOOTITANTAWAT: Database Management Systems 69

การตงคาสาหรบเรมใชงาน SQL Developer

แสดงหมายเลขบรรทดบนหนาจอ

Tool > Preference คลก

Code Editor เลอก Line Gutter และ

คลกหนาคาสง

Show Line Numbers

SOMKID SOOTITANTAWAT: Database Management Systems 70

ไมสามารถแสดงรปนได ในขณะน

การตงคาสาหรบเรมใชงาน SQL Developer(ตอ)

กาหนดลกษณะการแสดงผลคอลมน

ประเภทวนท

Tool >

Preference คลกเลอก Database

คลกเลอก NLS

SOMKID SOOTITANTAWAT: Database Management Systems 71

การตงคาสาหรบเรมใชงาน SQL Developer(ตอ)

กาหนดรปแบบและขนาดตวอกษร

Tool > Preference คลก

เลอก Code Editor

คลกเลอก Fonts

ปรบ Font Size

SOMKID SOOTITANTAWAT: Database Management Systems 72

Page 19: Chapter 4 · Chapter 4 Introducing Oracle ... queries and SQL scripts, and generate reports. 2 Oracle Database XE is a great ... Oracle 11g XE Install

เอกสารประกอบการบรรยายวชา ระบบการจดการฐานขอมล

อ.ดร. สมคด สทธธารธวช ม.ราชภฏพระนคร 19

Creating Database Connections 1. In the Connections navigator, right-click the

Connections node and select New Connection.

SOMKID SOOTITANTAWAT: Database Management Systems 73

SOMKID SOOTITANTAWAT: Database Management Systems 74

Creating Database Connections

Creating Database Connections(Cons.) Connection Name: ใสคา XE_chris

Username: chris Password: oracle Save Password: Specify this option if you want the

password is saved with the connection information; you will not be prompted for the password on subsequent attempts to connect using this connection.

Hostname: Host system for the Oracle database ชอ

เครองคอมพวเตอรหรอ IP ของเครองทตดต ง Oracle. For your Express Edition database, the hostname is localhost.

SOMKID SOOTITANTAWAT: Database Management Systems 75

Creating Database Connections(Cons.) Port: Listener port. The default is 1521. SID: Database name. The default for Express Edition is

xe.

SOMKID SOOTITANTAWAT: Database Management Systems 76

Page 20: Chapter 4 · Chapter 4 Introducing Oracle ... queries and SQL scripts, and generate reports. 2 Oracle Database XE is a great ... Oracle 11g XE Install

เอกสารประกอบการบรรยายวชา ระบบการจดการฐานขอมล

อ.ดร. สมคด สทธธารธวช ม.ราชภฏพระนคร 20

Creating Database Connections(Cons.) 2. Click Test to check if you have entered the correct

information for the connection. If the test is not successful, correct information as needed and click Test again.

3. When the test is successful, click Save to save the connection.

4. To open the connection after saving it, you can click Connect. (You can also open the connection using the Connections navigator.)

SOMKID SOOTITANTAWAT: Database Management Systems 77

สราง connection สาหรบ hr

SOMKID SOOTITANTAWAT: Database Management Systems 78

การออกจากการ connection

คลกขวาทไอคอน XE_hr

เลอกคาสง Disconnect

SOMKID SOOTITANTAWAT: Database Management Systems 79

Connect ใหม

คลกขวาทไอคอน XE_hr

เลอกคาสง Connect

กรอก password

SOMKID SOOTITANTAWAT: Database Management Systems 80

Page 21: Chapter 4 · Chapter 4 Introducing Oracle ... queries and SQL scripts, and generate reports. 2 Oracle Database XE is a great ... Oracle 11g XE Install

เอกสารประกอบการบรรยายวชา ระบบการจดการฐานขอมล

อ.ดร. สมคด สทธธารธวช ม.ราชภฏพระนคร 21

การใชคาสง SQL ผาน SQL Developer

การเขยนคาสง SQL ผาน SQL Worksheet เพอสงเขาไป

ทางานกบ Oracle จากนนจะแสดงขอมลทเปนผลลพธ

จากการทางานของคาสง SQL บนหนาจอ

สามารถเขยนคาสง SQL แบบทละคาสงแลวสงไปทางาน

หรอ

เขยนแบบทละหลายๆ คาสงแลวสงไปทางานในครงเดยว

สามารถบนทกคาสง SQL ทเขยนไวไดSOMKID SOOTITANTAWAT: Database Management Systems 81

เขยนคาสง SQL ทละคาสง

เขยนคาสงบน Worksheet

คลกปม Run Statement เพอสงใหคาสง SQL ทางาน

SOMKID SOOTITANTAWAT: Database Management Systems 82

เขยนคาสง SQL ทละคาสง (ตอ)

เลอกชอ connection และคลกตกลง

SOMKID SOOTITANTAWAT: Database Management Systems 83

เขยนคาสง SQL ทละคาสง (ตอ)

แสดง

ผลลพธของ

คาสง

SOMKID SOOTITANTAWAT: Database Management Systems 84

ลบคาส ง

Page 22: Chapter 4 · Chapter 4 Introducing Oracle ... queries and SQL scripts, and generate reports. 2 Oracle Database XE is a great ... Oracle 11g XE Install

เอกสารประกอบการบรรยายวชา ระบบการจดการฐานขอมล

อ.ดร. สมคด สทธธารธวช ม.ราชภฏพระนคร 22

เขยนคาสง SQL แบบทละหลายคาสง

เขยนคาสงบน Worksheet

คลกปม Run Script เพอสงใหคาสง SQL ทางาน

SOMKID SOOTITANTAWAT: Database Management Systems 85

เขยนคาสง SQL แบบทละหลายคาสง

ปรากฎผลลพธของคาสง

SOMKID SOOTITANTAWAT: Database Management Systems 86

การปด Worksheet File > Close

File > Close All

SOMKID SOOTITANTAWAT: Database Management Systems 87

เรยกหนาจอ SQL Worksheet

ไปทเมน

Tools > SQL

Worksheet

SOMKID SOOTITANTAWAT: Database Management Systems 88

Page 23: Chapter 4 · Chapter 4 Introducing Oracle ... queries and SQL scripts, and generate reports. 2 Oracle Database XE is a great ... Oracle 11g XE Install

เอกสารประกอบการบรรยายวชา ระบบการจดการฐานขอมล

อ.ดร. สมคด สทธธารธวช ม.ราชภฏพระนคร 23

เรยกหนาจอ SQL Worksheet (ตอ)

เลอกตว

connection

SOMKID SOOTITANTAWAT: Database Management Systems 89

เรยกหนาจอ SQL Worksheet (ตอ)

SOMKID SOOTITANTAWAT: Database Management Systems 90

การบนทกคาสง SQL คลกเมน File >

Save as

ตงชอไฟล

ระบแหลงทเกบ

ไฟล

ไฟลนามสกล .sql

SOMKID SOOTITANTAWAT: Database Management Systems 91

Unlocking the Sample User Account To view any objects owned by the supplied sample

database user named HR. Oracle Database XE comes with a sample database

user named HR. This user owns several database tables in a sample schema for a fictional Human Resources department. However, for security reasons, this user’s account is locked. You need to unlock this account before you can view the HR objects. You can use either of the following approaches to unlock the account:

SOMKID SOOTITANTAWAT: Database Management Systems 92

Page 24: Chapter 4 · Chapter 4 Introducing Oracle ... queries and SQL scripts, and generate reports. 2 Oracle Database XE is a great ... Oracle 11g XE Install

เอกสารประกอบการบรรยายวชา ระบบการจดการฐานขอมล

อ.ดร. สมคด สทธธารธวช ม.ราชภฏพระนคร 24

Unlock hr Using SQL Developer 1. Open a database connection for the SYSTEM user. 2. In the Connection navigator under the connection for

the SYSTEM user, expand the Other Users node.

SOMKID SOOTITANTAWAT: Database Management Systems 93

Unlock hr Using SQL Developer(ตอ) 3. Under Other Users, right-click the node for the hr

user and select Edit User.

SOMKID SOOTITANTAWAT: Database Management Systems 94

Unlock hr Using SQL Developer(ตอ) 4. In the Create/Edit User

dialog box, uncheck (deselect) the option Account is Locked. a. For New Password and

Confirm Password, enter the password that you want for the HR user.

b. Uncheck (deselect) Password expired (User must change next login).

c. Uncheck (deselect) Account is Locked.

SOMKID SOOTITANTAWAT: Database Management Systems 95

Unlock HR Using SQL Developer 5. Click Apply to alter

the HR user so that the account is unlocked and not expired.

6. Click Close to close the dialog box.

SOMKID SOOTITANTAWAT: Database Management Systems 96

Page 25: Chapter 4 · Chapter 4 Introducing Oracle ... queries and SQL scripts, and generate reports. 2 Oracle Database XE is a great ... Oracle 11g XE Install

เอกสารประกอบการบรรยายวชา ระบบการจดการฐานขอมล

อ.ดร. สมคด สทธธารธวช ม.ราชภฏพระนคร 25

สราง user ใหม ดวย SQL Developer

1. Open a database connection for the

SYSTEM user.

2. Under Other Users, right-click and select

Create User.

SOMKID SOOTITANTAWAT: Database Management Systems 97

สราง user ใหม ดวย SQL Developer (ตอ)

สราง user name

ชอ student

Password : oracle

คลกปม ใช

SOMKID SOOTITANTAWAT: Database Management Systems 98

สราง user ใหม ดวย SQL Developer (ตอ)

แสดงผลลพธวา

student ไดถกสราง

แลว

SOMKID SOOTITANTAWAT: Database Management Systems 99

เปรยบเทยบ SQL Plus กบ SQL Developer

SQL Developer SQL Plus

1.ใชงานแบบ GUI 1.ใชงานแบบ Command Line

2.ใชงานไดกบ DBMS

ยหออนๆ

2.ใชงานกบ Oracle เทานน

3.ใชไดกบ Oracle ตง

แตเวอรชน 9.0 เปน

ตนไป

3.ใชไดกบ Oracle ทกเวอรชน

SOMKID SOOTITANTAWAT: Database Management Systems 100

Page 26: Chapter 4 · Chapter 4 Introducing Oracle ... queries and SQL scripts, and generate reports. 2 Oracle Database XE is a great ... Oracle 11g XE Install

เอกสารประกอบการบรรยายวชา ระบบการจดการฐานขอมล

อ.ดร. สมคด สทธธารธวช ม.ราชภฏพระนคร 26

SOMKID SOOTITANTAWAT: Database Management Systems

References http://www.oracle.com/pls/xe112/homepage

http://i.dell.com/sites/content/business/solutions/brochures/en/Documents/oracle_db11g_comparison.pdf

ศภชย จวะรงสน. ระบบฐานขอมล Oracle 11g จากเรมตนสมออาชพ. กรงเทพฯ : ไทยเทคเนต, 2554.

ญาน กาชย. DBA Complete Guide Book ORACLE สมบรณทสด. นนทบร : ไอดซฯ , 2551.

ธนากร จงใจ. รลกระบบฐานขอมล Oracle 11g. กรงเทพฯ : บรษทเสรมวทย อนฟอรเมช นเทคโนโลย จ าก ด. 2551.

101