Wednesday, March 9, 2011

ORACLE FUNCTIONS


ORACLE FUNCTIONS
Functions are used to manipulate data items and return a result. Functions follow the format of:
Examples :-
Ø  AVG
·         Select AVG(s_price)”Average” from  data;
Ø  MIN
·         Select min(s_date)”Minimum Date” from data;
Ø  COUNT(expr)
·         Select count(s_order_no)”No of Orders”  from data;
Ø  COUNT(*)
·         Select count(*) “Total ” from data;
Ø  MAX
·         Select max(s_qty)”Maximum” from data;
Ø  SUM
·         Select sum(s_qty)”Total Qty.” from data;
Ø  ABS
·         Select ABS(-20)”Absolute” from dual;
Ø  POWER
·         Select power(3,2)”Raised” from dual;
Ø  ROUND
·         Select round(20.254,2)”Round” from dual;
Ø  SQRT
·         Select sqrt(49) “Square Root” from dual;
Ø  LOWER
·         Select lower(‘ABCD’)”LOWER” from dual;
Ø  INITCAP
·         Select inicap(‘PRADEEP SHARMA’)”Titel Case” from dual;
Ø  UPPER
·         Select uppar(‘rajeev gupta’) from dual;
Ø  SUBSTR
·         Select substr(‘123456789,1,3)”substruig” from dual;
Ø  LENGTH
·         Select length(‘apple’)”Length” from dual;
Ø  LTRIM
·         Select ltrim(‘xxxXxxWorld’,’x’)”Left trim example” from dual;
Ø  RTRIM
·         Select rtrim(‘wordxxXxx’,’x’)”reight trim example” from dual;
Ø  LPAD
·         Select lpad(‘ABC’,10,’*’)”LPAD” from dual;
Ø  RPAD
·         Select rpad(name,10,’x’)”Rpad example”  from data;
Ø  TO_NUMBER
·         Update data set amt=amt+to_number(sybstr(100,1,2);

The above oracle function are just a few selected from the many functions that are in built into oracle. 

Tuesday, March 8, 2011

convert d2k report in excel


How to convert d2k report in excel


first create a  RPT2XLS.pll  as under below :

first step :-

/start****************RPT2XLS(package space)@***********************/
PACKAGE RPT2XLS IS

BOLD constant binary_integer := 1;

ITALIC constant binary_integer := 2;

UNDERLINE constant binary_integer := 4;

PROCEDURE put_cell(ColNo binary_integer, CellValue in varchar2,

FontName in varchar2 DEFAULT null,

FontSize in binary_integer DEFAULT null,

FontStyle in binary_integer DEFAULT null,

FontColor in binary_integer DEFAULT null,

BgrColor in binary_integer DEFAULT null,

Format in varchar2 DEFAULT null  );

PROCEDURE new_line;

PROCEDURE run;

PROCEDURE release_memory;

END;

/end****************RPT2XLS(package space)@***********************/
/start****************RPT2XLS(package body)@***********************/
PACKAGE BODY RPT2XLS IS

TYPE ExcelCell IS RECORD(RowNo binary_integer,

ColNo binary_integer,

Val varchar2(2000),

FontName varchar2(20),

FontSize binary_integer,

FontStyle binary_integer,

FontColor binary_integer,

BgrColor binary_integer,

Format varchar2(60) DEFAULT null );

TYPE ExcelCells IS TABLE OF ExcelCell;

Cell ExcelCells := ExcelCells();

CurrentRow binary_integer := 1;

PROCEDURE new_line IS

BEGIN

CurrentRow := CurrentRow + 1;

END;

PROCEDURE put_cell(ColNo binary_integer, CellValue in varchar2,

FontName in varchar2 DEFAULT null,

FontSize in binary_integer DEFAULT null,

FontStyle in binary_integer DEFAULT null,

FontColor in binary_integer DEFAULT null,

BgrColor in binary_integer DEFAULT null,

Format in varchar2 DEFAULT null) IS

EGIN

Cell.Extend;

Cell(Cell.Last).RowNo := CurrentRow;

Cell(Cell.Last).ColNo := ColNo;

Cell(Cell.Last).Val := CellValue;

Cell(Cell.Last).FontName := FontName;

Cell(Cell.Last).FontSize := FontSize;

Cell(Cell.Last).FontStyle := FontStyle;

Cell(Cell.Last).FontColor := FontColor;

Cell(Cell.Last).BgrColor := BgrColor;

Cell(Cell.Last).Format := Format;

END;

PROCEDURE run IS

Application OLE2.OBJ_TYPE;

Workbooks OLE2.OBJ_TYPE;

Workbook OLE2.OBJ_TYPE;

Worksheets OLE2.OBJ_TYPE;

Worksheet OLE2.OBJ_TYPE;

WorkCell OLE2.OBJ_TYPE;

WorkColumn OLE2.OBJ_TYPE;

WorkFont OLE2.OBJ_TYPE;

WorkInterior OLE2.OBJ_TYPE;

ArgList OLE2.LIST_TYPE;

BEGIN

Application := OLE2.create_obj('Excel.Application');

OLE2.set_property(Application, 'Visible', 1);

Workbooks := OLE2.get_obj_property(Application, 'Workbooks');

Workbook := OLE2.invoke_obj(WorkBooks, 'Add');

Worksheets := OLE2.get_obj_property(Workbook, 'Worksheets');

Worksheet := OLE2.get_obj_property(Application, 'ActiveSheet');


for i in Cell.First .. Cell.Last

loop

if Cell(i).Val is not null then

ArgList := OLE2.create_arglist;

OLE2.add_arg(ArgList, Cell(i).RowNo);

ole2.add_arg(ArgList, Cell(i).ColNo);

WorkCell := OLE2.get_obj_property(Worksheet, 'Cells', ArgList);

ole2.destroy_arglist(ArgList);

ole2.set_property(WorkCell, 'Value', Cell(i).Val);

ole2.set_property(WorkCell, 'NumberFormat', Cell(i).Format);

WorkFont := OLE2.get_obj_property(WorkCell, 'Font');

WorkInterior := ole2.Get_Obj_Property(WorkCell, 'Interior');

if Cell(i).FontName is not null then

OLE2.set_property(WorkFont, 'Name', Cell(i).FontName);

end if;

if Cell(i).FontSize is not null then

OLE2.set_property(WorkFont, 'Size', Cell(i).FontSize);

end if;

if mod(Cell(i).FontStyle, 2) = 1  then

OLE2.set_property(WorkFont, 'Bold', 1);

end if;

if mod(Cell(i).FontStyle, 4) > 2  then

OLE2.set_property(WorkFont, 'Italic', 1);

end if;

if mod(Cell(i).FontStyle, 8) > 4  then

OLE2.set_property(WorkFont, 'Underline', 2);

end if;

 if Cell(i).FontColor is not null then

OLE2.set_property(WorkFont, 'ColorIndex', Cell(i).FontColor);

end if;

if Cell(i).BgrColor is not null then

OLE2.set_property(WorkInterior, 'ColorIndex', Cell(i).BgrColor);

end if;

OLE2.release_obj(WorkInterior);

OLE2.release_obj(WorkFont);

OLE2.release_obj(WorkCell);

end if;

end loop;

ArgList := ole2.create_arglist;

ole2.add_arg(ArgList, 'A:Z'); 

WorkColumn := ole2.Get_Obj_Property(WorkSheet, 'Columns', ArgList); 

ole2.destroy_arglist(ArgList);

ole2.invoke(WorkColumn, 'AutoFit');

OLE2.release_obj(WorkColumn);

OLE2.release_obj(Worksheet);

OLE2.release_obj(Worksheets);

OLE2.release_obj(Workbook);

OLE2.release_obj(Workbooks);

OLE2.release_obj(Application);

END;

PROCEDURE release_memory IS

BEGIN

Cell := ExcelCells();

SYS.DBMS_SESSION.free_unused_user_memory;

END;

END;

/end****************RPT2XLS(package body)@***********************/

Second Step:

Use RPT2XLZ.PLL in report builder 

attach lib fiel in reort builder 




attach lib file in reort builder 

After report trigger 
function AfterReport return boolean is
begin
rpt2xls.release_memory;
return (TRUE);
end;
format trigger 
function F_21FormatTrigger return boolean is
begin
--  RPT2XLS.PUT_CELL(1,:countasper);--,null,null,03,null,null,null);
--RPT2XLS.PUT_CELL(2,:p_date);
RPT2XLS.PUT_CELL(3,'Grand Total',null,null,03,null,null,null);
RPT2XLS.PUT_CELL(4,:sumoftotalweight1);
RPT2XLS.PUT_CELL(5,:sumofoutcenwtsoc);
RPT2XLS.PUT_CELL(6,:sumtotalwt);
--RPT2XLS.PUT_CELL(7,:govt_rule);
RPT2XLS.PUT_CELL(8,:sum_soc_comm_tot);
RPT2XLS.PUT_CELL(9,:sum_cf_4);
RPT2XLS.PUT_CELL(10,:sum_cf_4);
RPT2XLS.PUT_CELL(11,:sum_cf_4);
RPT2XLS.PUT_CELL(12,:sum_cf_4);
rpt2xls.new_line;
return (TRUE);
end;

when button pressed
procedure U_1ButtonAction is
begin
rpt2xls.run;
end;
then compile report and run properly 


Welcome your suggestion




Monday, March 7, 2011

What are the various report triggers

 What are the various report triggers ? What is their order of firing ?
A There are eight report triggers. Of these there are five global triggers called the Report Triggers.
They are fired in the following order :
* Before Parameter Form
* After Parameter Form
* Before Report
* Between Pages
* After Report
Apart from the above Five Report Triggers, there are three other types of triggers :
* Validation Triggers
* Format Triggers
* Action Triggers
Before Form : Fires before the Runtime Parameter Form is displayed. From this trigger, you can access and change the values of parameters, PL/SQL global variables, and report-level columns. (Note : If the Runtime Parameter Form is suppressed, this trigger still fires. Consequently, you can use this trigger for validation of command line parameters).
After Form : Fires after the Runtime Parameter Form is displayed. From this trigger, you can access parameters and check their values. This trigger can also be used to change parameter values or, if an error occurs, return to the Runtime Parameter Form. Columns from the data model are not accessible from this trigger. (Note : If the Runtime Parameter Form is suppressed, the After Form trigger still fires. Consequently, you can use this trigger for validation of command line parameters or other data).
Before Report : Fires before the report is executed but after queries are parsed and data is fetched.Between Pages : Fires before each page of the report is formatted, except the very first page. This trigger can be used for customized page formatting. (Note : In the Previewer, this trigger only fires the first time that you go to a page. If you subsequently return to the page, the trigger does not fire again.)
After Report : Fires after you exit the Previewer, or after report output is sent to a specified destination, such as a file, a printer, or an Oracle*Mail userid. This trigger can be used to clean up any initial processing that was done, such as deleting tables. Note, however, that this trigger always fires, whether or not your report completed successfully.
Validation Triggers : Validation Triggers are PL/SQL functions that are executed when parameter values are specified on the command line and when you accept the Runtime Parameter Form. (Notice that this means each Validation Trigger may fire twice when you execute the report). Validation Triggers are also used to validate the Initial Value of the parameter in the Parameter property sheet.
Format Triggers : Format Triggers are PL/SQL functions executed before the object is formatted. The trigger can be used to dynamically change the formatting attributes of the object.
Action Triggers : Action Triggers are PL/SQL procedures executed when a button is selected in the Previewer. The trigger can be used to dynamically call another report (drill down) or execute any other PL/SQL.