激情五月天婷婷,亚洲愉拍一区二区三区,日韩视频一区,a√天堂中文官网8

<ul id="buwfs"><strike id="buwfs"><strong id="buwfs"></strong></strike></ul>
    <output id="buwfs"></output>
  • <dfn id="buwfs"><source id="buwfs"></source></dfn>
      <dfn id="buwfs"><td id="buwfs"></td></dfn>
      <div id="buwfs"><small id="buwfs"></small></div>
      <dfn id="buwfs"><source id="buwfs"></source></dfn>
      1. <dfn id="buwfs"><td id="buwfs"></td></dfn>
        始創(chuàng)于2000年 股票代碼:831685
        咨詢熱線:0371-60135900 注冊有禮 登錄
        • 掛牌上市企業(yè)
        • 60秒人工響應(yīng)
        • 99.99%連通率
        • 7*24h人工
        • 故障100倍補(bǔ)償
        全部產(chǎn)品
        您的位置: 網(wǎng)站首頁 > 幫助中心>文章內(nèi)容

        使用存儲(chǔ)過程讀取Oracle中的clob字段的數(shù)據(jù)

        發(fā)布時(shí)間:  2012/9/16 14:05:05

        在做數(shù)據(jù)庫開發(fā)的時(shí)候,有時(shí)候會(huì)遇到需要讀取Oracle數(shù)據(jù)庫中的clob類型的數(shù)據(jù)的情況。本著代碼復(fù)用的目的,我寫了下面的存儲(chǔ)過程:讀取數(shù)據(jù)庫中clob字段的數(shù)據(jù)。希望跟大家交流一下。

        CREATE OR REPLACE PROCEDURE prc_read_clob(
          table_name IN VARCHAR2,
          clob_column_name IN VARCHAR2,-
         

          primary_Key_Column_names IN VARCHAR2,
          primary_key_values IN VARCHAR2,
          offset_i IN NUMBER,
          read_length_i IN NUMBER,
          RES OUT VARCHAR2,
          total_length OUT NUMBER
        ) AS
        /**
          Autor:Hanks_gao.
          Create Date:2008/12/10
          Description:This procedure is to read clob value by conditions
          --------------------------------------------------------------
          -----------------Parameters descritption----------------------
                        table_name : The table that contains clob/blob columns(表名)
                clob_column_name : Clob/blob column name of table_name(類型為clob的字段名)
        primary_key_column_names : The columns seperated by '}' that can fix only one row data (that is primary key) (主鍵名,以'}'分隔的字符串)
                primary_key_values : The primary keyes values that seperated by '}'(主鍵鍵值,以'}'分隔的字符串)
                          offset_i : The offset of reading clob data(要讀取的位移量)
                     read_length_i : The length of reading clob data per times(要讀取的長度)
                               res : Return value that can be referenced by application(讀取的結(jié)果)
                      total_length : The total length of readed clob data(數(shù)據(jù)庫查詢到的clob數(shù)據(jù)的總長度)
          -----------------End Parameters descritption------------------
        */

          tmpPrimaryKeys VARCHAR2(2000);  --To save primary_Key_Column_names temporarily(暫存主鍵,主鍵是以'}'分隔的字符串)
          tmpPrimaryKeyValues VARCHAR2(2000);  --To save primary_key_values temporarily(暫存主鍵鍵值,以'}'分隔的字符串)
          i NUMBER;  --循環(huán)控制變量
          tmpReadLength NUMBER; --暫存要讀取的長度
          sqlStr VARCHAR2(6000);  --Query string(查詢字符串)
          sqlCon VARCHAR2(5000);  --Query condition(查詢條件)

          TYPE tmparray IS TABLE OF VARCHAR2(5000) INDEX BY BINARY_INTEGER;
            arrayPrimaryKeys  tmparray;  --To save the analyse result of primary_Key_Column_names (暫存分析后得到的主鍵名)
            arrayPrimaryKeyValues  tmparray;  --To save the analyse result of primary_key_values(暫存分析后得到的主鍵鍵值)
        BEGIN
          total_length := 0;
          RES := '';
          DECLARE
            clobvar CLOB := EMPTY_CLOB;
          BEGIN
            tmpPrimaryKeys:=primary_Key_Column_names;
            tmpPrimaryKeyValues:=primary_key_values;

            i:=0;
            WHILE INSTR(tmpPrimaryKeys,'}')>0 LOOP --Analyse the column names of primary key(將主鍵分開,相當(dāng)于arrayPrimaryKeys =tmpPrimaryKeys.split("}") )
              arrayPrimaryKeys(i):=subSTR(tmpPrimaryKeys,1,(INSTR(tmpPrimaryKeys,'}')-1));
              tmpPrimaryKeys:=subSTR(tmpPrimaryKeys,(INSTR(tmpPrimaryKeys,'}')+1));
              i:=i+1;
            END LOOP;

            i:=0;
            WHILE INSTR(tmpPrimaryKeyValues,'}')>0 LOOP --Analyse the values of primary key
              arrayPrimaryKeyValues(i):=subSTR(tmpPrimaryKeyValues,1,(INSTR(tmpPrimaryKeyValues,'}')-1));
              tmpPrimaryKeyValues:=subSTR(tmpPrimaryKeyValues,(INSTR(tmpPrimaryKeyValues,'}')+1));
              i:=i+1;
            END LOOP;

            IF arrayPrimaryKeys.COUNT()<>arrayPrimaryKeyValues.COUNT() THEN  --判斷鍵與鍵值是否能匹配起來
              res:='KEY-VALUE NOT MATCH';
              RETURN;
            END IF;

            i := 0;
            sqlCon  := '';
            WHILE i < arrayPrimaryKeys.COUNT() LOOP
              sqlCon := sqlCon || ' AND ' || arrayPrimaryKeys(i) || '='''
                      || replace(arrayPrimaryKeyValues(i),'''','''''') || '''';
              i := i + 1;
            END LOOP;

            sqlStr := 'SELECT ' || clob_column_name || ' FROM ' || table_name
                || ' WHERE 1=1 ' || sqlCon || ' AND ROWNUM = 1' ;  --組查詢字符串


            dbms_lob.createtemporary(clobvar, TRUE);
            dbms_lob.OPEN(clobvar, dbms_lob.lob_readwrite);

            EXECUTE IMMEDIATE TRIM(sqlStr) INTO clobvar;  --執(zhí)行查詢
           
            IF offset_i <= 1 THEN
              total_length:=dbms_lob.getlength(clobvar);
            END IF;
           
            IF read_length_i <=0 THEN
              tmpReadLength := 4000;
            ELSE
              tmpReadLength := read_length_i;
            END IF;
           
            dbms_lob.READ(clobvar,tmpReadLength,offset_i,res);  --讀取數(shù)據(jù)
           
            IF dbms_lob.ISOPEN(clobvar)=1 THEN
              dbms_lob.CLOSE(clobvar);
            END IF;

          END;
        EXCEPTION
          WHEN OTHERS THEN
            res:='';
            total_length:=0;
        END;

         


        本文出自:億恩科技【mszdt.com】

        服務(wù)器租用/服務(wù)器托管中國五強(qiáng)!虛擬主機(jī)域名注冊頂級(jí)提供商!15年品質(zhì)保障!--億恩科技[ENKJ.COM]

      2. 您可能在找
      3. 億恩北京公司:
      4. 經(jīng)營性ICP/ISP證:京B2-20150015
      5. 億恩鄭州公司:
      6. 經(jīng)營性ICP/ISP/IDC證:豫B1.B2-20060070
      7. 億恩南昌公司:
      8. 經(jīng)營性ICP/ISP證:贛B2-20080012
      9. 服務(wù)器/云主機(jī) 24小時(shí)售后服務(wù)電話:0371-60135900
      10. 虛擬主機(jī)/智能建站 24小時(shí)售后服務(wù)電話:0371-60135900
      11. 專注服務(wù)器托管17年
        掃掃關(guān)注-微信公眾號(hào)
        0371-60135900
        Copyright© 1999-2019 ENKJ All Rights Reserved 億恩科技 版權(quán)所有  地址:鄭州市高新區(qū)翠竹街1號(hào)總部企業(yè)基地億恩大廈  法律顧問:河南亞太人律師事務(wù)所郝建鋒、杜慧月律師   京公網(wǎng)安備41019702002023號(hào)
          0
         
         
         
         

        0371-60135900
        7*24小時(shí)客服服務(wù)熱線