NETWORK_DATASTORE Example

This example shows you how to configure HTTP and HTTPS network connections and create an index based on the NETWORK_DATASTORE type to access the files stored on the World Wide Web.

Create a user and grant the necessary privileges:

CREATE USER myuser IDENTIFIED by password;
GRANT connect, resource, unlimited tablespace, ctxapp to myuser;

Append an access control entry (ACE) to the ACL of a network host. The ACL controls access to the given host from the database and the ACE specifies the privileges granted to or denied from the specified principal. When host is specified as '*', you can access any host through the network datastore which uses UTL_HTTP package internally to access data from websites through HTTP.

begin
   DBMS_NETWORK_ACL_ADMIN.APPEND_HOST_ACE(
    host => '*',
    ace  =>  xs$ace_type(privilege_list => xs$name_list('connect', 'resolve'),
                         principal_name => 'MYUSER',
                         principal_type => xs_acl.ptype_db));
end;
/

Create a network datastore preference called NETWORK_PREF:

begin
 ctx_ddl.create_preference('NETWORK_PREF','NETWORK_DATASTORE');
 ctx_ddl.set_attribute('NETWORK_PREF','HTTP_PROXY','www-proxy.us.example.com');
 ctx_ddl.set_attribute('NETWORK_PREF','NO_PROXY','us.example.com');
 ctx_ddl.set_attribute('NETWORK_PREF','TIMEOUT','300');
end;
/

Create a table named mytable and populate it with URLs:

create table mytable(id number primary key, docs varchar2(2000));
insert into mytable values(111555,'http://context.example.com');
insert into mytable values(111556,'http://www.johndoe.com');

Create the index as follows:

create index myindex on mytable(docs)
  indextype is ctxsys.context
  parameters ('datastore NETWORK_PREF');

See Also: