Pages

Sunday, November 30, 2014

PLSQL Cursor with example



PLSQL Cursor:
A cursor is a pointer to this context area. PL/SQL controls the context area through a cursor. A cursor holds the rows (one or more) returned by a SQL statement. The set of rows the cursor holds is referred to as the active set.
There are two types of cursors:
·         Implicit cursors
·         Explicit cursors

Implicit Cursor: Implicit cursors are automatically created by Oracle whenever an SQL statement is executed, when there is no explicit cursor for the statement. Programmers cannot control the implicit cursors and the information in it.

Whenever a DML statement (INSERT, UPDATE and DELETE) is issued, an implicit cursor is associated with this statement. For INSERT operations, the cursor holds the data that needs to be inserted. For UPDATE and DELETE operations, the cursor identifies the rows that would be affected.

Attribute of Implicit Cursor:
Attribute
Description
%FOUND
Returns TRUE if an INSERT, UPDATE, or DELETE statement affected one or more rows or a SELECT INTO statement returned one or more rows. Otherwise, it returns FALSE.
%NOTFOUND
The logical opposite of %FOUND. It returns TRUE if an INSERT, UPDATE, or DELETE statement affected no rows, or a SELECT INTO statement returned no rows. Otherwise, it returns FALSE.
%ISOPEN
Always returns FALSE for implicit cursors, because Oracle closes the SQL cursor automatically after executing its associated SQL statement.
%ROWCOUNT
Returns the number of rows affected by an INSERT, UPDATE, or DELETE statement, or returned by a SELECT INTO statement.


Example: The following program would update the table and increase salary of each customer by 500 and use the SQL%ROWCOUNT attribute to determine the number of rows affected:

DECLARE
   total_rows number(2);
BEGIN
   UPDATE customers
   SET salary = salary + 500;
   IF sql%notfound THEN
      dbms_output.put_line('no customers selected');
   ELSIF sql%found THEN
      total_rows := sql%rowcount;
      dbms_output.put_line( total_rows || ' customers selected ');
   END IF;
END;
/
Result:
6 customers selected
 
PL/SQL procedure successfully completed.


Explicit Cursor: Explicit cursors are programmer defined cursors for gaining more control over the context area. An explicit cursor should be defined in the declaration section of the PL/SQL Block. It is created on a SELECT Statement which returns more than one row.

Explicit cursor involves four steps:
·         Declaring the cursor for initializing in the memory
·         Opening the cursor for allocating memory
·         Fetching the cursor for retrieving data
·         Closing the cursor to release allocated memory

Example:
DECLARE
   c_id customers.id%type;
   c_name customers.name%type;
   c_addr customers.address%type;
   CURSOR c_customers is
      SELECT id, name, address FROM customers;
BEGIN
   OPEN c_customers;
   LOOP
      FETCH c_customers into c_id, c_name, c_addr;
      EXIT WHEN c_customers%notfound;
      dbms_output.put_line(c_id || ' ' || c_name || ' ' || c_addr);
   END LOOP;
   CLOSE c_customers;
END;
/

Result:
1 Ramesh Ahmedabad 
2 Khilan Delhi 
3 kaushik Kota    
4 Chaitali Mumbai 
5 Hardik Bhopal  
6 Komal MP  
 
PL/SQL procedure successfully completed.

Feature & Advantage of PLSQL



Features of PL/SQL
  • PL/SQL is completely integrated with SQL.
  • PL/SQL is a block-oriented language
  • It offers extensive error checking.
  • It offers numerous data types.
  • It offers a variety of programming structures.
  • It supports structured programming through functions and procedures.
  • It supports object-oriented programming.
  • PL/SQL is as easy to learn as it is powerful. 
  • PL/SQL is allow scripting language

Advantages of PL/SQL
  • SQL is the standard database language and PL/SQL is strongly integrated with SQL. PL/SQL supports both static and dynamic SQL. Static SQL supports DML operations and transaction control from PL/SQL block. Dynamic SQL is SQL allows embedding DDL statements in PL/SQL blocks.
  • PL/SQL allows sending an entire block of statements to the database at one time. This reduces network traffic and provides high performance for the applications.
  • PL/SQL gives high productivity to programmers as it can query, transform, and update data in a database.
  • PL/SQL saves time on design and debugging by strong features, such as exception handling, encapsulation, data hiding, and object-oriented data types.
  • Applications written in PL/SQL are fully portable.
  • PL/SQL provides high security level.
  • PL/SQL provides access to predefined SQL packages.
  • PL/SQL provides support for Object-Oriented Programming.
  • PL/SQL provides support for Developing Web Applications and Server Pages.

