Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
40
Добавлен:
16.04.2013
Размер:
4.96 Mб
Скачать

Representing Conditional Expressions as Data

TABLESPACE ts2);

Y2K Example: Views Defined Using 2-Digit Years

Oracle Database views depend on the session state. In particular, a predicate with a 2-digit year is allowed in a view. For example:

WHERE col > '12-MAY-99'

Interpretation of the full 4-digit year depends on the setting of NLS_DATE_FORMAT.

Representing Conditional Expressions as Data

The Oracle Expression Filter feature lets you store conditional expressions as data in the database. The Expression Filter provides a mechanism that you use to place a constraint on a VARCHAR2 column to ensure that the values stored are valid SQL WHERE clause expressions. This mechanism also identifies the set of attributes that can be referenced in the conditional expressions.

For example, suppose each row of a table Traders holds data for a stock trading account holder. You can define a column that stores information about stocks each trader is interested in as a conditional expression. To do so, you use the following PL/SQL commands to create an attribute set Ticker with a list of required elementary attributes for the trading symbol, limit price, and amount of change in the stock price:

CREATE OR REPLACE TYPE Ticker AS OBJECT

(Symbol VARCHAR2(20), Price NUMBER, Change NUMBER);

BEGIN

dbms_expfil.create_attribute_set(attr_set => 'Ticker', from_type => 'YES');

END;

Next, you associate the attribute set with the expression set stored in the database column TRADER.INTEREST as follows:

BEGIN

dbms_expfil.assign_attribute_set (attr_set => 'Ticker', expr_tab => 'Traders', expr_col => 'Interest');

END;

2-32 Oracle Database Application Developer's Guide - Fundamentals

Representing Image, Audio, and Video Data

This places a constraint on the INTEREST column that ensures the column stores valid conditional expressions. You can then populate the table with trader names, email addresses and conditional expressions that represents a stock the trader is interested in at a particular price:

INSERT INTO Traders (Name, Email, Interest)

VALUES ('Scott', 'scott@abc.com', 'SYMBOL = ''ABC'' and PRICE > 25');

At this point, you can use the EVALUATE operator to identify the conditional expressions that evaluate to TRUE for a given data item. For example, the following query can be issued to return all the traders who are interested in a given stock quote (Symbol='ABC', Price=31, Change=5.2):

SELECT Name, Email FROM Traders

WHERE EVALUATE (Interest,

'Symbol=>''ABC'', Price=>31, Change=>5.2') = 1;

To speed up a query like this one, you can optionally create an Oracle Expression Filter index on the INTEREST column.

See Also: Oracle Database Application Developer's Guide - Expression

Filter for details on Oracle Expression Filter

Representing Geographic Coordinate Data

To represent Geographic Information System (GIS) or spatial data in the database, you can use Oracle Spatial features, including the type MDSYS.SDO_GEOMETRY. You can store the data in the database using either an object-relational or a relational model, and manipulate and query the data using a set of PL/SQL packages.

For more information, see Oracle Spatial User's Guide and Reference.

Representing Image, Audio, and Video Data

Whether you store such multimedia data inside the database as BLOB or BFILE values, or store it externally on a Web server or other kind of server, you can use interMedia to access the data using either an object-relational or a relational model, and manipulate and query the data using a set of object types.

For more information, see Oracle interMedia Reference.

Selecting a Datatype 2-33

Соседние файлы в папке Oracle 10g