Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Introducing LOB Locators

  • Last Updated : 28 Jun, 2019

Large object (LOB) locators let you reference a LOB in Transact-SQL statements rather than referencing the LOB itself as the size of a text can be unitext, or image LOB can be many megabytes. Using a LOB locator in Transact-SQL statements helps to reduce network traffic between the client and SAP ASE and also reduces the amount of memory which would be needed by the client to process the LOB. SAP ASE or Sybase ASE help client applications to send and receive locators as host variables and parameter markers.

A LOB locator will remain valid for the duration of the transaction in which it was created. SAP ASE performs validation which invalidates the locator whenever the transaction commits or is rolled back.

Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.


Datatypes used in LOB Locators:
LOB locators use three different datatypes:

  • text_locator: for text LOBs.

  • unitext_locator: for unitext LOBs.

  • image_locator: for image LOBs.

Declaring a local variable for the LOB Locator: One can declare local variables for the locator datatypes.
For example:

declare @v1 text_locator

Because LOBs and locators are stored only in memory, you cannot use locator datatypes as column datatypes for user tables or views, or in constraints or defaults.

Creating a LOB Locator: One can create a LOB locator explicitly or implicitly.

In general, when LOB locator is used in a Transact-SQL statement, locators are implicitly converted to the LOB they reference. That is, whenever a LOB locator is passed to a Transact-SQL function, the function operates on the LOB that is referenced by the locator.

Any changes you make to the LOB referenced by the locator are not reflected in the source LOB in the database—unless you explicitly save them. Similarly, if any changes you make to the LOB stored in the database will be not reflected in the LOB referenced by the locator.

A LOB instance has both a locator and a value. The LOB locator is referred to where the LOB value is physically stored. The LOB value is termed as the data stored in the LOB.

Whenever you use a LOB in an operation such as passing a LOB as a parameter, you are actually passing a LOB locator. For most of the part, you can work with a LOB instance in your application without being concerned with the semantics of LOB locators. There is no need to de-reference LOB locators because it is required with pointers in some programming languages.

There are still some issues regarding the semantics of LOB locators and how LOB values are stored that you should be aware of.

Temporary LOBs

You can also create temporary LOBs, that are like local variables, to assist the use of database LOBs. Temporary LOBs are not associated with any table, they are only accessible by their creator, have locators (which is how they are accessed), and are deleted when a session ends.

There is no support for temporary BFILES. Temporary LOBs are only permitted to be input variables (IN values) in the WHERE clauses of INSERT, UPDATE, or DELETE statements. They are also permitted as values inserted by an INSERT statement, or a value in the SET clause of an UPDATE statement. Temporary LOBs have no transactional support from the database server, which means that you cannot do COMMITS or ROLLBACKs on them.

Temporary LOB locators can span transactions. They also are deleted when the server abnormally terminates, and when an error is returned from a database SQL operation.

LOB Locators in Your Application
To use a LOB locator in Pro*C/C++ application, we have to include the oci.h header file and have to declare a pointer to the type OCIBlobLocator for BLOBs, OCIClobLocator for CLOBs and NCLOBs, or OCIBFileLocator for BFILEs.

For an NCLOB, you can either

  • Use the clause ‘CHARACTER SET IS NCHAR_CS’ in Pro*C/C++ declaration,

  • Or, you must have already used an NLS_CHAR precompiler option on the command line or in a configuration file to set the NLS_NCHAR environment variable.
My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!