Tuesday, November 25, 2014

Create a parameterized view in Oracle

CREATE TABLE CITIES
 (
 REGION VARCHAR2 (30),
 COUNRTY VARCHAR2 (30),
 CITY VARCHAR2 (30)
 );

Insert into CITIES (REGION,COUNRTY,CITY) values ('AMERICA','UNITED STATED','NEW YORK');

Insert into CITIES (REGION,COUNRTY,CITY) values ('EUROPE','FRANCE','PARIS');

Insert into CITIES (REGION,COUNRTY,CITY) values ('ASIA','JAPAN','TOKYO');

Insert into CITIES (REGION,COUNRTY,CITY) values ('ASIA','INDIA','MUMBAI');

Insert into CITIES (REGION,COUNRTY,CITY) values ('EUROPE','UNITED KINGDOM','LONDON');

Insert into CITIES (REGION,COUNRTY,CITY) values ('AMERICA','UNITED STATES','WASHINGTON DC');

COMMIT;

CREATE OR REPLACE PACKAGE PKG_PARAM AS
PROCEDURE SET_REGION (P_REGION IN VARCHAR2);
FUNCTION GET_REGION RETURN VARCHAR2;
END PKG_PARAM;
/

CREATE OR REPLACE PACKAGE BODY PKG_PARAM AS
REGION VARCHAR2 (30);

PROCEDURE SET_REGION (P_REGION IN VARCHAR2)
IS
BEGIN
REGION := P_REGION;
END;

FUNCTION GET_REGION RETURN VARCHAR2
IS
BEGIN
RETURN REGION;
END;
END PKG_PARAM;
/

CREATE OR REPLACE VIEW PARAM_VIEW AS
SELECT *
FROM CITIES
WHERE REGION=PKG_PARAM.GET_REGION;

SELECT * FROM PARAM_VIEW;

no rows returned....

EXEC PKG_PARAM.SET_REGION('ASIA');

SELECT * FROM PARAM_VIEW;

Move an Item with Oracle Developer

procedure prc_move_item (p_item varchar2)
is
  x number; --Max 495(Canvas Width....)
  y number := 3; --Y Position of Move Item
  w number;
  diff_width number:=(:global.can_width-:global.item_width);
 
begin

/*
 Please Assign :global.w :=get_item_property ('control.show_title',width); (get item width)
  :global.can_width :=get_canvas_property('can_main',width); (get canvas width)
  :global.item_width :=get_item_property ('control.show_title',width); :global.x_pos:=0;
 
  in NEW-FORM-INSTANCE trigger.
 
 Also Create a Timer in NEW-FORM-INSTANCE trigger.
 This Procedure is referred into WHEN-TIMER-EXPIRED trigger.
 Change Item name which Item you want to move.
*/

  x := :global.x_pos + 1;
  w := :global.w;

  if x < :global.can_width --(Canvas Width....) Start 1
  then
  if x < diff_width --(Canvas width - Item width)Maximum Move of X position of Move Item. Start 2
  then
  if w < :global.item_width --Item Width Start 3
  then
  set_item_property (p_item, width, w);
  :global.w := :global.w + 1;
  x := 0; --X Position still 0(zero) untill item width 181.
  end if; --end 3

  set_item_property (p_item, position, x, y);
  :global.x_pos := x;
  else
  w := :global.w - 1;
  set_item_property (p_item, alignment, alignment_left);
  set_item_property (p_item, width, w);
  set_item_property (p_item, position, x, y);
  :global.w := w;
  :global.x_pos := x;
  end if; --end 2
  else
  :global.x_pos := 0;
  set_item_property (p_item, alignment, alignment_right);
  end if; --end 1
end;
/

Data Transfer from Oracle Developer to Excel

PROCEDURE fpr_forms_to_excel(p_block_name in varchar2 default NAME_IN('system.current_block'),
  p_path in varchar2 default 'C:\',
  p_file_name in varchar2 default 'Temp') IS
