将图像插入Oracle Apex中的表中

时间:2015-12-23 20:58:42

标签: sql oracle plsql oracle-apex

我已根据下表创建了一个表单:

CREATE TABLE  "POSTS" 
   (    "POST_ID" NUMBER(15,0) NOT NULL ENABLE, 
    "USER_ID" VARCHAR2(30) NOT NULL ENABLE, 
    "TITLE" VARCHAR2(255) NOT NULL ENABLE, 
    "TEXT" CLOB, 
    "RESPONSE_TO" NUMBER(15,0), 
    "FLAGGED" CHAR(1), 
    "MIMETYPE" VARCHAR2(50), 
    "LAST_UPDATE" DATE, 
    "THUMB" BLOB, 
    "IMAGE" "ORDSYS"."ORDIMAGE" , 
    "FILENAME" VARCHAR2(255), 
     CONSTRAINT "POSTS_PK" PRIMARY KEY ("POST_ID")
  USING INDEX  ENABLE
   )
/
ALTER TABLE  "POSTS" ADD CONSTRAINT "POSTS_CON" FOREIGN KEY ("RESPONSE_TO")
      REFERENCES  "POSTS" ("POST_ID") ENABLE
/


CREATE INDEX  "POSTS_TEXT_INDEX" ON  "POSTS" ("TEXT") 
   INDEXTYPE IS "CTXSYS"."CONTEXT"
/


CREATE INDEX  "POSTS_TITLE_INDEX" ON  "POSTS" ("TITLE") 
   INDEXTYPE IS "CTXSYS"."CONTEXT"
/


CREATE OR REPLACE EDITIONABLE TRIGGER  "BI_POSTS" 
  before insert on "POSTS"               
  for each row  
begin   
  if :NEW."POST_ID" is null then 
    select "POSTS_SEQ".nextval into :NEW."POST_ID" from sys.dual; 
  end if; 
end; 

/
ALTER TRIGGER  "BI_POSTS" ENABLE
/


CREATE OR REPLACE EDITIONABLE TRIGGER  "NEW_POST" 
  BEFORE INSERT
  ON posts

FOR EACH ROW
BEGIN
  --l_image := ORDSYS.ORDImage.Init();
  --ORDSYS.ORDImage.process(:new.image, 'maxscale=200 200');

  :new.user_id := v(':APP_USER');
  --process_post_image(:new.post_id);
END;

/
ALTER TRIGGER  "NEW_POST" ENABLE
/

标题,文字和文件名字段可在表单中编辑。

要上传文件,请在自定义流程中使用以下代码代替自动生成的插入代码:

DECLARE

  l_upload_size INTEGER;
  l_upload_blob BLOB;
  l_image_id    NUMBER;
  l_image       ORDSYS.ORDImage;

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 = :P16_FILENAME;
  --
  -- Insert a new row into the table, initialising the image and
  -- returning the newly allocated image_id for later use
  --
  INSERT
  INTO
    posts
    (
      post_id,
      title,
      text,
      filename,
      image
    )
    VALUES
    (
      posts_seq.nextval,
      :P16_TITLE,
      :P16_TEXT,
      :P16_FILENAME,
      ORDSYS.ORDImage()
    )
  RETURNING
    post_id, image
  INTO
    l_image_id, l_image;

  -- 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(); 

  UPDATE
    posts
  SET
    image     = l_image -- original ORDImage image
  WHERE
    post_id = l_image_id;

END;

location of the custom process

但产生了以下错误:

Invalid action CREATE on this object. (D)

enter image description here

1 个答案:

答案 0 :(得分:1)

如果移动blob,我可以使用

成功将blob转换为ordImage
UPDATE images
SET ord_image = ORDSYS.ORDImage(image)
WHERE ...

触发器需要删除冒号

:new.user_id := v('APP_USER');

我经常使用

COALESCE(apex_application.g_user, sys_context('userenv','session_user'))