2012-11-14 24 views
1

我有以下存儲過程錯誤數量或參數類型,而在Oracle數據庫中插入的Blob空存儲過程

create or replace procedure cust_details(idValue Custdetails.id_value%type, 
                idUser Custdetails.id_user%type, 
                idType Custdetails.id_type%type, 
                nickName Custdetails.nickname%type, 
                imageData Custdetails.IMAGE%type) IS 
    bene_id  number(10); 
    current_seq number(10); 
    isExist  number(2); 
BEGIN 

    select count(*) 
    into isExist 
    from iddetails 
    where id_value = idValue; 

    if isExist = 0 then 
    select beneficiary_seq.nextval into current_seq from dual; 
    insert into details 
     (beneficiary_id, date_added) 
    values 
     (current_seq, sysdate); 
    insert into Custdetails 
     (beneficiary_id, id_user, nickname,image) 
    valuesnumber 
     (current_seq, idUser, nickName,imageData); 
    insert into iddetails 
     (beneficiary_id, id_type, id_value) 
    values 
     (current_seq, idType, idValue); 
    else 
    select beneficiary_id 
     into bene_id 
     from iddetails 
    where id_value = idValue; 
    insert into Custdetails 
     (beneficiary_id, id_user, nickname,image) 
    values 
     (bene_id, idUser, nickName,imageData); 
    end if; 
END; 

--Custdetails.idValue is varchar2(40) 
--Custdetails.IMAGE is Blob 

,我把它從Java類像以下:

CallableStatement callableStatement = con.prepareCall("{CALL cust_details(?,?,?,?,?)}"); 
    callableStatement.setString(1, "9855154"); 
callableStatement.setString(2, "123"); 
callableStatement.setString(3, "sdsd"); 
callableStatement.setString(4, "ssdsd"); 
    byte [] imageData = l_rs.getBlob (0); // setting bytes 
    if(// if byte array has data){ 
     Blob imgDataBlob = con.createBlob(); 
     imgDataBlob.setBytes(1, imageData); 
     callableStatement.setBlob(5, imgDataBlob); 
    } 
    else{ 
     // even this is giving same error i also tried OracleTypes.Blob 
     callableStatement.setNull (2, java.sql.Types.BLOB); 
    } 
     callableStatement.execute(); 

但調用此過程在if和else兩種情況下都會產生以下錯誤

導致:java.sql.SQLException:ORA-06550:第1行第7列: PLS-00306:錯號碼或類型的呼叫參數「CUST_DETAILS」

任何想法,我在做什麼錯在這裏

+0

您是否嘗試過與Oracle特定的數據類型(C對'OracleCallableStatement'的聲明和使用'oracle.sql.BLOB')? –

+0

是的,我試過(OracleTypes.BLOB),但是同樣的錯誤 – user460293

+0

@ user460293檢查執行是否到達if和else部分。 – user75ponic

回答

1

我已經工作正常以下,司機我使用Ojdbc14.jar

CREATE OR REPLACE PROCEDURE my_proc (idvalue  NUMBER, 
    imagedata  tobedeleted.img%TYPE 
               ) 
IS 
BEGIN 
    INSERT INTO tobedeleted 
     VALUES (idvalue, imagedata 
       ); 
END my_proc; 

Java代碼

ResultSet res = sta.executeQuery(
      "SELECT * FROM TOBEDELETED for update "); 
      while (res.next()) { 
      myblob = res.getBlob("IMG"); 

      }  
    callablestatement = 
      conn.prepareCall("{CALL my_proc(?,?)}"); 
    callablestatement.setInt(1, 100);   
      if(myblob==null){    
     callablestatement.setNull(2,java.sql.Types.BLOB); 

    } 
    else { 
     byte[] chuck = {(byte)0x00, (byte)0x00, (byte)0x00, 
        (byte)0x00, (byte)0x00, (byte)0x00}; 
       myblob.setBytes(1,chuck); 
    callablestatement.setBlob(2,myblob); 
    } 
    int affectedRows = callablestatement.executeUpdate(); 
+0

大概'IMG'不爲空,那麼'myblob'也不爲空?使blob空的前六個字節與具有空的blob不同。我認爲在有些東西要傳遞給參數時,OP是可以的,當沒有(在'else'分支中)時,'setNull()'有問題。 –

+1

@AlexPoole我已經修改了我的答案以配合null,它完美地工作。我想這可能與駕駛者有關,只能猜測。 – user75ponic

相關問題