40735: when-button-pressed trigger raised unhandled exception ORA-305500 - oracle

I want to generate report in Excel File using oracle forms 10g and implement trigger when-button-pressed. When button press then getting following error:
40735: when-button-pressed trigger raised unhandled exception ORA-305500
Code:
declare
application ole2.obj_type;
workbooks ole2.obj_type;
workbook ole2.obj_type;
worksheets ole2.obj_type;
worksheet ole2.obj_type;
cell ole2.obj_type;
arglist ole2.list_type;
row_num number;
col_num number;
fontObj ole2.obj_type;
cursor rec is SELECT so.descr saleorgdescr,ih.invdate invdatemaster, ih.docNUM docnum,
TO_CHAR(ih.invdate,'mon-yyyy') invmonth
FROM ARMINVHEAD ih, SDMSALEORG so
WHERE
ih.status='69'
AND TO_DATE(ih.INVDATE,'DD-MM-RRRR')
BETWEEN
TO_DATE('01-01-2008','DD-MM-RRRR')
AND
TO_DATE('01-01-2009','DD-MM-RRRR')
order by IH.INVDATE, ih.docnum;
procedure SetCellValue(rowid number,colid number,cellValue varchar) is
begin
arglist := ole2.create_arglist;
ole2.add_arg(arglist,rowid);
ole2.add_arg(arglist,colid);
cell:= ole2.get_obj_property(worksheet,'Cells',arglist);
fontObj := ole2.get_obj_property(cell,'Font');
ole2.destroy_arglist(arglist);
ole2.set_property(cell,'value',cellValue);
ole2.set_property(fontObj,'Size',16);
ole2.set_property(fontObj,'BOLD',1);
ole2.set_property(fontObj,'ColorIndex',7);
ole2.release_obj(cell);
end SetCellValue;
procedure app_init is
begin
application := ole2.create_obj('Excel.Application');
ole2.set_property(application,'Visible',true);
workbooks := ole2.get_obj_property(application,'workbooks');
workbook := ole2.Get_Obj_Property(workbooks,'add');
worksheets := ole2.get_obj_property(application,'worksheets');
worksheet := ole2.Get_Obj_Property(worksheets,'add');
ole2.set_property(worksheet,'Name','Emp Sheet');
end app_init;
procedure save_excel(path varchar,filename varchar) is
begin
OLE2.Release_Obj(worksheet);
OLE2.Release_Obj(worksheets);
-- Save the Excel file created
If path is not null then
Arglist := OLE2.Create_Arglist;
OLE2.Add_Arg(Arglist,path||'\'||file_name||'.xls');
OLE2.Invoke(workbook, 'SaveAs', Arglist);
OLE2.Destroy_Arglist(Arglist);
end if;
end save_excel;
begin
app_init;
row_num:=1;
col_num:=1;
SetCellValue(row_num,col_num,'saleorgdescr');
col_num:=col_num + 1;
SetCellValue(row_num,col_num,'invdatemaster');
col_num:=col_num + 1;
SetCellValue(row_num,col_num,'docnum');
col_num:=col_num + 1;
SetCellValue(row_num,col_num,'invmonth');
for i in rec loop
row_num:=row_num + 1;
col_num:=1;
SetCellValue(row_num,col_num,i.saleorgdescr);
col_num:=2;
SetCellValue(row_num,col_num,i.invdatemaster);
col_num:=3;
SetCellValue(row_num,col_num,i.docnum);
col_num:=4;
SetCellValue(row_num,col_num,i.invmonth);
end loop;
save_excel('C:\excel_export','emp_data');
OLE2.Release_Obj(workbook);
OLE2.Release_Obj(workbooks);
OLE2.Release_Obj(application);
end;
How to solve this problem in oracle forms 10g?
I am using oracle forms 10g with Oracle Apps ERP Module

ORA-305500 is a generic OLE2 error, indicating some problem between Forms and a non-Oracle resource, in this case Excel.
The following error raise at line application := ole2.create_obj('Excel.Application');
The basic problem is you are using Forms 10g, which uses an n-tier architecture. This is a massive change from client-server of Forms 6i or earlier. It means Forms OLE runs applications like Excel locally to the Forms application i.e. on the Forms app server not your desktop. So OLE won't work, unless your Forms app server runs on Windows OS and has Excel installed, and even then it will generate the file on the server.
Forms 10g comes with the Webutils library to support client-server style functionally in a multi-tier system. You need to use CLIENT_OLE2() functions to wrangle Excel in Forms 10g and WebUtil_File.File_Save_Dialog() to save the file to a local directory.
There is a good example on the OTN Forum here (link).
Webutil Error: Oracle.forms.webutil.ole.OleFunctions bean not found
Sounds like you haven't configured Forms to use Webutil properly (or at all). There's some stuff in the Forms Help document or you can follow this article (link).

Related

Limiting file size before submit through Dynamic Acrton in Oracle Apex

I want to create a Dynamic Action to check file size of File Browser field. I can not put validation I have to implement this through Dynamic Action. Please help here.
I guess you want to check the size of a file before a user upload it inside an apex application. That does not look to me like a dynamic action. Why you cannot use validations ?
Anyway, I would have a look at this interesting plugin : apex file size plugin
If you are interested, I know how to do it by using PL/SQL against apex_application_temp_files. In my case the user uploads the file using a file browser, then press upload, which triggers a PL/SQL process. The PLSQL program returns an error if the size is greater than 10M. Let me know if this suits you.
Correction: Actually the plugin I mentioned before can be used in a dynamic action.
Continuation
As I said before, I would use a piece of PL/SQL code over the apex_application_temp_files table. That table is maintained automatically by Apex. In my application I have the following code associated to the button which Upload the files. Once the user selects the file he/she wants to upload, the process triggers the procedure to check several aspects ( in my case I check that is a csv file and also the size )
procedure ValidateFiles (p_file_name in varchar2, p_file_type in varchar2) is
v_blob blob;
blob_length integer;
v_mime_type varchar2(2000);
vlimitsize pls_integer := XXXXXXX -- your limit here
--
begin
SELECT BLOB_CONTENT,
DBMS_LOB.GETLENGTH(blob_content),
mime_type,
INTO v_blob,blob_length,v_mime_type
FROM apex_application_temp_files
WHERE name = p_file_name;
if upper(v_mime_type) <> 'TEXT/COMMA-SEPARATED-VALUES' then
raise_application_error(-20000, 'Wrong extension file, expected:
text/comma-separated-values.');
end if;
-- debug apex messages
apex_debug.message('blob length: %s', blob_length);
--
if blob_length > vlimitsize
then
raise_application_error(-20000, 'File is greater than the limit allowed');
end if;
end;
end ValidateFiles;

How to select only folder not files using FBean oracle forms

I have sample oracle form AWTFileDialog in which open dialog box and select files but I want user select only folder and get all files inside folder.
Code:
:BL.FILE := FBean.Invoke_Char('CTRL.BEAN', 1, 'openFile' ,'Open a file...,C:\');
I am using oracle forms 11g
How to achieve this target
Thanks
One option would be using webutil_file package of webutil.pll which should be attached, and the object library webutil.olb should be imported by subclassing to the forms before proceeding with the program. After all, consider to write the following code :
Declare
v_dir varchar2(500);
Begin
Client_Tool_Env.Getvar('WINDIR',v_dir);
:BL.FILE := webutil_file.file_open_dialog(v_dir,'myblock','*.*','Open a file...');
End;

How to open PDF File From oracle forms 11g?

I am using Oracle Database 11gR2 with Oracle Forms 11gR2. I have PDF File Saved on Server Machine. I created button with Name "HELP" Manual PDF File. Now i want when user click on button on their local machine then PDF File open from server machine.
I found this code:
host('rundll32 url.dll,FileProtocolHandler c:\file_name.pdf');
Is this code run correctly? Oracle Forms 11g
You can create such a Procedure within your form :
Procedure Pr_Print( i_document varchar2 ) Is
pl_id paramlist;
pl_list paramlist;
my_rep_server varchar2(500);
Begin
pl_list := Get_Parameter_List('tmpdata');
if not Id_Null(pl_list) then
Destroy_Parameter_List(pl_list);
end if;
pl_list := Create_Parameter_List('tmpdata');
set_report_object_property('RP2RRO', report_filename, i_document );
set_report_object_property('RP2RRO', report_server, my_rep_server);
add_parameter(pl_id, 'column1', text_parameter, :col1 );
add_parameter(pl_id, 'column2', text_parameter, :col2 );
rp2rro.rp2rro_run_product(reports, i_document, synchronous, runtime,
filesystem, pl_id, null);
End;
where rp2rro.rp2rro_run_product is a method coming from rp2rro.pll ( a binary library module supplied by Oracle ),
assuming you have col1 and col2 text fields in it.
And call it from a button's WHEN-BUTTON-PRESSED trigger with the code :
Pr_Print('myDocument');
P.S. the library rp2rro.pll should be installed and configured within the application server, too. Since Reports 11g runs on app. server as a web-based application.
I think you can use WEB.SHOW_DOCUMENT(url,’_blank’); in your WHEN-BUTTON-PRESSED trigger

Oracle 11g - sys_refcursor

I am working on a system where Oracle 11g is the back end database.
I have very limited permissions on the database and as such all I can do is call procedures that reside in packages.
Gerally, these procedure return their result set via an OUT parameter of type sys_refcursor.
I can call them fine in C# and get data from the cursor via the C# OracleDataset type.
Here is my question.
I want to be able to run these procedures and see the results via SQL Developer.
I can execute the procedure fine, but seeing the contents of the sys_refcursor OUT parameter is boggling me.
I've done some gooling and people ar saying about creating type and other solutions I simply do not have the permissions to persue.
So, how can I possibly see the result set contained in a sys_refcursor?
So say I have a procedure with this signature....
procedure an_oracle_Proc(p_ref IN varchar2,
p_result_set OUT sys_refcursor);
I call it like this....
DECLARE
l_ref VARCHAR2(10);
l_result_set sys_refcursor;
BEGIN
oracle_pkg.an_oracle_Proc(p_ref => l_ref,
p_result_set => l_result_set);
--How to select from l_result_set with limited permissions
END
How can I look at the contents of l_result_Set?
This is repeating the answer I linked to before really but specifically for your code:
VARIABLE result_set refcursor;
DECLARE
l_ref VARCHAR2(10);
BEGIN
l_ref := 'whatever';
oracle_pkg.an_oracle_Proc(p_ref => l_ref,
p_result_set => :result_set);
END;
/
PRINT result_set
... and run all of that as a script from an SQL Worksheet. The contents of the ref cursor will be shown in the script output window.
Thought I'd have another look and found this - amazing what stepping away from the computer can do. ;)
I just have to select the appropriate variable on the left pane.
http://www.thatjeffsmith.com/archive/2011/12/sql-developer-tip-viewing-refcursor-output/
Still - it would be nice to write my own SQL to do this rather than using the execute window.
Sys_refcursor form an anonymous block is bit tricky. Use the sql-developer, explore the package or procedure , right click and execute the procedure/package.
Sql-developer will open an input/output UI where you can key in values. And you can see the output on the same UI as well. Let me know if you need more details. I was actually debugging the same a couple of weeks back successfully.

Calling Oracle package procedures which return ref cursors in straight PL/SQL

I've got an Oracle 10g database which is accessed from an ASP.NET application. Although I've used SQL Server heavily in many different aspects and Oracle for querying and reporting, this is my first time using Oracle as the OLTP database for an application.
The database-level procedures in the packages are typically of the form:
-- TYPE refcur IS REF CURSOR;
PROCEDURE get_some_stuff(o_cursor OUT refcur, p_param1 IN INTEGER, p_param2 IN INTEGER) IS
BEGIN
OPEN o_cursor FOR
SELECT whatever
FROM whatever
END
I assume these are done this way for the benefit of the ADO.NET layer able to use the cursor from the output param and it is my understanding that this is the acceptable best practice for calling Oracle procs from .NET.
In SQL Server, for example, we don't have explicit ref cursors, if a proc returns a result set (or several result sets), that's accessible as an output result set in both ADO.NET and SSMS, and you can simply test the SPs by doing EXEC spname param1, param2.
The problem I'm having is that I don't know how to call these directly in SQL in Toad, for example, to be able to test changes at the PL/SQL level first before going to the app. I'm very used to being able to exercise and even re-mix stored procs and functions in SQL Server to be able to refactor the database interface layer without affecting the external interface to application-level code.
look at the link that OMG Ponies posted, but what you can do is
var x refcursor;
declare
PROCEDURE GET_SOME_STUFF(O_CURSOR OUT SYS_REFCURSOR, P_PARAM1 IN NUMBER, P_PARAM2 IN NUMBER) IS
BEGIN
OPEN O_CURSOR FOR
SELECT LEVEL, p_param1 ,P_PARAM2 FROM DUAL CONNECT BY LEVEL < 3;
END ;
BEGIN
GET_SOME_STUFF(:x , 5, 10);
END;
/
PRINT X;
you pretty much just wrap it in a anonymous block ad it will run. I use SQL Developer (highly recommmend, free with plenty of support) or SQL plus so I cannot help with TOAD, but I would expect it to be the same. In SQL Developer (and in SQL Navigator if memory serves correct) you can simply right click the package/method you wish and it will create the script for you.
in toad and navigator I believe you may be able to get the ref cursor in a pretty grid while in developer you get it in text.
SQL Developer you can unit test as well
Try this:
DECLARE
aCursor SYS_REFCURSOR;
someVariable SOME_TYPE;
FUNCTION SOME_FUNC_RETURNING_A_CURSOR RETURN SYS_REFCURSOR IS
csrLocal SYS_REFCURSOR;
BEGIN
OPEN csrLocal FOR SELECT whatever FROM wherever;
RETURN csrLocal;
END SOME_FUNC_RETURNING_A_CURSOR;
BEGIN
aCursor := SOME_FUNC_RETURNING_A_CURSOR;
WHILE TRUE LOOP
FETCH aCursor INTO someVariable;
EXIT WHEN aCursor%NOTFOUND;
...do whatever with variables...
END LOOP;
COMMIT;
END;
Share and enjoy.
I found an easier way to this ...try it (This will also generate script for you)
In the Procedure Editor, load your procedure. Click on the lightning
bolt to execute and you will see the Set Parameters window, which is
also available via the button on the Proc Editor toolbar that has an
image similar to (...) on it, next to the lightning bolt. Click on the
output options button and you'll see your options. If this is a weak ref
cursor then you must use the in-memory grid option. Results go to the
cursor results tab at the bottom of the PE after you execute.
http://toad.10940.n7.nabble.com/display-ref-cursor-in-toad-td1427.html

Resources