CLOB
CLOB stands for Character Large Object, a datatype in SQL that stores large amounts of character data, up to 4 gigabytes. It's used when standard character data types, such as CHAR or VARCHAR, are not sufficient. Unlike these smaller types, CLOBs can tolerate larger document stores, making them ideal for storing longer texts.
Example
Output
Explanation
This example creates a test_table
with a CLOB (Character Large Objects) field file_content
and other fields like id
and file_name
. It then inserts a row into the table with test_file
as the file name and ‘This is a test content for CLOB’ as the large text content. This serves as an example to handle and store large textual data in MySQL using CLOB.
Example
Output
You won’t get an explicit output from the SQL statements above. You can confirm that the data is saved correctly in the documents
table by running a SELECT command.
For example:
The output will be:
Explanation
PostgreSQL doesn’t have an explicit CLOB
data type, instead, it offers large object data types such as TEXT
and BYTEA
which can store up to 1 GB of text or binary data, fulfilling the aim of a CLOB
. The example creates a table named documents
, and then inserts a row containing a large string of text into the content
column of the table. The SELECT statement verifies that the data was saved correctly.
Example
Output
Explanation
In SQL Server, Large Object (LOB) data types can store large amounts of data. CLOB (Character Large Object) is one type of LOB that can store large amounts of character data. In SQL Server, the NVARCHAR(MAX) data type is typically used to represent CLOB. The provided code declares a variable @CLOB as NVARCHAR(MAX), sets its value to ‘This is a CLOB example’, then selects the value of the variable to output it.
Example
Output
Explanation
In this example, a CLOB data type is declared with the variable name large_text
. The TO_CLOB function is used to convert a long string of characters into a CLOB data type which can hold up to 4 GB in Oracle. ‘DBMS_OUTPUT.PUT_LINE’ is used to display the contents of the CLOB data type.
Example
Output
Explanation
In SQLite, the TEXT datatype is used instead of CLOB to store large amounts of text. The above code declares a new table named “documents”, with one of the columns set as TEXT to hold the CLOB data. This could include large text files, JSON objects, XML documents and so on. It further inserts a sentence into the created table. There’s no visible output from the INSERT
statement itself, other than a report that the query ran successfully.