-- Declare the OLE objects
 application OLE2.OBJ_TYPE;
 workbooks OLE2.OBJ_TYPE;
 workbook OLE2.OBJ_TYPE;
 worksheets OLE2.OBJ_TYPE;
 worksheet OLE2.OBJ_TYPE;
 cell OLE2.OBJ_TYPE;
 range OLE2.OBJ_TYPE;
 range_col OLE2.OBJ_TYPE;

 -- Declare handles to OLE argument lists
 args OLE2.LIST_TYPE;
 arglist OLE2.LIST_TYPE;
 -- Declare form and block items
 form_name VARCHAR2(100);
 f_block VARCHAR2(100);
 l_block VARCHAR2(100);
 f_item VARCHAR2(100);
 l_item VARCHAR2(100);
 cur_block VARCHAR2(100):= NAME_IN('system.current_block');
 cur_item VARCHAR2(100);
 cur_record VARCHAR2(100);
 item_name VARCHAR2(100);
 baslik VARCHAR2(100);
 row_n NUMBER;
 col_n NUMBER;
 filename VARCHAR2(1000):= p_path||p_file_name;


 ExcelFontId OLE2.list_type;

BEGIN
  -- Start Excel
  application:=OLE2.CREATE_OBJ('Excel.Application');
  OLE2.SET_PROPERTY(application, 'Visible', 'False');

  -- Return object handle to the Workbooks collection
  workbooks:=OLE2.GET_OBJ_PROPERTY(application, 'Workbooks');

  -- Add a new Workbook object to the Workbooks collection
  workbook:=OLE2.GET_OBJ_PROPERTY(workbooks,'Add');

  -- Return object handle to the Worksheets collection for the Workbook
  worksheets:=OLE2.GET_OBJ_PROPERTY(workbook, 'Worksheets');

  -- Get the first Worksheet in the Worksheets collection
  -- worksheet:=OLE2.GET_OBJ_PROPERTY(worksheets,'Add');
  args:=OLE2.CREATE_ARGLIST;
  OLE2.ADD_ARG(args, 1);
  worksheet:=OLE2.GET_OBJ_PROPERTY(worksheets,'Item',args);
  OLE2.DESTROY_ARGLIST(args);

  -- Return object handle to cell A1 on the new Worksheet
  go_block(p_block_name);

  baslik := get_block_property(p_block_name,FIRST_ITEM);
  f_item := p_block_name||'.'||get_block_property(p_block_name,FIRST_ITEM);
  l_item := p_block_name||'.'||get_block_property(p_block_name,LAST_ITEM);
  first_record;

  LOOP
  item_name := f_item;
  row_n := NAME_IN('SYSTEM.CURSOR_RECORD');
  col_n := 1;
 
  LOOP
  IF get_item_property(item_name,ITEM_TYPE)&lt;&gt;'BUTTON' AND get_item_property(item_name,VISIBLE)='TRUE' THEN
  -- Set first row with the item names
  IF row_n=1 THEN
  args := OLE2.create_arglist;
  OLE2.add_arg(args, 1);
  OLE2.add_arg(args, col_n);
  cell := OLE2.get_obj_property(worksheet, 'Cells', args);
  OLE2.destroy_arglist(args);
  --cell_value := OLE2.get_char_property(cell, 'Value');
  ExcelFontId := OLE2.get_obj_property(Cell, 'Font');
  OLE2.set_property(ExcelFontId, 'Bold', 'True');
  --------------------------------------------
  baslik:=NVL(get_item_property(item_name,PROMPT_TEXT),baslik);
  args:=OLE2.CREATE_ARGLIST;
  OLE2.ADD_ARG(args, row_n);
  OLE2.ADD_ARG(args, col_n);
  cell:=OLE2.GET_OBJ_PROPERTY(worksheet, 'Cells', args);
  OLE2.DESTROY_ARGLIST(args);
  OLE2.SET_PROPERTY(cell, 'Value', baslik);
  OLE2.RELEASE_OBJ(cell);
  END IF;
  -- Set other rows with the item values
  args:=OLE2.CREATE_ARGLIST;
  OLE2.ADD_ARG(args, row_n+1);
  OLE2.ADD_ARG(args, col_n);
  cell:=OLE2.GET_OBJ_PROPERTY(worksheet, 'Cells', args);
  OLE2.DESTROY_ARGLIST(args);
 
  IF get_item_property(item_name,DATATYPE)&lt;&gt;'NUMBER' THEN
  OLE2.SET_PROPERTY(cell, 'NumberFormat', '@');
  END IF;
  OLE2.SET_PROPERTY(cell, 'Value', name_in(item_name));
  OLE2.RELEASE_OBJ(cell);
  END IF;
 
  IF item_name = l_item THEN
  exit;
  END IF;
  baslik := get_item_property(item_name,NEXTITEM);
  item_name := p_block_name||'.'||get_item_property(item_name,NEXTITEM);
  col_n := col_n + 1;
  END LOOP;

  EXIT WHEN NAME_IN('system.last_record') = 'TRUE';
  NEXT_RECORD;
  END LOOP;

  -- Autofit columns
  range := OLE2.GET_OBJ_PROPERTY( worksheet,'UsedRange');
  range_col := OLE2.GET_OBJ_PROPERTY( range,'Columns');
  OLE2.INVOKE( range_col,'AutoFit' );
  OLE2.RELEASE_OBJ( range );
  OLE2.RELEASE_OBJ( range_col );

  -- Save as worksheet with a Specified file path &amp; name.
  IF NVL(filename,'0')&lt;&gt;'0' THEN
  args := OLE2.CREATE_ARGLIST;
  OLE2.ADD_ARG(args,filename );
  OLE2.INVOKE(worksheet,'SaveAs',args );
  OLE2.DESTROY_ARGLIST( args );
  END IF;

  -- Release the OLE objects
  OLE2.RELEASE_OBJ(worksheet);
  OLE2.RELEASE_OBJ(worksheets);
  OLE2.RELEASE_OBJ(workbook);
  OLE2.RELEASE_OBJ(workbooks);
  OLE2.INVOKE (application,'Quit');
  OLE2.RELEASE_OBJ(application);

  -- Focus to the original location

exception
 when others then null;
  raise form_trigger_failure;
END;

Best way to derive site traffic

Best way to derive site traffic

Website traffic or visitor is an important thing for webmasters. It’s not hard to derive traffic if you follow some simple tips and tricks. Those tips will help you to derive massive traffic in your site within few days. I will discuss those tips in the following.

1. Original Content: Write always original content and avoid duplicate content for your site. Search engine will penalize your duplicate contents. Write yourself whatever you know from reading articles or searching sites. Try to keep your article’s words minimum 200 words. It will take 15 to 30 minutes to write a 200 words article. Write daily what interests you. But best will be chose a specific niche such as sports, health, relation, food, travel etc. So remember original content is king to derive website traffic.

2. Keywords: Write keywords on your article’s title and first paragraph of your article. Also try to write those keywords at the last paragraph of your article.

3. Inbound link: Keep inbound link in your content. Inbound link is to link some keywords with your other article or any other site.

4. Submit sitemap to search engine: It’s very important to submit your sitemap to popular search engines like google, yahoo and msn. You can know the way of submitting site map from searching web.

5. Submit to Article directory: Write an article according to your niche and submit it to some number of article directories. Those article directories will allow you to keep your site link and after reading your article visitor will come to your site clicking the link. Some popular article directories are Ezine, ArticlesBase, Isnare etc.

6. Join Forums: Join some forum site related to your niche and participate conversation with the members of the forum site. Keep your site or article link at the end of your speech.

7. Join Answer site: It easy to derive traffic by joining answering site. On those site you can find to many topics and members are asking questions for an specific topic. Answer the topic of your niche and keep your site link as source of your answer.

Those are the most effective and basic tips to derive traffic and if you follow those tips you will not have to wait for traffic.

Generate a XML file from Oracle Database

Grant dba to scott;

Connect scott/tiger;

CREATE OR REPLACE DIRECTORY
XML_DIR AS
'D:\';

CREATE OR REPLACE PROCEDURE Generate_XML_file ( p_filename in varchar2 default 'Dept',
p_dir in varchar2 default 'XML_DIR'
) IS
v_OutFile utl_file.file_type;
v_value varchar2(2000);
v_QryCtx DBMS_XMLQuery.ctxType;
v_Xml CLOB;
v_More BOOLEAN := TRUE;
v_SqlQuery varchar2(2000):='Select * from dept';
v_RowsetTag Varchar2(200) :='Dept';
v_RowTag varchar2(200) :='Dept';

BEGIN


v_OutFile := utl_file.fopen( p_dir, p_filename||'.xml', 'w' );
v_More := TRUE;
v_QryCtx := DBMS_XMLQuery.newContext(v_SqlQuery);
DBMS_XMLQuery.setRowsetTag(v_QryCtx, v_RowsetTag);
DBMS_XMLQuery.setRowTag(v_QryCtx, v_RowTag);
v_Xml := DBMS_XMLQuery.GetXML(v_QryCtx);
DBMS_XMLQuery.closeContext(v_QryCtx);

while v_more loop
utl_File.Put(v_OutFile, Substr(v_Xml, 1, 32767));
if length(v_Xml) &gt; 32767 then
v_Xml := substr(v_Xml, 32768);
else
v_More := FALSE;
end if;
end loop;

utl_file.fclose( v_OutFile );

Exception
when others then
utl_file.fclose( v_OutFile );
End;

--========================
exec Generate_XML_file;
--========================

Webutil Configuration for Oracle Developer10g

It is assumed that You install developer suite in drive D:\ and have webutil tools;


step-1
-----

paste webutil folder in the following path
D:\DevSuiteHome\forms90


step-2
------

Paste webutil.cfg,webutiljini.htm in the following path
D:\DevSuiteHome\forms90\server


step-3
------

Paste additional jar file in the following path
D:\DevSuiteHome\forms90\java


Step-4
------

open deafult.env file (path :&gt;&gt; D:\DevSuiteHome\forms90\server)

go to last line of file ( the line is:&gt;&gt; CLASSPATH=D:\DevSuiteHome\j2ee\OC4J_BI_Forms\applications\forms90app\forms90web\WEB-INF\lib\f90srv.jar;D:\DevSuiteHome\jlib\repository.jar;D:\DevSuiteHome\jlib\ldapjclnt9.jar;D:\DevSuiteHome\jlib\debugger.jar;D:\DevSuiteHome\jlib\ewt3.jar;D:\DevSuiteHome\jlib\share.jar;D:\DevSuiteHome\jlib\utj90.jar;D:\DevSuiteHome\jlib\zrclient.jar;D:\DevSuiteHome\reports\jlib\rwrun.jar)
Modify this line as your required jar files
:&gt;&gt; example
CLASSPATH=D:\DevSuiteHome\j2ee\OC4J_BI_Forms\applications\forms90app\forms90web\WEB-INF\lib\f90srv.jar;D:\DevSuiteHome\jlib\repository.jar;D:\DevSuiteHome\jlib\ldapjclnt9.jar;D:\DevSuiteHome\jlib\debugger.jar;D:\DevSuiteHome\jlib\ewt3.jar;D:\DevSuiteHome\jlib\share.jar;D:\DevSuiteHome\jlib\utj90.jar;D:\DevSuiteHome\jlib\zrclient.jar;D:\DevSuiteHome\reports\jlib\rwrun.jar;D:\DevSuiteHome\forms90\java\getclientinfo.jar;D:\DevSuiteHome\forms90\java\frmwebutil.jar;D:\DevSuiteHome\forms90\java\GetImageFileName.jar;D:\DevSuiteHome\forms90\java\images.jar;D:\DevSuiteHome\forms90\java\infobutton.jar;D:\DevSuiteHome\forms90\java\jacob.jar;D:\DevSuiteHome\forms90\java\rolloverbutton.jar


add following line in the end of file

#Webutil Config
WEBUTIL_CONFIG=D:\DevSuiteHome\forms90\server\webutil.cfg


Step-5
------

open forms90.conf file (path :&gt;&gt; D:\DevSuiteHome\forms90\server)

go to line where the following code already written
# Virtual path for runform.htm (used to run a form for testing purposes)
AliasMatch ^/forms90/html/(..*) "D:\DevSuiteHome/tools/web90/html/$1"

add following line after this
AliasMatch ^/forms90/webutil/(..*) "D:\DevSuiteHome/forms90/webutil/$1"

:&gt;&gt; example
# Virtual path for runform.htm (used to run a form for testing purposes)
AliasMatch ^/forms90/html/(..*) "D:\DevSuiteHome/tools/web90/html/$1"
AliasMatch ^/forms90/webutil/(..*) "D:\DevSuiteHome/forms90/webutil/$1"



Step-6a
------
1. Edit D:\DevSuiteHome\forms90\webutil\sign_webutil.bat file
as:
1. Go to Line
ECHO Generating a self signing certificate for key=%JAR_KEY%...
Next Line
edit Line in replace of previous address
D:\DevSuiteHome\jdk.........
2. Go to Line
ECHO Signing %1 using key=%JAR_KEY%...
Next Line
edit Line in replace of previous address
D:\DevSuiteHome\jdk.........

