Object Query Language
Encyclopedia
Object Query Language is a query language
Query language
Query languages are computer languages used to make queries into databases and information systems.Broadly, query languages can be classified according to whether they are database query languages or information retrieval query languages...

 standard for object-oriented databases
Object database
An object database is a database management system in which information is represented in the form of objects as used in object-oriented programming...

 modeled after SQL
SQL
SQL is a programming language designed for managing data in relational database management systems ....

. OQL was developed by the Object Data Management Group (ODMG). Because of its overall complexity no vendor has ever fully implemented the complete OQL. OQL has influenced the design of some of the newer query languages like JDOQL and EJB QL
EJB QL
EJB QL or EJB-QL is a portable database query language for Enterprise Java Beans. It was used in Java EE applications. Compared to SQL, however, it is less complex but less powerful as well.-History:...

, but they can't be considered as different flavors of OQL.

General Rules of OQL

The following rules apply to OQL statements:
  • All complete statements must be terminated by a semi-colon.
  • A list of entries in OQL is usually separated by commas but not terminated by a comma.
  • Strings of text are enclosed by matching quotation marks.

Simple query

The following example illustrates how one might retrieve the CPU-speed of all PCs with more than 64MB of RAM from a fictional PC
Personal computer
A personal computer is any general-purpose computer whose size, capabilities, and original sales price make it useful for individuals, and which is intended to be operated directly by an end-user with no intervening computer operator...

 database:


SELECT pc.cpuspeed

FROM PCs pc

WHERE pc.ram > 64


Query with grouping and aggregation

The following example illustrates how one might retrieve the average amount of RAM
Ram
-Animals:*Ram, an uncastrated male sheep*Ram cichlid, a species of freshwater fish endemic to Colombia and Venezuela-Military:*Battering ram*Ramming, a military tactic in which one vehicle runs into another...

 on a PC
Personal computer
A personal computer is any general-purpose computer whose size, capabilities, and original sales price make it useful for individuals, and which is intended to be operated directly by an end-user with no intervening computer operator...

, grouped by manufacturer:


SELECT manufacturer, AVG(SELECT part.pc.ram FROM partition part)

FROM PCs pc

GROUP BY manufacturer: pc.manufacturer


Note the use of the keyword partition, as opposed to aggregation in traditional SQL
SQL
SQL is a programming language designed for managing data in relational database management systems ....

.

See also

  • ODMG - Object Data Management Group
  • Object Definition Language
    Object Definition Language
    Object Definition Language is the specification language defining the interface to object types conforming to the ODMG Object Model...

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK