CREATE TABLE "MYIMAGES_TBL"
( "ID" NUMBER NOT NULL ENABLE,
"IMAGE_NAME" VARCHAR2(400),
"FILENAME" VARCHAR2(350),
"MIME_TYPE" VARCHAR2(255),
"DOC_SIZE" NUMBER,
"CHARSET" VARCHAR2(128),
"LAST_UPDATE_DATE" DATE,
"CONTENT" BLOB,
CONSTRAINT "MYIMAGES_TBL_PK" PRIMARY KEY ("ID")
USING INDEX ENABLE
)
/
CREATE OR REPLACE EDITIONABLE TRIGGER "BI_MYIMAGES_TBL"
before insert on "MYIMAGES_TBL"
for each row
begin
if :NEW."ID" is null then
select "MYIMAGES_TBL_SEQ".nextval into :NEW."ID" from sys.dual;
end if;
end;
/
ALTER TRIGGER "BI_MYIMAGES_TBL" ENABLE
/
CREATE SEQUENCE MYIMAGES_TBL_SEQ
MINVALUE 1
MAXVALUE 999999999999999999999999999
START WITH 1
INCREMENT BY 1
CACHE 20;
Step 2
create blank page
& item P13_FILENAME text ,
P13_MIME_TYPE text,
P13_CONTENT file browse
--This page after submit plsql code
declare
doc_size integer;
Upload_blob blob;
begin
--Copy BLOB to Upload_blob variable
select blob_content
into Upload_blob
from APEX_APPLICATION_TEMP_FILES
where name = :P75_FILE_BROWSER;
--Get BLOB size
doc_size := dbms_lob.getlength(Upload_blob);
--Copy data to table MyIMAGES_TBL
if doc_size <= 1000000 then
insert into MyIMAGES_TBL (
IMAGE_NAME, FILENAME,
MIME_TYPE, DOC_SIZE,
CONTENT )
select :FILE_NAME, filename,
mime_type, doc_size,
blob_content
from APEX_APPLICATION_TEMP_FILES
where name = :P75_FILE_BROWSER;
--Delete temp files
delete from APEX_APPLICATION_TEMP_FILES where name = :P75_FILE_BROWSER;
else
delete from APEX_APPLICATION_TEMP_FILES where name = :P75_FILE_BROWSER;
commit;
raise_application_error(-20001,'Cannot upload pictures bigger than 1MB!');
end if;
exception
when others then
raise_application_error(-20001,'Error when uploading image!');
end;
Step 3
Run
No comments:
Post a Comment