PHP getOracleClobValue

public static function getOracleClobValue($tableName, $fieldName, $primaryKey, $pk)
{
    $sql = 'SELECT LENGTH('.$fieldName.') AS NUM FROM '.$tableName.' WHERE '.$primaryKey.'=:PK';
    $cmd = Yii::app()->db->createCommand($sql);
    $cmd->bindParam(':PK', $pk);
    $row = $cmd->queryRow();
    $num = $row['NUM'];

    $content='';

    $start = 1;
    $len = 2500; // fetch length per time
    while($start <= $num)
    {
        $ret='';
        $sql = "BEGIN GET_CLOB(:TABLE_NAME, :FIELD_NAME, :PRIMARY_KEY, :PRIMARY_KEY_VALUE, :START_POS, :FETCH_LENGTH, :RETURN_VALUE); END;";
        $cmd = Yii::app()->db->createCommand($sql);
        $cmd->bindParam(':TABLE_NAME', $tableName);
        $cmd->bindParam(':FIELD_NAME', $fieldName);
        $cmd->bindParam(':PRIMARY_KEY', $primaryKey);
        $cmd->bindParam(':PRIMARY_KEY_VALUE', $pk);
        $cmd->bindParam(':START_POS', $start);
        $cmd->bindParam(':FETCH_LENGTH', $len);
        $cmd->bindParam(':RETURN_VALUE', $ret, PDO::PARAM_STR, 5000);
        $cmd->execute();
        $content .= $ret;
        $start=$start+$len;
    }
    
    return $content;

}

CREATE OR REPLACE PROCEDURE GET_CLOB(TABLE_NAME IN VARCHAR2, FIELD_NAME IN VARCHAR, PRIMARY_KEY IN VARCHAR, PRIMARY_KEY_VALUE IN INTEGER, START_POS IN INTEGER, FETCH_LENGTH IN BINARY_INTEGER, RETURN_VALUE OUT VARCHAR2) IS RULE_XML CLOB;
FETCH_BUFFER VARCHAR2(3999);
FETCH_LENGTH_ BINARY_INTEGER;
BEGIN
EXECUTE IMMEDIATE 'SELECT ' ||FIELD_NAME|| ' FROM ' ||TABLE_NAME|| ' WHERE ' ||PRIMARY_KEY|| '=:1' INTO RULE_XML USING PRIMARY_KEY_VALUE;
FETCH_LENGTH_:=FETCH_LENGTH;
DBMS_LOB.READ(RULE_XML, FETCH_LENGTH_, START_POS, FETCH_BUFFER);
RETURN_VALUE := FETCH_BUFFER;
END GET_CLOB;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值