Monday, October 26, 2009

Restrict or Protect Oracle Forms Developer from SQL Injection.

For Developer6i:
FORMS60_RESTRICT_ENTER_QUERY=true/false

For Developer9i/10g:
Open Default.env file from the foollowing path
\forms90\server\default.env
and write FORMS90_RESTRICT_ENTER_QUERY=true/false
Must restart from service/oc4j.

Wednesday, October 21, 2009

Data Convert From a FILE to CLOB

CREATE OR REPLACE Procedure Dpr_fileToClob(Fname in VARCHAR2, Fdir in VARCHAR2, Outclob out CLOB)
IS

fclob CLOB;
theBFile BFILE;
num NUMBER :=0;
src_offset NUMBER :=1;
dest_offset NUMBER :=1;
lang_context NUMBER :=1;

BEGIN

dbms_lob.createtemporary(fclob,FALSE,DBMS_LOB.SESSION);

theBFile := BFileName(Fdir,Fname);

dbms_lob.fileOpen(theBFile);

dbms_lob.loadClobFromFile(dest_lob =>fclob,
src_bfile =>theBFile,
amount =>dbms_lob.getLength(theBFile),
dest_offset =>dest_offset,
src_offset =>src_offset,
bfile_csid =>0,
lang_context =>lang_context,
warning =>num
);

dbms_lob.fileClose(theBFile);

Outclob := fclob;

end;
/

Data Convert From a FILE to BLOB

CREATE OR REPLACE Procedure Dpr_fileToBlob(Fname in VARCHAR2, Fdir in VARCHAR2, OutBlob out BLOB)

IS

fblob BLOB;
theBFile BFILE;

Bsrc_offset NUMBER :=1;
Bdest_offset NUMBER :=1;

BEGIN

dbms_lob.createtemporary(fblob,FALSE,DBMS_LOB.SESSION);

theBFile := BFileName(Fdir,Fname);

dbms_lob.fileOpen(theBFile);

dbms_lob.loadblobfromfile(dest_lob => fblob ,
src_bfile => theBFile ,
amount => dbms_lob.getLength(theBFile),
dest_offset => Bdest_offset,
src_offset => Bsrc_offset
);

dbms_lob.fileClose(theBFile);

OutBlob := fblob;

End;
/

Data Convert From CLOB to BLOB

CREATE OR REPLACE Function Fnc_Clob_to_Blob (P_clob_in in clob)
Return blob

is
v_blob blob;
v_offset integer;
v_buffer_varchar varchar2(32000);
v_buffer_raw raw(32000);
v_buffer_size binary_integer := 32000;

Begin
--
If p_clob_in is null Then
return null;
End If;
--
DBMS_LOB.CREATETEMPORARY(v_blob, TRUE);
v_offset := 1;

FOR i IN 1..CEIL(DBMS_LOB.GETLENGTH(p_clob_in) / v_buffer_size)

Loop

dbms_lob.read(p_clob_in, v_buffer_size, v_offset, v_buffer_varchar);
v_buffer_raw := utl_raw.cast_to_raw(v_buffer_varchar);

dbms_lob.writeappend(v_blob, utl_raw.length(v_buffer_raw), v_buffer_raw);
v_offset := v_offset + v_buffer_size;

End Loop;

Return v_blob;

End Fnc_Clob_to_Blob;
/

Monday, October 19, 2009

Clear or Delete Htree Data form Htree View

PROCEDURE Prc_Clear_Htree_Data(P_Tree_item varchar2,
P_Search_String varchar2)
IS
/*
* P_Tree_item - Htree Item.
* P_Search_String - Tree Node Label that which you want to Delete/Clear.
* give the exact node label (Character must be same).
*
* This Procedure will clear or delete Tree View from your given
* search_string & child node.
*/
Htree Item;
DeleteNode FTREE.NODE;
ItemName Varchar2(30) :=p_Tree_item;
vSearchString Varchar2(200):=p_Search_String;

BEGIN
Htree := FIND_ITEM(ItemName);

DeleteNode := FTREE.FIND_TREE_NODE(htree,vSearchString,FTREE.FIND_NEXT ,
FTREE.NODE_LABEL,
FTREE.ROOT_NODE ,
FTREE.ROOT_NODE
);
IF NOT FTREE.ID_NULL(DeleteNode)
THEN FTREE.DELETE_TREE_NODE(Htree, DeleteNode);
END IF;
END;

Wednesday, September 30, 2009

Read XML data from a CLOB file which is already stored into Database

CREATE TABLE XML_LOAD_IN
(
FILE_ID VARCHAR2(13 BYTE),
FILE_NAME VARCHAR2(200 BYTE),
XML_CFILE CLOB,
);


ALTER TABLE XML_LOAD_IN ADD (PRIMARY KEY (FILE_ID));

--==========================================================================


CREATE TABLE BCR
(
"ItemsWithinBundleCount" NUMBER(4) NOT NULL,
"BundleTotalAmount" NUMBER(12) NOT NULL,
"MICRValidTotalAmount" NUMBER(12),
"ImagesWithinBundleCount" NUMBER(5),
"UserField" VARCHAR2(5 BYTE)
);

--==========================================================================

/*** We assume that a XML file is Stored into your table ***/

CREATE OR REPLACE procedure Dpr_Read_Xml_Data(p_file_id in varchar2)
is
l_clob CLOB;
l_parser dbms_xmlparser.Parser;
l_doc dbms_xmldom.DOMDocument;
l_nl dbms_xmldom.DOMNodeList;
l_n dbms_xmldom.DOMNode;

TYPE tab_type IS TABLE OF BCR%ROWTYPE;
t_tab tab_type := tab_type();

BEGIN

Begin

select xml_cfile
into l_clob
from xml_load_in
where file_id = p_file_id;


Exception
When no_data_found then
raise_application_error(-2001,'XML File Not Found.');
When others then null;
End;


l_parser := dbms_xmlparser.newParser;
dbms_xmlparser.parseClob(l_parser, l_clob);
l_doc := dbms_xmlparser.getDocument(l_parser);

dbms_xmlparser.freeParser(l_parser);
l_nl := dbms_xslprocessor.selectNodes(dbms_xmldom.makeNode(l_doc),'/OCE/CashLetter/Bundle/BundleControl');
/* Edit above xml node as your required */

FOR CUR_BCR IN 0 .. dbms_xmldom.getLength(l_nl) - 1 LOOP
l_n := dbms_xmldom.item(l_nl, CUR_BCR);
t_tab.extend;

-- Use XPATH syntax to assign values to he elements of the collection.

dbms_xslprocessor.valueOf(l_n,'ItemsWithinBundleCount/text()' ,t_tab(t_tab.last)."ItemsWithinBundleCount" );
dbms_xslprocessor.valueOf(l_n,'BundleTotalAmount/text()' ,t_tab(t_tab.last)."BundleTotalAmount" );
dbms_xslprocessor.valueOf(l_n,'MICRValidTotalAmount/text()' ,t_tab(t_tab.last)."MICRValidTotalAmount" );
dbms_xslprocessor.valueOf(l_n,'ImagesWithinBundleCount/text()' ,t_tab(t_tab.last)."ImagesWithinBundleCount" );
dbms_xslprocessor.valueOf(l_n,'UserField/text()' ,t_tab(t_tab.last)."UserField" );
END LOOP;


FOR CUR_BCR IN t_tab.first .. t_tab.last LOOP

