更新BLOB列,ORA-01461:只能绑定LONG值以插入LONG列

时间:2016-04-19 12:11:07

标签: oracle

我想在BLOB列中存储一个过程,不幸的是我无法向您显示代码,但它包含126行。这是我正在使用的更新

DECLARE   str varchar2(20000);
BEGIN   str :='create or replace A_LONG_PROCEDURE  procedure .........';
UPDATE tab1 SET  report=str
WHERE reference= 'TER';
commit;
end;
/

我收到错误ORA-01461; can bind a LONG value only for insert into a LONG column

我尝试使用更新.. set ='CREATE OR REPLACE LONG_PROCEDURE ...'我收到错误01704字符串litteral到long

如何将长程序更新为blob列?

2 个答案:

答案 0 :(得分:1)

这应该可行,考虑将列更改为clob。

DECLARE   
  declare str tab1.report%type;
BEGIN   
  str:= to_blob(utl_raw.cast_to_raw('create or replace     A_LONG_PROCEDURE...'));

  UPDATE tab1 SET  report=str
  WHERE reference= 'TER';

  commit;
end;
/

答案 1 :(得分:0)

您需要将列类型更改为CLOB或将CLOB变量初始化为过程文本,然后在插入前将其转换为BLOB create table lob_sample( id number, clob_field clob, blob_field blob ); insert into lob_sample(id) values(1); 过程。

Oracle 11g示例:

表格设置:

declare 
  vSomeLongString varchar2(32767);
  vClob CLOB;          
  vBlob BLOB;
begin

  -- Build sample string from all_objects view
  for cFill in (
    select object_type||' '||owner||'.'||object_name||'; '||chr(10) sample_string
    from all_objects
  ) loop                                              

    vSomeLongString := vSomeLongString || cFill.sample_string;
    if(length(vSomeLongString) > 32000) then exit; end if;
  end loop;                                       


  -- String may be directly assigned to CLOB
  vClob := vSomeLongString;

  -- And it's possible to simple assign CLOB variable value to CLOB field 
  update lob_sample set clob_field = vClob where id = 1;

  -- Even, string value may be directly assigned to CLOB field
  update lob_sample set clob_field = vSomeLongString where id = 1;

  -- But for BLOB field conversion are needed.     
  -- BLOB is just a set of raw bytes and it may present 
  -- any character set as well as non-text data.
  dbms_lob.CreateTemporary(vBlob, false);                       
  declare
    vDestOffset  integer := 1;
    vSrcOffset   integer := 1;
    vDefaultCSID number  := dbms_lob.default_csid;
    vLangContext integer := dbms_lob.default_lang_ctx;
    vWarning     integer;
  begin               
    dbms_lob.convertToBlob(
      vBlob, vClob, dbms_lob.LobMaxSize,
      vDestOffset, vSrcOffset, vDefaultCSID, vLangContext, vWarning
    );  
  end;  

  update lob_sample set blob_field = vBlob where id = 1;

  dbms_lob.freetemporary(vBlob);

end;

代码:

var pendingAuthRequest;
this.responseError = function(response) {
    if (response.status === 401 { //slightly truncated for brevity
        var defer = $q.defer();
        if (!pendingAuthRequest) { 
            pendingAuthRequest = AuthenticationService.refreshToken();
        }
        pendingAuthRequest.then(
            function() {
                pendingAuthRequest = undefined;
                defer.resolve(response);
            },
            function() {
                pendingAuthRequest = undefined;
                defer.reject(response);
            }
        );
        return defer.promise.then(
            function() {
                return ResolverService.get.$http(response.config);
            },
            function() {
                //probably a righter way to do this
                ResolverService.get.$state.transitionTo('login');
                return $q.reject(response);
            }
        );
    }
    else {
        return $q.reject(response);
    }
};