Step-6b
Sign additional jar file in the following way........

1.open cmd window
2.type d: and press enter
3.type cd DevSuiteHome\forms90\webutil and press enter
4.type sign_webutil D:\DevSuiteHome\forms90\java\rolloverbutton.jar and press enter

repeat line no. 4 as your required jar files



Step-7
------

Open formsweb.cfg file (path :&gt;&gt; D:\DevSuiteHome\forms90\server)
go to the end of file and then type the following line

[test_config]
form=D:\test\image_browser.fmx usesdi=yes
userid=user_id/pass@database_string
width=100%
height=100%
colorscheme=blue
pageTitle=Abc
imagebase=codebase
archive_jini=f90all_jinit.jar,rolloverbutton.jar,GetImageFileName.jar
webUtilArchive=frmwebutil.jar,jacob.jar
baseHTMLjinitiator=webutiljini.htm
splashscreen=abc_splash.gif
logo=abc_logo.gif
separateFrame=false

---End Configuration---


Now Call Your Configuration From Internet Explorer or Any Other Browser as below:

Ex:http://computer_name(or Ip_address):8889/forms90/f90servlet?config=test_config

Ex:http://abc_computer:8889/forms90/f90servlet?config=test_config

WebUtil Package For WebUtil Configuration

CREATE OR REPLACE PACKAGE WEBUTIL_DB AUTHID CURRENT_USER AS

/*********************************************************************************\
* WebUtil_DB - Database functions used by the WebUtil_File_Transfer
* Package. These functions allow reading and writing direct
* to the specified BLOB in the database.
* The functions should not be called externally from WebUtil
*********************************************************************************
* Version 1.0.0
*********************************************************************************
* Change History
* DRMILLS 11/JAN/2003 - Creation
*
\*********************************************************************************/

FUNCTION OpenBlob(blobTable in VARCHAR2,
blobColumn in VARCHAR2,
blobWhere in VARCHAR2,
openMode in VARCHAR2,
chunkSize in PLS_INTEGER default null) return BOOLEAN;

FUNCTION CloseBlob(checksum in PLS_INTEGER) return BOOLEAN;

PROCEDURE WriteData(data in VARCHAR2);

FUNCTION ReadData return VARCHAR;

FUNCTION GetLastError return PLS_INTEGER;

FUNCTION GetSourceLength return PLS_INTEGER;

FUNCTION GetSourceChunks return PLS_INTEGER;

END WEBUTIL_DB;
/



CREATE OR REPLACE PACKAGE BODY WEBUTIL_DB AS
m_binaryData BLOB;
m_blobTable VARCHAR2(60);
m_blobColumn VARCHAR2(60);
m_blobWhere VARCHAR2(1024);
m_mode CHAR(1);
m_lastError PLS_INTEGER := 0;
m_sourceLength PLS_INTEGER := 0;
m_bytesRead PLS_INTEGER := 0;
MAX_READ_BYTES PLS_INTEGER := 4096;

-- internal Program Units
PROCEDURE Reset;

PROCEDURE Reset is
BEGIN
m_blobTable := null;
m_blobColumn := null;
m_blobWhere := null;
m_mode := null;
m_lastError := 0;
m_sourceLength := 0;
m_bytesRead := 0;
END Reset;


FUNCTION OpenBlob(blobTable in VARCHAR2, blobColumn in VARCHAR2, blobWhere in VARCHAR2, openMode in VARCHAR2, chunkSize PLS_INTEGER default null) return BOOLEAN is
result BOOLEAN := false;
stmtFetch VARCHAR2(2000);
hit PLS_INTEGER;
BEGIN
-- New transaction clean up
reset;

m_blobTable := blobTable;
m_blobColumn := blobColumn;
m_blobWhere := blobWhere;
m_mode := upper(openMode);

if chunkSize is not null then
if chunkSize &gt; 16384 then
MAX_READ_BYTES := 16384;
else
MAX_READ_BYTES := chunkSize;
end if;
end if;

-- check the target row exists
stmtFetch := 'select count(*) from '||m_blobTable||' where '||m_blobWhere;
EXECUTE IMMEDIATE stmtFetch into hit;

if hit = 1 then
if m_mode = 'W' then
DBMS_LOB.CREATETEMPORARY(m_binaryData,false);
DBMS_LOB.OPEN(m_binaryData,DBMS_LOB.LOB_READWRITE);
m_sourceLength := 0;
result := true;
elsif m_mode = 'R' then
stmtFetch := 'select '||m_blobColumn||' from '||m_blobTable||' where '||m_blobWhere;
EXECUTE IMMEDIATE stmtFetch into m_binaryData;
if m_binaryData is not null then
m_sourceLength := dbms_lob.getlength(m_binaryData);
if m_sourceLength &gt; 0 then
result := true;
else
m_lastError := 110;
end if;
else
m_lastError := 111;
end if;
else
m_lastError := 112;
end if; -- mode
else
-- too many rows
m_lastError := 113;
end if; -- Hit
return result;
END OpenBlob;

FUNCTION CloseBlob(checksum in PLS_INTEGER) return BOOLEAN is
sourceBlob BLOB;
stmtFetch VARCHAR2(2000);
stmtInit VARCHAR2(2000);
result BOOLEAN := false;
BEGIN
if m_mode = 'W' then
m_sourceLength := DBMS_LOB.GETLENGTH(m_binaryData);
end if;

-- checksum
if checksum = m_sourceLength then
if m_mode = 'W' then
-- get the locator to the table blob
stmtFetch := 'select '||m_blobColumn||' from '||m_blobTable||' where '||m_blobWhere||' for update';
EXECUTE IMMEDIATE stmtFetch into sourceBlob;

-- Check the blob has been initialised
-- and if it's not empty clear it out
if sourceBlob is null then
stmtInit := 'update '||m_blobTable||' set '||m_blobColumn||'=EMPTY_BLOB() where '||m_blobWhere;
EXECUTE IMMEDIATE stmtInit;
EXECUTE IMMEDIATE stmtFetch into sourceBlob;
elsif dbms_lob.getlength(sourceBlob) &gt; 0 then
dbms_lob.TRIM(sourceBlob,0);
end if;
-- now replace the table data with the temp BLOB
DBMS_LOB.APPEND(sourceBlob,m_binaryData);
DBMS_LOB.CLOSE(m_binaryData);
result := true;
else
-- todo
null;
end if; --mode
else
m_lastError := 115;
end if; --checksum
return result;
END CloseBlob;

PROCEDURE WriteData(data in VARCHAR2) is
rawData raw(16384);
BEGIN
rawData := utl_encode.BASE64_DECODE(utl_raw.CAST_TO_RAW(data));
dbms_lob.WRITEAPPEND(m_binaryData, utl_raw.LENGTH(rawData), rawData);
END WriteData;


FUNCTION ReadData return VARCHAR is
rawData RAW(16384);
bytesToRead PLS_INTEGER;
BEGIN
bytesToRead := (m_sourceLength - m_bytesRead);
if bytesToRead &gt; MAX_READ_BYTES then
bytesToRead := MAX_READ_BYTES;
end if;
DBMS_LOB.READ(m_binaryData, bytesToRead, (m_bytesRead + 1), rawData);
m_bytesRead := m_bytesRead + bytesToRead;
return UTL_RAW.CAST_TO_VARCHAR2(UTL_ENCODE.BASE64_ENCODE(rawData));
END ReadData;

FUNCTION GetLastError return PLS_INTEGER is
BEGIN
return m_lastError;
END GetLastError;


FUNCTION GetSourceLength return PLS_INTEGER is
BEGIN
return m_sourceLength;
END GetSourceLength;

FUNCTION GetSourceChunks return PLS_INTEGER is
chunks PLS_INTEGER;
BEGIN
chunks := floor(m_sourceLength/MAX_READ_BYTES);
if mod(m_sourceLength,MAX_READ_BYTES) &gt; 0 then
chunks := chunks+1;
end if;
return chunks;
END GetSourceChunks;

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 &gt; 0 then
vPath := substr(vPath,1,vPath_Len);
else
vPath_Len := null;
end if;
return vPath;
end;

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;
/

Clear or Delete Htree Data from 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 &amp; 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;

Data Convertion from a FILE(jpeg,gif,pdf,doc,txt etc.) to BLOB in ORACLE

paid surveys

Compile below procedure:

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;
/

***Now execute below PLSQL block to show your desired output:

declare
  v_blob blob;
begin
  Dpr_fileToBlob(Fname   => 'File_Name.ext',
                 Fdir    => 'Database_Directory_Name',
                 OutBlob => v_blob);
  dbms_output.out_line(dbms_lob.getlength(v_blob));
end;
 
paid surveys