1 Overview of Oracle
1 Overview of Oracle
This chapter introduces you to application development with Oracle Database. This chapter contains the following sections:
Roadmap Overview of Oracle Database Schemas Overview of Application Development with Oracle Database Overview of Other Development Environments
Roadmap
You are an Oracle Database developer, someone who has the responsibility of creating or maintaining the database components of an application that uses the Oracle technology stack. The discussion in this and following sections assumes that you, or someone else in your organization, must know how to architect multiuser applications (two tier or multitier) and understands the advantages of using a relational database for the data persistence tier. As a database developer, you need to know how to implement the data model that the application requires, how to implement the rules for data integrity, and how to implement the specified functions for accessing and manipulating the application data. You know already that you can access an Oracle Database only through a client program, and that the SQL language is that client program's interface to the Oracle Database. You will learn how to access the Oracle Database by using two clients that are packaged with the Oracle Database and designed for developers: SQL Developer and SQL*Plus. Both allow you to issue the SQL statements you need in order to create and test your application's database component without doing any client programming. Programming such clients is outside the scope of this discussion. To briefly review widely accepted best practices in software engineering, you must define APIs that model business functions, and hide the implementation. Oracle Database supports this practice by letting you specify the APIs as PL/SQL subprograms. The implementation is tables, indexes, constraints, triggers, and the various SQL statements that modify and fetch table rows. By embedding these SQL statements in PL/SQL subprograms, and by using Oracle's schema and privilege mechanisms, you can securely hide the implementation from the client programs. Many of Oracle's major customers follow this practice strictly: client programs are allowed to access the database only by calling PL/SQL subprograms. Some customers relax this rule by allowing the client to issue raw SQL SELECT statements, but requiring it to call PL/SQL subprograms for all business functions that make changes to the database.
This general discussion sets the charter for your job as an Oracle Database developer:
You need to know about the various types of objects that you can create in the database, as described in "Exploring Database Objects". You need to know the SQL that is used to manage these objects: CREATE, ALTER, TRUNCATE, and DROP. This is known as data definition language (DDL), and is described in "Creating and Using Database Objects". You need to know the SQL language that is used to maintain application data: INSERT, UPDATE, DELETE, and MERGE. This is known as data manipulation language (DML), and is described in "Querying and Manipulating Data". You need to know the SQL language for querying data: SELECT statement and its various clauses, as described in "Retrieving Data with Queries". You need to know about transactions, and the SQL language for controlling them: COMMIT, SAVEPOINT, and ROLLBACK, as described in "Controlling Transactions". You need to know how to write PL/SQL subprograms and procedural code that use DDL, DML, transaction control, and queries, as described in "Developing and Using Stored Procedures" and "Using Triggers". You need to know how to manage your deliverables and how to instantiate your application in several different databases for the purposes of development itself, unit testing, integration testing, end-user acceptance testing, education, and ultimately for deploying your application in a production environment. This information is in "Deploying a Database Application".
See Also:
In addition to tables, schemas contain many other objects. Indexes are optional structures that can improve the performance of data retrieval from tables. Indexes are created on one or more columns of a table, and are automatically maintained in Oracle Database. See "Creating and Using Tables". Depending on your business needs, you can create a view that combines information from several different tables into a single presentation. Such views can rely on information from other views as well as tables. See "Using Views". In an application where all records of the table must be distinct, a sequence can generate a serial list of unique integer numbers for a numeric column that represents the ID of each record. See "Using Sequences". A synonym is an alias for any table, view, sequence, procedure, and so on. Synonyms are often used for security and convenience, such as masking the ownership of an object or simplifying SQL statements. See "Using Synonyms". Schema-level procedures and functions, and also packages, are collectively known as stored procedures. Stored procedures are blocks of code that are actually stored in the database. They are callable from client applications that access a relational database system. See "Developing and Using Stored Procedures". Triggers are procedural code that is automatically executed by the database when specified events occur in a particular table or view. Triggers can restrict access to specific data, perform logging, or audit data. See "Using Triggers". See Also:
http://www.oracle.com/technology/tech/pl_sql/
See Also:
Oracle Database SQL Language Reference Oracle Database PL/SQL Language Reference Oracle Database PL/SQL Packages and Types Reference
"Overview of Other Development Environments"
java -version
Output similar to the following should appear:
java version "1.5.0_06" Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05) Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode, sharing) To start SQL Developer:
1. In Linux: o Click the Application menu (on Gnome) or the K menu (on KDE). o Select Oracle - ORACLE_HOME, then Application Development, and then SQL Developer.
In Windows:
From the Start menu, select All Programs. Select Oracle - ORACLE_HOME, then Application Development, and then SQL Developer. 2. When prompted, enter the full path to the Java executable.
o o
For example: C:\jdk1.5.0\bin\java.exe You only need to specify this path the first time you start SQL Developer. After the splash screen appears, SQL Developer starts.
Description of the illustration sql_dev_new.gif For more information about SQL Developer, see the SQL Developer Oracle Technology Network site at
http://www.oracle.com/technology/products/database/sql_deve loper/index.html
See Also:
Introducing SQL*Plus
SQL*Plus is installed together with Oracle Database. SQL*Plus has a command-line interface for accessing Oracle Database. You can also access SQL*Plus within SQL Developer.
3. In the cmd.exe window, at the c:>\ prompt, enter sqlplus and press the Enter button of your keyboard. SQL*Plus starts and prompts you to authenticate your connection to the database. Your screen looks something like this:
C:\>sqlplus SQL*Plus: Release 11.1.0.1.0 - Production on Tue April 3 10:10:11 2007 Copyright (c) 1982, 2007, Oracle. All rights reserved. Enter user-name:
4. Enter your user name and press Enter. Your screen looks something like this:
Enter password:
5. Enter your password and press Enter. Note that entering your user name and password in this manner is secure because your password is not visible on the screen. The system connects you to a database instance, and shows a SQL prompt. Your screen looks something like this:
Connected to: Oracle Database 11g Enterprise Edition Release 11.1.0.1.0 - Production With the Partitioning, OLAP and Data Mining options
You can now start using the SQL command prompt. 6. To close the SQL*Plus session, at the SQL prompt enter the exit command. Note that you are not shutting down the Oracle Database instance.
7. SQL> exit
Your screen looks something like this:
Disconnected from Oracle Database 11g Enterprise Edition Release 11.1.0.1.0 With the Partitioning, OLAP and Data Mining options
See Also:
Oracle Database 2 Day + Security Guide SQL*Plus User's Guide and Reference
(UNKNOWN STEP NUMBER) Unlocking a User Account Connecting to Oracle Database from SQL*Plus Connecting to Oracle Database from SQL Developer
Unlocking a User Account By default, when the hr schema is installed, it is locked and its password is expired. Before you can connect to Oracle Database using the hr schema, a user with administrator privileges needs to unlock the hr account and reset its password. The following steps show how to unlock the hr account and change its password.
USER
hr
ACCOUNT
UNLOCK
IDENTIFIED
BY
The system confirms that the hr account is unlocked and its password changed:
User altered
Connecting to Oracle Database from SQL*Plus
When the hr account is unlocked, you can create a new hr connection using the new password that you set in "Unlocking a User Account".
Connecting to Oracle Database from SQL Developer When the hr account is unlocked, you can use it to access the hr schema inside the Oracle Database. In this section, you will be working with Oracle SQL Developer.
Description of the illustration sql_dev_conn_1.gif 3. In the upper part of the New/Select Database Connection window, enter this information: o For Connection Name, enter hr_conn.
For Username, enter hr. For Password, enter the password that the system administrator created after unlocking the hr account. Note that the password text is masked. o Leave the Save Password option unchecked.
o o
Under the Oracle tab of the New/Select Database Connection window, enter this information: For For For o For o For
o o o
Role, select Default. Connection Type, select Basic. Hostname, enter localhost. Port, enter 1521. SID, enter orcl.
4. The connection is tested. At the bottom of the New/Select Database Connection window, Status is changed to Success.
Description of the illustration sql_dev_conn_4.gif 5. At the bottom of the New/Select Database Connection window, click Connect. The Oracle SQL Developer window appears, with a new hr_conn connection.
Description of the illustration sql_dev_conn_5.gif You have successfully established a connection to the hr schema.
Oracle Data Provider for .NET, Oracle Database Extensions for .NET and Oracle Developer Tools for Visual Studio .NET
Oracle Data Provider for .NET (ODP.NET), is a .NET data provider that uses and extends the Microsoft .NET Framework Class Library. ODP.NET uses the .NET Framework to expose provider-specific features and data types, so its use of native Oracle Database APIs bring the features of Oracle Database to .NET applications. Oracle Database Extensions for .NET provide a Microsoft Common Language Runtime (CLR) host for Oracle Database, data access through ODP.NET classes, and the Oracle
Deployment Wizard for Visual Studio .NET. Because CLR runs as an external process on Oracle Database server, this integration enables you to run .NET stored procedures and functions on Oracle Database in Microsoft Windows XP, 2000, and 2003. These stored procedures and functions can be authored in any .NET language, such as C# and VB.NET, and then deployed in Oracle Database using the Oracle Deployment Wizard for .NET, just like PL/SQL or Java stored procedures. Oracle Developer Tools provide a graphical user interface to access Oracle Database functionality through Visual Studio .NET. Oracle Developer Tools include Oracle Explorer for browsing the database schema, wizards and designers for creating and altering schema objects, the ability to automatically generate code by dragging schema objects onto the .NET design form, and a PL/SQL editor with integrated context-sensitive help. Additionally, the Oracle Data Window enables you to perform routine database tasks and test stored procedures in the Visual Studio environment, while the SQL Query Window executes SQL statements and scripts. For an introduction to .NET application development with Oracle Database, see Oracle Database 2 Day + .NET Developer's Guide. Further Oracle Database .NET documentation includes Oracle Data Provider for .NET Developer's Guide and Oracle Database Extensions for .NET Developer's Guide. For complete information about Oracle Database .NET APIs, ODP.NET, Oracle Developer Tools, downloads, tutorials, and related information, see the .NET Oracle Technology Network site at
http://www.oracle.com/technology/tech/dotnet/ PHP
The Hypertext Preprocessor, PHP, is a powerful interpreted server-side scripting language for quick Web application development. PHP is an open source language that is distributed under a BSD-style license. PHP is designed for embedding Oracle Database access requests directly into HTML pages. For an introduction to PHP application development with Oracle Database, see the Oracle Database 2 Day + PHP Developer's Guide. For complete information about Oracle Database PHP APIs and related information, see the PHP Oracle Technology Network site at
Oracle Application Express, APEX, is an application development and deployment tool that enables you to quickly create secure and scalable Web applications even if you have limited previous programming experience. The embedded Application Builder tool assembles an HTML interface or a complete application that uses database objects, such as tables or stored procedures, into a collection of pages that are linked together through tabs, buttons, or hypertext links. See Oracle Database 2 Day + Application Express Developer's Guide for complete information on APEX. For complete information about APEX and related information, see the APEX Oracle Technology Network site at
http://www.oracle.com/technology/products/database/applicat ion_express/ Oracle Call Interface and Oracle C++ Call Interface
Oracle Call Interface (OCI) is the native C language API for accessing Oracle Database directly from C applications. See Oracle Call Interface Programmer's Guide for complete information on OCI. Oracle C++ Call Interface (OCCI) is the native C++ language API for accessing Oracle Database directly from C++ applications. Very similar to the OCI, OCCI supports both relational and object-oriented programming paradigms. See Oracle C++ Call Interface Programmer's Guide for complete information on OCCI. The OCI and OCCI Software Development Kits are also installed as part of the Oracle Instant Client, which enables you to run applications without installing the standard Oracle client or having an ORACLE_HOME. Your applications will work without modification, while using significantly less disk space. Oracle Instant Client is available from the Instant Client Oracle Technology Network site at
http://www.oracle.com/technology/tech/oci/instantclient/
For complete information about Oracle Database OCI and related information, see the OCI Oracle Technology Network site at
http://www.oracle.com/technology/tech/oci/
For complete information about Oracle Database OCCI and related information, see the OCCI Oracle Technology Network site at
Oracle Java Database Connectivity (JDBC) is an API that enables Java to send SQL statements to an object-relational database, such as Oracle Database. Oracle Database JDBC provides complete support for the JDBC 3.0 and JDBC RowSet (JSR-114) standards, advanced connection caching for both XA and non-XA connections, exposure of SQL and PL/SQL data types to Java, and fast SQL data access. Like OCI and OCCI, JDBC is part of the Oracle Instant Client installation, which is available from the Instant Client Oracle Technology Network site at
http://www.oracle.com/technology/tech/oci/instantclient/
For more information about JDBC APIs, see the Sun Developer Network site at
http://java.sun.com/javase/technologies/database/
For complete information about Oracle Database JDBC APIs, drivers, support and desupport notices, and similar information, see the Oracle Technology Network site at
http://www.oracle.com/technology/tech/java/sqlj_jdbc/
For an introduction on how to use Java to access and modify data in Oracle Database, see Oracle Database 2 Day + Java Developer's Guide.
http://www.oracle.com/technology/tech/windows/odbc/
For information about unixODBC standards and the latest Driver manager, see the unixODBC site at
http://www.unixodbc.org/
For information about using the Oracle ODBC driver with Windows, see Oracle Services for Microsoft Transaction Server Developer's Guide.
For information about how to use the Oracle ODBC driver on Linux, see Oracle Database Administrator's Reference for Linux and UNIX. Like OCI, OCCI, and JDBC, ODBC is part of the Oracle Instant Client installation, which is available from the Instant Client Oracle Technology Network site at
http://www.oracle.com/technology/tech/oci/instantclient/