更新显示未找到数据错误

时间:2016-01-02 13:15:23

标签: sql oracle plsql

以下更新未更新我的表格。它在提交时声明以下错误消息:

  

ORA-01403:未找到数据

我确保所有字段都输入了一些数据,但它仍然表明没有数据的以下错误。任何想法或帮助?

DECLARE

  l_upload_size INTEGER;
  l_upload_blob BLOB;
  l_image_id    NUMBER;
  l_image       ORDSYS.ORDImage;
  l_name        VARCHAR2(100);
  l_address        VARCHAR2(100);  
  l_postcode       VARCHAR2(100);
  l_description   VARCHAR2(100);

BEGIN

  --
  -- Get the BLOB of the new image from the APEX_APPLICATION_TEMP_FILES (synonym for WWV_FLOW_TEMP_FILES)
  -- APEX 5.0 change from APEX_APPLICATION_FILES which has been deprecated
  -- APEX_APPLICATION_TEMP_FILES has fewer columns and is missing doc_size
  --

  SELECT
    blob_content
  INTO
    l_upload_blob
  FROM
    apex_application_temp_files
  WHERE
    name = :P3_filename;
  --
  -- Insert a new row into the table, initialising the image and
  -- returning the newly allocated image_id for later use
  --
UPDATE bars
SET
      image_id = :P3_IMAGE_ID,
      filename = :P3_FILENAME,
      image = ORDSYS.ORDImage(),
      name = :P3_NAME,
      address = :P3_ADDRESS,
      postcode = :P3_POSTCODE,
      description = :P3_DESCRIPTION

  WHERE
    image_id = l_image_id;

  -- find the size of BLOB (get doc_size)
  l_upload_size := dbms_lob.getlength(l_upload_blob);
  -- copy the blob into the ORDImage BLOB container
  DBMS_LOB.COPY( l_image.SOURCE.localData, l_upload_blob, l_upload_size );

  -- set the image properties
  l_image.setProperties(); 
  create_blob_thumbnail(l_image_id);



END;

2 个答案:

答案 0 :(得分:2)

就像Alex提到的那样,ORA-01403不会被UPDATE引发,而是由SELECT引发。 确保P3_filename有一个值,表中有匹配的数据。

简单地证明这一点,只需将SELECT包含在这样的异常块中:

....
BEGIN

  SELECT
    blob_content
  INTO
    l_upload_blob
  FROM
    apex_application_temp_files
  WHERE
    name = :P3_filename;

EXCEPTION
  WHEN NO_DATA_FOUND THEN
     <<Add your troubleshooting code here, like display the variable>>
END
.....

答案 1 :(得分:0)

也许您使用SQL%ROWCOUNT来检查受影响的行数。 Here就是一个很好的例子。