Recently, in an sns project, PDO is used to connect to the Oracle database and read the Clob field. When the data volume is very large (tens of thousands of characters), a null value is returned, no relevant information was found from the Internet. I worked hard and helped my colleagues to solve the problem. If you don't talk nonsense, post the content below.
Recently, in an sns project, PDO is used to connect to the Oracle database and read the Clob field. When the data volume is very large (tens of thousands of characters), a null value is returned, no relevant information was found from the Internet. I worked hard and helped my colleagues to solve the problem. If you don't talk nonsense, post the content below.
First, create a stored procedure get_clob:
T_name: name of the table to be queried; f_name: name of the field to be queried; u_id: Primary Key of the table, query condition; l_pos: Start position of the truncation; l_amount: truncation length;
Create or replace procedure get_clob (t_name in varchar2, f_name in varchar, u_id in integer, l_pos in integer, l_amount in BINARY_INTEGER, ReturnValue out varchar2) is
Rule_xml clob;
Rochelle buffer varchar2 (3999 );
Rochelle amount _ BINARY_INTEGER;
Begin
Execute immediate 'select' | f_name | 'from' | t_name | 'where id =: 1 'into rule_xml using u_id;
Rochelle amount _: = l_amount;
DBMS_LOB.read (rule_xml, l_amount _, l_pos, l_buffer );
ReturnValue: = l_buffer;
End get_clob;
Then the php processing program:
$ Content = "";
$ Num = 0; // clob Field Length
$ Stmt = $ oracle-> prepare ("select length (content) as num from test where id = $ id ");
If ($ stmt-> execute () {// zsequence is the query Condition
$ Row = $ stmt-> fetch ();
$ Num = $ row ['num'];
}
$ Start = 1; // initialization start position
$ Len = 2500; // capture Length
$ T_name = 'test'; // operation table name
$ F_name = 'content'; // name of the clob field to be queried
While ($ start <= $ num ){
$ Ret = '';
$ SQL = "begin get_clob (?,?,?,?,?,?); End ;";
$ Stmt = $ oracle-> prepare ($ SQL );
$ Stmt-> bindParam (1, $ t_name, PDO: PARAM_STR, 100 );
$ Stmt-> bindParam (2, $ f_name, PDO: PARAM_STR, 100 );
$ Stmt-> bindParam (3, $ id, PDO: PARAM_STR, 100 );
$ Stmt-> bindParam (4, $ start, PDO: PARAM_STR, 100 );
$ Stmt-> bindParam (5, $ len, PDO: PARAM_STR, 100 );
$ Stmt-> bindParam (6, $ ret, PDO: PARAM_STR, 5000 );
$ Stmt-> execute ();
$ Content. = $ ret;
$ Start = $ start + $ len;
}
$ Oracle = null;
The above is the complete solution. This method is not the first one. Most people who have worked on pb projects should be familiar with this operation.
The number of php Oracle operations is still relatively small on the Internet, and there is not much to solve the problem. I will share it with you. There are certainly other good solutions, you are welcome to discuss with us.