PDO取Oracle lob大字段,当数据量太大无法取出的问题的解决办法
时间:2024-01-15 00:47:43
首先,创建一个存储过程 get_clob:
t_name:要查询的表名;f_name:要查询的字段名;u_id:表的主键,查询条件;l_pos:截取的开始位置; l_amount :截取长度;
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;
l_buffer varchar2(3999);
l_amount_ BINARY_INTEGER;
begin
execute immediate 'select ' ||f_name|| ' from ' ||t_name|| ' where id=:1' into rule_xml using u_id;
l_amount_:=l_amount;
DBMS_LOB.read(rule_xml, l_amount_, l_pos, l_buffer);
ReturnValue := l_buffer;
end get_clob;
然后是php的处理程序:
$content = "";
$num = 0;//clob字段长度
$stmt = $oracle->prepare("select length(content) as num from test where id = $id");
if ($stmt->execute()) { //zjh为查询的条件
$row = $stmt->fetch();
$num = $row['NUM'];
}
$start = 1;//初始化开始位置
$len = 2500;//截取长度
$t_name = 'test';//操作表名
$f_name = 'content';//需要查询的clob字段名
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;
以上就是完整的解决办法,这个方法不是俺的首创,做过pb项目的人大多数应该比较熟悉这种操作。
php操作Oracle的资料网上还是比较少的,能解决问题的就更不多了,发出来跟大家分享一下,肯定还有其他比较好的解决办法,欢迎跟大家一起探讨。
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python&Matlab实现炫酷的3D旋转图
![](https://img.aspxhome.com/file/2023/6/118426_0s.jpg)
asp产生不重复的随机数
getWindow与isWindow
python tkinter图形界面代码统计工具
![](https://img.aspxhome.com/file/2023/2/131732_0s.jpg)
javascript中的数字与字符串相加实例分析
python字符串判断密码强弱
javascript 通用滑动门tab类
python中字符串数组逆序排列方法总结
通过Django Admin+HttpRunner1.5.6实现简易接口测试平台
![](https://img.aspxhome.com/file/2023/1/130611_0s.png)
ASP返回某年总共有多少天的代码
php中关于hook钩子函数底层理解
Python中isnumeric()方法的使用简介
Python cookbook(数据结构与算法)让字典保持有序的方法
pytorch geometric的GNN、GCN的节点分类方式
python实现AdaBoost算法的示例
如何在Python3中使用telnetlib模块连接网络设备
JS实现单击输入框弹出选择框效果完整实例
![](https://img.aspxhome.com/file/2023/9/135649_0s.png)
Python计算已经过去多少个周末的方法
详解Python手写数字识别模型的构建与使用
![](https://img.aspxhome.com/file/2023/2/100292_0s.png)
python中not not x 与bool(x) 的区别
![](https://img.aspxhome.com/file/2023/1/120371_0s.png)