Sample DQLs

These are few sample DQL’s that will give you some idea about some of the queries that you can build using Documentum Query Language. These examples are meant only to give you a head-start on the basic DQL syntax. For more information on DQL please refer to Content Server DQL Reference guide ( I will be adding a downloadable note with basic DQL queries to this page soon)

Simple DQL to select Single attributes of a Object
select r_object_id from dm_document where object_name=’test’

DQL to select a Repeated Attributes of a Object
select r_version_label from dm_document where any r_version_label in (’CURRENT’)

Usage of As in the Query
select object_name as name from dm_document where r_object_id=’09xxxxxx’

Finding all groups a user belongs to
select group_name from dm_group where any users_names in (’user_name’)

To find Folder Path of a Object
select r_folder_path from dm_folder where r_object_id in(select i_folder_id from dm_document where object_name=’object_name’) ;

Query to search a document (with full text indexing )
select * from dm_document search document contains ‘test’

Create a Simple Object Type
CREATE TYPE “mycustomtype” (”firstname” string(64), country string(64) , phone string(10) REPEATING) WITH SUPERTYPE “dm_document”

Modify a Simple Object Type (Adding a new Attribute)
ALTER TYPE “mycustomtype” Add lastname string (64), age integer, height double, weight double

Modity a Simple Object Type (Deleting an Attribute)

ALTER TYPE mycustomtype drop weight

Modify a Simple Object type (Modify existing attribute)
ALTER TYPE mycustomtype MODIFY firstname string (121)
(Modifying a object type attribute has many constrains)

Create a Object and set attributes
CREATE mycustomtype OBJECT SET “firstname” = ‘Hello World’, SET “country”= ‘US’, SET phone [0]= ‘1111111111’

Update a Object Attribute
update dm_document object set object_name = ’new_name’ where object_name = ‘old_name’

Adding a value to a repeated attribute
update dm_document objects set keywords[0]=’value’ where r_object_id=’09xxxxxx’

Delete a Object
delete dm_document object where object_name=’object_name’

Delete All Objects of a Object type
delete my_custom_object (all) objects

Dropping a type
drop type “my_custom_object”

To know attributes of a object type
describe <object_type>
e.g. describe dm_document

Usage of Dates in Where Clause
select r_object_id, object_name from dm_document where r_modify_date > DATE(’01/01/2008 00:00:00′,’MM/DD/YYYY hh:mm:ss’) AND r_modify_date < DATE(’TODAY’)

To Find Objects those have Same (Duplicate) Name
SELECT object_name, count(*) from dm_document GROUP BY object_name having count (*) > 1 order by object_name

Usage of NULLSTRING
select object_name from my_object_type where my_attribute is NULLSTRING
select object_name from my_object_type where my_attribute is not NULLSTRING
First Query will return Object name of all the objects that has my_attributes as blank
Second Query will return Object name of all the objects that has some values in my_attributes (non-blanks)

Usage of DATEDIFF
(This query will return all dm_documents that are created between today and the last 2 weeks)
select * from dm_document where DATEDIFF(week, “r_creation_date” , DATE(TODAY))<=2
DATEDIFF(date_part, date1, date2)
DATEDIFF function returns the number that represents the difference between given two dates.
Valid values for date_part are year, month, week, and day and date1 is subtracted from date2

To Return N number of Records
select * from dm_sysobject ENABLE (RETURN_TOP N)
e.g. To Return only 5 records
select * from dm_sysobject ENABLE (RETURN_TOP 5)

猜你喜欢

转载自l007it.iteye.com/blog/1423872