%OBJECT (SQL)
Synopsis
%OBJECT(stream)
Description
%OBJECT is used to open a stream object and return the OREF (object reference) of the stream field.
A SELECT on a stream field returns the fully formed OID (object ID) value of the stream field. A SELECT %OBJECT on a stream field returns the OREF (object reference) of the stream field.
If stream is not a stream field, %OBJECT generates an SQLCODE -128 error.
%OBJECT can be used as an argument to the following functions:
-
CHARACTER_LENGTH(%OBJECT(streamfield)), CHAR_LENGTH(%OBJECT(streamfield)), or DATALENGTH(%OBJECT(streamfield)).
-
SUBSTRING(%OBJECT(streamfield),start,length).
You can perform the same operation by issuing a SELECT on a stream field, then opening the stream OID by calling the $Stream.Object.%Open()Opens in a new tab class method, which generates an OREF from the OID:
SET oref = ##class(%Stream.Object).%Open(oid)
For information on OREFs, see OREF Basics. For information on OIDs, see Identifiers for Saved Objects: ID and OID.
Arguments
stream
An expression that is the name of a stream field.
Examples
The following example shows how a SELECT %OBJECT on a stream field returns the OREF, in which Notes and Picture are both stream fields:
SELECT TOP 3 Title,Notes,%OBJECT(Picture) AS Photo FROM Sample.Employee