简体   繁体   中英

Inserting data into a CLOB column

I'm trying to find a way to insert data on BLOB column.

During my research, I found this example on IBM web site, and I don't understand what is a "regular file".

The title of this example is "This example shows how to insert data from a regular file referenced by :hv_text_file into a CLOB column"

Is :hv_text_file a kind of variable containing the description of the file to insert in blob column?

strcpy(hv_text_file.name, "/home/userid/dirname/filnam.1");
hv_text_file.name_length = 
strlen("/home/userid/dirname/filnam.1");
hv_text_file.file_options = SQL_FILE_READ; /* this is a ’regular’ 
file */
EXEC SQL INSERT INTO CLOBTAB
VALUES(:hv_text_file);

I assume you're looking at the Db2 SQL Programming reference: IBM i 7.2 > Database > Programming > SQL programming > Processing special data types > Large objects at https://www.ibm.com/support/knowledgecenter/ssw_ibm_i_72/sqlp/rbafyexampinsertclob.htm

This is a program fragment; it assumes that you have read and understand how to reference a LOB column: IBM i 7.2 > Database > Reference > SQL reference > Language elements > Variables at https://www.ibm.com/support/knowledgecenter/ssw_ibm_i_72/db2/rbafzreferencelob.htm

There, you can see there are two types of LOB references: 1) LOB or XML locator variables 2) LOB of XML file reference variables

It looks like you want to move a stream file into a BLOB via a File reference variable. The quick summary is in the second link, but the answer to 'what is meant by regular file' is this bit:

File reference variables are currently supported in the root (/), QOpenSys, and UDFS file systems. When a file is created, it is given the CCSID of the data that is being written to the file. Currently, mixed CCSIDs are not supported. To use a file created with a file reference variable, the file should be opened in binary mode.

So, 'regular file' means IFS stream file.

The 'other half' of the program fragment that might help illustrate the example is in the SQL programming reference: IBM i 7.2 > Database > Programming > SQL programming > Processing special data types > Examples: Using UDTs, UDFs, and LOBs at https://www.ibm.com/support/knowledgecenter/ssw_ibm_i_72/sqlp/rbafyexplob.htm

The keywords you need to keep in mind are 'LOB file reference variable'.

If you're an RPG programmer, look for the SQLTYPE() keyword on the DCL-S statement https://www.ibm.com/support/knowledgecenter/ssw_ibm_i_72/rzajp/rzajpirpglobfileref.htm

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM