�e Graduate Programme for Engineers and Geoscientists
Month 16
I was a construction
supervisor in
the North Sea
advising and
helping foremen
solve problems
I was a
he
s
Real work International opportunities �ree work placementsal Internationa
or �ree wo
I wanted real responsibili�
I joined MITAS because
Maersk.com/Mitas
�e Graduate Programme for Engineers and Geoscientists
Month 16
I was a construction
supervisor in
the North Sea
advising and
helping foremen
solve problems
I was a
he
s
Real work International opportunities �ree work placementsal Internationa
or �ree wo
I wanted real responsibili�
I joined MITAS because
Maersk.com/Mitas
�e Graduate Programme for Engineers and Geoscientists
Month 16
I was a construction
supervisor in
the North Sea
advising and
helping foremen
solve problems
I was a
he
s
Real work International opportunities �ree work placementsal Internationa
or �ree wo
I wanted real responsibili�
I joined MITAS because
A practical introduction using Oracle SQL Introduction to Oracle SQL
This book uses the Oracle database with the Oracle Application Express (APEX) version 5 toolset to execute the presented SQL commands.
A free Oracle account can be obtained from apex.oracle.com. Alternatively, a copy of Oracle Database Express Edition 11g and APEX can be downloaded from apex.oracle.com for installation on your own PC. A web browser is used to access APEX and the database.
The following chapters will introduce you to the main SQL commands; a full Oracle SQL language reference can be found at docs.oracle.com.
Signing In
To sign in to the database, open your web browser and go to apex.oracle.com or your system’s own login page. You will need to enter your database workspace name, username and password. These will be provided to you when you open an Oracle account or will be given to you by your system administrator. The password can be reset by clicking on the Reset password option on the sign-in screen if required. Your workspace within the Oracle database is where your data tables and SQL commands will be stored.
A practical introduction using Oracle SQL
87
Introduction to Oracle SQL
Script files
Although you can enter SQL commands directly using the APEX SQL Command Tool, when developing applications it is usual practice to create script files to store regularly used SQL commands along with any supporting comments, e.g. commands for creating database tables.
A script file allows you to quickly retrieve, edit and rerun SQL commands. It is basically a simple text file and can, if required, be created outside of APEX using any text editor such as Microsoft Notepad.
Do not confuse script files with database tables, even though they can both have the same name. Script files should be saved with a suffix of .sql to avoid confusion with other file types.
1. Once signed in to APEX, on the Home page click on the SQL Workshop icon.
A practical introduction using Oracle SQL Introduction to Oracle SQL
The following screens will show you how to create and run a script file called music.sql which contains SQL commands that will create four tables in your database workspace relating to a music system (see Appendix B). The system will hold data about music companies that have produced music CDs, details of each CD, the tracks (songs) on each CD and music categories which tracks belong to.
2. Click on SQL Scripts.
A practical introduction using Oracle SQL
89
Introduction to Oracle SQL
3. Then click on Create >.
A practical introduction using Oracle SQL Introduction to Oracle SQL
4. Enter music in the Script Name box and then position the cursor in the editor area and enter all the SQL commands from the music.sql script file in Appendix B. Take care when entering these commands to ensure that they are all entered exactly as shown below.
A practical introduction using Oracle SQL
91
Introduction to Oracle SQL
Alternatively, you can create a script file outside of Oracle using a simple text editor such as Microsoft Notepad. Enter your SQL commands using the editor and save the file with a .sql suffix. To upload the script into APEX go to the SQLScripts tool and click on the Upload button, then choose the file name, enter a script name and click on the Upload button.
Comments can be included in script files by preceding them with --
5. You are now ready to run the script file to execute its SQL commands; click on the Run button. The script will be saved automatically. p y
Running a Script
To delete a script on the SQL Scripts page just tick the small box to the left of the script detail and click on the Delete Checked button, then click OK when prompted to perform the delete action.
A practical introduction using Oracle SQL Introduction to Oracle SQL
6. Click on the Run in Background button (or Run Now)
Run Script