Working with Oracle Database XE

[Pages:7]Working with Oracle Database XE

Create New User Account Using SQL

Run Script Files PL/SQL Objects PL/SQL Server Pages

Create New User Account

Users access Oracle Database 10g Express Edition through database user accounts. Some of these accounts are automatically created as administrative accounts--accounts with database administration privileges. You log in with these accounts to create and manage other user accounts, and to maintain database security.

The installation process creates an account named SYSTEM. This account is considered an Administrator Account since it has DBA access.

To institute Oracle's best practice, a user can create their own Administrator Account and Password, or any other account.

Login with SYSTEM account and click the Administration icon arrow. Click the Database Users arrow. Click Create User option from the submenu. In the following screen enter the new user name, password, and assign some privileges (roles). The DBA checkbox provides the account with database administration privileges. Then click the Create button. A new database account has been created.

Using SQL

In Oracle Database XE, there are many ways to work with the SQL language.

1. Click the arrow attached to the SQL icon in the home page, select the SQL Commands arrow, and choose Enter Command from the associated submenu.

In the SQL Command Web page, the screen is horizontally divided in two parts. In the top part enter the SQL or PL/SQL command, and then press the Run button to see the results in the bottom portion of the screen.

2. Click the arrow attached to SQL icon in the home page, select the Query Builder arrow, and choose Create from the associated submenu.

In the Query Builder Web page, the left pane will show the tables. Select the table to view its graphical structure in the right pane. Relationships and attribute selection can then be accomplished. Press the Run button to see the results in the bottom portion of the right pane.

1

3. Click the arrow attached to SQL icon in the home page, select the SQL Scripts arrow, and choose Create from the associated submenu. Script Editor screen opens up. Enter the SQL statements and press Run button to execute.

4. SQL Command Line

Go to the Start menu, select Programs (or All Programs), select Oracle Database 10g Express Edition program group, and choose Run SQL Command Line. This will open the SQL Editor in a Windows Prompt window. Start the session by connecting to the database using the command:

connect userid/password

Once the connected message appears, enter the SQL statement following the SQL prompt as in SQL Plus. To end session, enter exit or quit command.

Run Script Files

Click the SQL icon arrow. Select SQL Scripts arrow. In the associated submenu select the Upload option.

Now, click the Browse button to select the script file to be uploaded. Enter the script name and press the Upload button.

To run the script file, first click the script name in the next screen, and then once the script contents are displayed press the Run button. (You may be asked to press another Run button). Click the file results icon to see the results of script execution.

PL/SQL Objects

PL/SQL objects can be procedures, function, package, trigger, including tables, sequences, and so on.

To create a PL/SQL object, in the home page, click the Object Browser arrow, select the Create arrow, and choose the nature of operation to perform from the associated submenu. Follow the graphical interface to complete the object.

To modify existing PL/SQL object structures, in the home page, click the Object Browser arrow, select the Browse arrow, and choose the nature of operation to perform from the associated submenu. Follow the graphical interface to edit the object.

2

Run PL/SQL Programs

To run a PL/SQL program like procedure, function, or package use the SQL Command page or SQL Command Line.

To run a procedure create an anonymous block containing the procedure name as follows.

Begin procedure-name; End;

For example, to run a procedure supplier_check, the anonymous block is:

Begin supplier_check; End;

To run or test a function create an anonymous block containing a variable and have the function assigned to this variable as follows:

Declare Variable datatype; Begin Variable := function-name; dbms_output.put_line(Variable); End;

For example to test a function count_suppliers with one input parameter, the anonymous block is:

Declare count_out number; Begin count_out := count_suppliers(100); dbms_output.put_line(count_out); End;

Of course, another way to test the above function is:

Begin dbms_output.put_line(count_suppliers(100)); End;

3

PL/SQL Server Pages

Compose the PL/SQL server page in any HTML editor, and then run loadpsp command from the Windows command prompt window. Use the "xe" connect string. For example,

loadpsp -replace -user userid/password@xe drive&path\??.psp

Once the PSP has been loaded, it can be viewed/edited as a PL/SQL procedure object through the Object Browser option of the home page.

To view the loaded PSP through the browser, a database access descriptor (DAD) has to be created.

Database Access Descriptor (DAD) Setup

The administration of Database Access Descriptors (DADs) is performed using the DBMS_EPG package. This package has procedures to create DAD, delete DAD, allow authorized access, and so on. Programs in this package can be run from the SQL Command Line.

The CREATE_DAD procedure is used to create a DAD. It requires two parameters ? one for DAD name, and the other for associated virtual path. For example create a DAD named "classpsp" and its associated virtual path as follows:

Begin DBMS_EPG.create_dad('classpsp','/classpsp/*'); End;

Now to access a PSP from the browser, the URL will be



The browser will prompt for userid password.

The AUTHORIZE_DAD procedure is used to enable direct access to the specified user schema without the browser prompt for userid and password. For example, allow the "classpsp" DAD access to a user "sam" account as follows:

Begin DBMS_EPG.authorize_dad('classpsp','SAM'); End;

The authorization can be reversed using the DEAUTHORIZE_DAD procedure as follows:

Begin DBMS_EPG.deauthorize_dad('classpsp','SAM'); End;

4

The DROP_DAD is used to remove an unwanted DAD. For example, drop the "classpsp" DAD as follows:

Begin DBMS_EPG.drop_dad('classpsp'); End; To enable viewing of images in a PSP through the browser create a Web (virtual) folder and then access those images through absolute path specifications. The Web (virtual) folder name as well as file names are case sensitive. Create a Web (virtual) folder 1. Go to My Network Places and start the "Add Network Place Wizard."

2. Select "Choose another network location", then 3. Click "Next" and follow the Wizard's prompts. 4. When prompted for an "Internet or network address", enter the URL

to open Oracle XE home folder. Continue to follow the Wizard's prompts. The system will prompt for username and password. Enter the SYSTEM username and its corresponding password. Towards the end of wizard, enter a name to identify this Web (virtual) folder, eg. WEBSPACE.

5

5. Once the Wizard is finished,. your "My Network Places" window will contain a Web folder WEBSPACE. To access your WEBSPACE folder initially the system may prompt for DBA type username and password.

6. Now, within the home Web (virtual) folder, create a subfolder. Move files from hard drive to this new subfolder, and then access them directly through the browser or PSP procedure.

For example, create a subfolder pspweb1, and paste an image file HalfDome.jpg in it.

To access this image file from the browser enter the URL .

To access this image file from the pspweb1 subfolder within a PSP procedure, the absolute path will be /pspweb1/HalfDome.jpg.

If another subfolder pspclass1 is created inside pspweb1, and the image file HalfDome.jpg is pasted inside it, then to access the image from the browser, the URL is .

Now, to access this image file from the pspclass1 subfolder within a PSP procedure, the absolute path will be /pspweb1/pspclass1/HalfDome.jpg.

A sample PSP procedure with access to an image file in a Web (virtual) folder is as follows:

create or replace PROCEDURE helloworld AS BEGIN NULL;

htp.prn(' '); htp.prn(' '); htp.prn(' Hello Hello World ');

END;

6

7

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download