INSERT INTO BCR
("ItemsWithinBundleCount" ,
"BundleTotalAmount" ,
"MICRValidTotalAmount" ,
"ImagesWithinBundleCount" ,
"UserField"
)
VALUES
(t_tab(CUR_BCR)."ItemsWithinBundleCount" ,
t_tab(CUR_BCR)."BundleTotalAmount" ,
t_tab(CUR_BCR)."MICRValidTotalAmount" ,
t_tab(CUR_BCR)."ImagesWithinBundleCount" ,
t_tab(CUR_BCR)."UserField"
);

END LOOP;

COMMIT;

dbms_xmldom.freeDocument(l_doc);

EXCEPTION
WHEN OTHERS THEN
dbms_xmlparser.freeParser(l_parser);
dbms_xmldom.freeDocument(l_doc);
END;
/

Tuesday, September 29, 2009

Show Database Version

Create or Replace Function Fnc_Database_version Return char IS

v_data varchar2(1000);
ShowData varchar2(4000);
p_data varchar2(4000);

Begin

For i in (select banner
from sys.v_$version)
Loop
v_data := i.banner;
ShowData:= ShowData||v_data||chr(10);
End Loop;

p_data := 'Connected to :'||chr(10)||ShowData;
p_data := substr(p_data,1,length(p_data)-1);

Return p_data;

Exception
When others then null;
End;

Manual Ordering Block Data

PROCEDURE Prc_ordering_REF ( pBlock VARCHAR2, pClause VARCHAR2, pExec VARCHAR2 default 'NO') IS
vOrder_by VARCHAR2(5);
V_ORDER VARCHAR2(500);
begin
-- Checking whether pBlock is DB Block or not
if get_block_property(pBlock, query_data_source_type) = 'TABLE' then

-- Finding out " ASC" or " DESC" from the existing "null" or "1 ASC" order clause.
-- Set " DESC" if null


vOrder_by := nvl(substr(get_block_property(pBlock, order_by),2), ' a');

-- Assigning vice-versa
if Upper(vOrder_by) = ' A' then
vOrder_by := ' ASC';
elsif Upper(vOrder_by) = ' ASC' then
vOrder_by := ' DESC';
else
vOrder_by := ' ASC';
end if;

-- Setting order by clause to the supplied block
set_block_property (pBlock, order_by, pClause||vOrder_by);

if upper(pExec) = 'YES' then
go_block(pBlock);
:system.message_level := 5;
execute_query;
:system.message_level := 0;
end if;
set_block_property(pBlock, order_by, '1'||vOrder_by);
end if;
end;

Get Form Path Dynamically

function FORM_PATH return char is
vPath varchar2(200);
vPath_Len pls_integer;
vPath_Sep char(1);
begin
vPath := get_application_property(current_form);

if get_application_property(operating_system) in ('MSWINDOWS', 'MSWINDOWS32', 'WIN32COMMON') then
vPath_Sep := '\';
else
vPath_Sep := '/';
end if;

vPath_len := instr(vPath,vPath_Sep,-1);

if vPath_Len > 0 then
vPath := substr(vPath,1,vPath_Len);
else
vPath_Len := null;
end if;
return vPath;
end;

Create A Stop Watch with Sql

function fnc_hh_mm_ss (p_ss in number) return varchar2
is
v_ss number;
v_mm number;
v_hh number;
v_temp number;
show_hh varchar2(5);
show_mm varchar2(5);
show_ss varchar2(5);
p_show_time varchar2 (500);

begin

select decode (length(floor(floor(p_ss/60)/60)), 1 , ('0'||floor(floor(p_ss/60)/60)) , (floor(floor(p_ss/60)/60)))||':'||
decode (length(mod(floor(p_ss/60),60)) , 1 , ('0'||mod(floor(p_ss/60),60)) , (mod(floor(p_ss/60),60))) ||':'||
decode (length(mod(p_ss,60)) , 1 , ('0'||mod(p_ss,60)) , (mod(p_ss,60)))
into p_show_time
from dual;

return (p_show_time);

exception
when others then
p_show_time:='00:00:00';
return (p_show_time);
end;