0% found this document useful (0 votes)
42 views5 pages

OQL Database Querying Guide

The document outlines the use of Object Query Language (OQL) for creating and managing object relational databases. It provides syntax and examples for creating databases, tables, and inserting data, as well as retrieving data using select statements. The document concludes that the query for the object relational database using OQL was successfully created and executed.

Uploaded by

joyalprincess
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views5 pages

OQL Database Querying Guide

The document outlines the use of Object Query Language (OQL) for creating and managing object relational databases. It provides syntax and examples for creating databases, tables, and inserting data, as well as retrieving data using select statements. The document concludes that the query for the object relational database using OQL was successfully created and executed.

Uploaded by

joyalprincess
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

EX-NO : 10

OBJECT RELATIONAL DATABASE USING


OBEJCT QUERY LANGUAGE
DATE :

AIM:
To write query for object relational database using object query language.

Object Query Language:

Query Object Language (OQL) is a version of the Structured Query Language (SQL) that has been
designed for use in Network Manager. The components create and interact with their databases using OQL.

Use OQL to create new databases or insert data into existing databases (to configure the operation
of Network Manager components) by amending the component schema files. You can also issue OQL
statements using the OQL Service Provider, for example, to create or modify databases, insert data into
databases and retrieve data.

Database and table creation

You can create databases and tables with the create command. You

can issue the create command to create a database. create database

database_name ;

create table database_name.table_name (

column_name [ constraints ] [ default default ] ,

[ column_name [ constraints ] [ default default ] , ] [

additional_columns ]

[ unique ( column_name ) , ] [

counter ( column_name ) , ]

[ timestamp ( column_name ) ]

);
Examples of database and table creation

create database staff; // creates the staff database

The following insert defines the managers table.

create table [Link]


(
EmployeeIDint NOT NULL PRIMARY KEY,
Name text NOT NULL,
Department text default "Sales",
Gender text,
Age int,
unique ( EmployeeID ) // indicates that the data in the
// EmployeeID column must be unique.
);

For the managers table:

The EmployeeID and Name columns cannot be NULL.


The EmployeeID column is the primary key and must be unique.
If no value is inserted into the Department column for a given record it takes the value "Sales".

Example 2

The following insert creates the [Link] table.

create table [Link]


(
EmployeeIDint NOT NULL PRIMARY KEY,
Name text NOT NULL,
Skills list type text,
Gender text,
Age int // There is no comma here because this
// is the last entry.
);

For the [Link] table:

The EmployeeID and Name columns cannot be NULL.


The Skills column is a list of text strings.
Example 3
The following insert creates the [Link] table.

create table [Link]


(
EmployeeIDint NOT NULL PRIMARY KEY,
Name text NOT NULL,
Gender text,
Age int,
ExtraInfo object type vblist,
volatile
);

For the [Link] table:

The ExtraInfo column contains a list of varbinds.

Selecting data from a table


QSyntax

The following syntax shows how to use the select keyword to retrieve data from a table.

select comma_separated_column_list_or_wildcard
from database_name.table_name
[ where conditional_test ]
[ order by field_name[asc|desc] ];

The * symbol can be used as a wildcard in a select statement to return all the columns of the table.
Alternatively a comma-separated list of columns can be specified.

If you specify an order by clause, then results are returned in ascending order by default. NULL
values are returned first when the results are in ascending order. Ordering of results in descending
order is the exact opposite of the ordering of results in ascending order.

Example 1

The following example shows how to use the select statement within the OQL Service Provider to
query the [Link] table (the following example output is abbreviated).

|phoenix:1.>select * [Link];
|phoenix:2.>go
.....
{
EmployeeID=1;
Name='Matt';
Department='Development';
Gender='M';
Age=28;
}
{
EmployeeID=2;
....
....
}
( 5 record(s) : Transaction complete )
Example 2

The following example shows a select statement that retrieves only specific fields from
the [Link] table.

|phoenix:1.>select Name, Gender [Link];


|phoenix:2.>go
.....
{
Name='Matt';
Gender='M';
}
{
Name='Irene';
Gender='F';
}
{
Name='Ernie';
....
....
}
( 5 record(s) : Transaction complete )
Example 3

The following example uses a where clause to restrict the results.

|phoenix:1.>selectEmployeeID, Name [Link]


|phoenix:2.>where Department = "Marketing";
|phoenix:3.>go
.
{
EmployeeID=4;
Name='John';
}
( 1 record(s) : Transaction complete )
Example 4

The following example shows how to use a select DISTINCT keyword to retrieve a single row
for each type of data; for example a single row for each department.

|phoenix:1.>select DISTINCT Department [Link]


|phoenix:2.>go
.
{
Department='Development';
}
{
Department='Marketing';
}
{
Department='Sales';
}
( 3 record(s) : Transaction complete )
query the data in a table using the select keyword. Use these examples to help you use the select
keyword.

RESULT:
Thus the query for object relational database using object query language was created and
executed.

You might also like