Adsense Ad

Wednesday, 28 March 2018

How to Print Oracle Report To A Network Shared Printer

In this post I will demonstrate how to send Oracle Report print job direct to a network shared printer.(WINDOWS ONLY)

Assuming you are running your application on Oracle Application Server 10g.

WHEN-BUTTON-PRESSED

DECLARE
pl_id ParamList;
lv_repid REPORT_OBJECT;
lv_report VARCHAR2(100);
BEGIN
pl_id := Get_Parameter_List('tmpdata');
IF NOT Id_Null(pl_id) THEN
Destroy_Parameter_List( pl_id );
END IF;
pl_id := Create_Parameter_List('tmpdata');
Add_Parameter(pl_id,'P_1',TEXT_PARAMETER,:STUDENTS.STDCODE);
Add_Parameter(pl_id, 'PARAMFORM', TEXT_PARAMETER, 'NO');
lv_repid:=FIND_REPORT_OBJECT('std_ledger');
SET_REPORT_OBJECT_PROPERTY(lv_repid, REPORT_FILENAME, 'c:\apps\reports\std_ledger1.rep');
SET_REPORT_OBJECT_PROPERTY(lv_repid, REPORT_EXECUTION_MODE, RUNTIME);
SET_REPORT_OBJECT_PROPERTY(lv_repid, REPORT_COMM_MODE , SYNCHRONOUS);
SET_REPORT_OBJECT_PROPERTY(lv_repid, REPORT_DESTYPE ,PRINTER);
SET_REPORT_OBJECT_PROPERTY(lv_repid,REPORT_DESNAME,'\\192.168.1.69\hpLaserJ');
SET_REPORT_OBJECT_PROPERTY(lv_repid, REPORT_DESFORMAT ,'hpl.prt');
SET_REPORT_OBJECT_PROPERTY(lv_repid, REPORT_SERVER , 'rep_localhost_oracleas');
lv_report := RUN_REPORT_OBJECT (lv_repid,pl_id);
END;


Tuesday, 27 March 2018

Oracle Forms: A Full Web Browser Java Bean


Here is a Java bean that allows to have an enhanced Web Browser.It is a full Web browser that can handle Javascript and display Flash animations.

The material comes from a sourceforge project:
http://sourceforge.net/project/showfiles.php?group_id=170904

It can accept both http url and local machine html file names.

It needs, at least, a 1.4 JRE so the Sun Java plug-in, so that it won't run with the JInitiator.


The Java code

     EnhancedHTMLBrowser.java



The implementation class of the Bean Item

     oracle.forms.fd.EnhancedHTMLBrowser


The methods you can call


  • Get the Forms Window
Set_Custom_Property( 'BL.BEAN', 1, 'INFOBEAN', '' ) ;

This must be used to retrieve the Forms window that handles the webBrowser, then synchronize its position when the windows is moved. This must be the first property set (in the When-New-Form-Instance trigger).

  • Set the URL/File
Set_Custom_Property( 'BL.BEAN', 1, 'SET_URL', 'url | file_name' ) ;


e.g. :

Set_Custom_Property('BL.BEAN', 1, 'SET_URL', 'http://www.developpez.com/' ) ;         


Set_Custom_Property('BL.BEAN', 1, 'SET_URL', 'd:/mypage.htm' ) ;
  • Set the border of the bean
Set_Custom_Property( 'BL.BEAN', 1, 'SET_BORDER', 'true | false' ) ;


When you want to use this bean to display a Flash image (*.swf), you would probably prefer not to have any border bounding the image.
In this case, set the border to false.

  • Basic navigation
Set_Custom_Property( 'BL.BEAN', 1, 'SET_NAVIGATION', 'back | forward | refresh' ) ;



The sample dialog     . 
     . Download the eHTMLBrowser.zip file
     . Download the sourceforge project zip file


     . Unzip the files
     . copy the jdic.jar and eHTMLBrowser.jar files in the <ORACLE_HOME>/forms/java directory
     . Edit your /forms/server/formsweb.cfg file to add these 2 jar files
     . Add the 2 .dll files and IeEmbed.exe (from the javaflashbridge-v1.zip file) to your Windows/system32 directory
     . Open the EHTMLBROWSER.fmb module (Oracle Forms 9.0.2)
     . Compile all and run the module
     The .jar files must be signed
     The eHTMLBrowser.jar and jdic.jar files provided with the .zip file are already signed


Click to download complete package


Reference: http://forms.pjc.bean.over-blog.com/article-5029633.html

Monday, 26 March 2018

Oracle Forms: A simple JavaBean HTML browser

Here is a (very) simple HTML browser.



This JavaBean component allows to browse some simple HTML pages inside the Oracle Forms frame.
It may be a good way to browse into local documents, like documentation html pages.

You can click on the hyperlinks to navigate through the content.



The Java code
Get the source code here
Get the source code here


Forms configuration
     . Copy the htmlbrowser.jar file in the /forms/java directory
        This .jar file must be signed
     . Edit the /forms/server/formsweb.cfg file to add the jar file to the archive_jini variable

         archive_jini=f90all_jinit.jar,……,htmlbrowser.jar



Implementation Class property

     oracle.forms.fd.HtmlFrame


The properties you can set
The url to display
Set_Custom_Property( 'BLOCK.BEAN_AREA', 1, 'SETURL', 'new_url' ) ;

The HTML content to display
Set_Custom_Property( 'BLOCK.BEAN_AREA', 1, 'SETCONTENT', 'html_content' ) ;

Where html_content must be valid HTML source like : '<html><body><b>Hello there</b></body></html>'


The sample dialog
     . Download Link1 the htmlbrowser.zip file Download Link2 the htmlbrowser.zip file
     . Unzip the file
     . Edit your /forms/server/formsweb.cfg file
     . Open the HTML_BROWSER.fmb module (Oracle Forms 9.0.2)
     . Compile all and run the module

Oracle Forms 10G: Signing JAR Files

Signing JAR Files

This article describes the method for creating a keystore and signing JAR files.
  • Create Keystore (keytool)
  • Sign JAR Files (jarsigner)

Create Keystore (keytool)

Before you can sign a jar file you need a keystore. If one doesn't already exist, you can create it using the keytool utility. The keytoolutility is normally found under the JDK bin directory, so you may find it in several locations on your server. For example, on Oracle Application Server and WebLogic environments you would find it in at least the following locations:
  • OAS: $ORACLE_HOME/jdk/bin/keytool
  • WebLogic: $MW_HOME/oracle_common/jdk/bin/keytool
Navigate to the users home directory.
$ cd ~
$ # Or
$ cd $HOME
Use the keytool utility to generate the keystore. The default name for the keystore is ".keystore", but this can be overridden with the "-keystore" parameter.
$ $ORACLE_HOME/jdk/bin/keytool -genkey -alias myapp -keyalg RSA -keystore .keystore_myapp

Enter keystore password:  mypassword
What is your first and last name?
  [Unknown]:  Joe Bloggs
What is the name of your organizational unit?
  [Unknown]:  My Department
What is the name of your organization?
  [Unknown]:  My Company
What is the name of your City or Locality?
  [Unknown]:  My City
What is the name of your State or Province?
  [Unknown]:  My State
What is the two-letter country code for this unit?
  [Unknown]:  UK
Is CN=Joe Bloggs, OU=My Department, O=My Company, L=My City, ST=My State, C=UK correct?
  [no]:  yes

Enter key password for <myapp>
        (RETURN if same as keystore password):

$
See the linked documentation for more information about the keytool command line syntax.

Sign JAR Files (jarsigner)

Once the keystore is created, you can use the jarsigner utility to sign the JAR files. The jarsigner utility is normally found under the JDK bin directory, so you may find it in several locations on your server. For example, on Oracle Application Server and WebLogic environments you would find it in at least the following locations:
  • OAS: $ORACLE_HOME/jdk/bin/jarsigner
  • WebLogic: $MW_HOME/oracle_common/jdk/bin/jarsigner
Sign the JARs using the information from the keystore.
$ORACLE_HOME/jdk/bin/jarsigner -keystore .keystore_myapp -storepass mypassword $ORACLE_HOME/forms/java/frmall.jar myapp

See the linked documentation for more information about the jarsigner command line syntax.

Monday, 12 March 2018

Oracle SQL / PLSQL: ABS Function

Oracle SQL / PLSQL: ABS Function

This Oracle tutorial explains how to use the Oracle/PLSQL ABS function with syntax and examples.

Description

The Oracle/PLSQL ABS function returns the absolute value of a number.

Syntax

The syntax for the ABS function in Oracle/PLSQL is:
ABS( number )

Parameters or Arguments

number
The number to convert to an absolute value.

Returns

The ABS function returns a numeric value.

Applies To

The ABS function can be used in the following versions of Oracle/PLSQL:
  • Oracle 12c, Oracle 11g, Oracle 10g, Oracle 9i, Oracle 8i

Example

Let's look at some Oracle ABS function examples and explore how to use the ABS function in Oracle/PLSQL.
For example:
ABS(-23)
Result: 23

ABS(-23.6)
Result: 23.6

ABS(-23.65)
Result: 23.65

ABS(23.65)
Result: 23.65

ABS(23.65 * -1)
Result: 23.65

Thursday, 15 February 2018

Create Custom split() function in Oracle

Some programming and scripting languages provide built-in functions that split a string around a given delimiter. Oracle SQL does not offer similar functionality out of the box, but this following function can help fill the gap.



create or replace function split(input_list varchar2, ret_this_one number, delimiter varchar2) 
return varchar2 is 
        v_list varchar2(32767) := delimiter || input_list; 
        start_position number; 
        end_position number; 
begin 
        start_position := instr(v_list, delimiter, 1, ret_this_one); 
        if start_position > 0 then 
                end_position := instr( v_list, delimiter, 1, ret_this_one + 1); 
                if end_position = 0 then 
                        end_position := length(v_list) + 1; 
                end if; 
return(substr(v_list, start_position + 1, end_position - start_position - 1)); 
        else 
        return NULL; 
        end if; 
end split; 

/ show errors;


In the previous listed example, we would run this function as follows.

select split('AAA,BBB',1,','); -- Returns AAA 
select split('AAA,BBB',2,','); -- Returns BBB


Please note that the first index is 1, not 0.

The following function will take in a list, let's say "AAA,BBB", split them up to "AAA" and "BBB", and allow the user to specify which one to return.

Functions to join and split strings in Oracle SQL

A common task when selecting data from a database is to take a set of values a query returns and format it as a comma delimited list. Another task that's almost as common is the need to do the reverse: Take a comma delimited list of values in a single string and use it as a table of values.

Many scripting languages, such as Perl and Python, provide functions that do this with their own language-specific list of values; so it's surprising that, as of yet, this functionality isn't a standard part of SQL functions. I've seen some pretty ugly looking code that involved complex declarations with MAX and DECODE, but that solution usually only returns a limited set of values. With some of the new Oracle9i and above features, it's possible to do this yourself.

I'd like to use a "join" functionality to specify a query that returns a single column and a delimiter, and then receive a simple string that contains a list of those values separated by my delimiter. The query part can be passed to the function as a REF CURSOR using the new SQL CURSOR function. The delimiter should default to a comma, since that is the most commonly used delimiter. So, the syntax should be:

SQL> select join(cursor(select ename from emp)) from dual;


SMITH,ALLEN,WARD,JONES,MARTIN,BLAKE,CLARK,SCOTT,KING,TURNER,ADAMS,
JAMES,FORD,MILLER

The following code will perform this function:

create or replace function join
(
p_cursor sys_refcursor,
p_del varchar2 := ','
) return varchar2
is
l_value varchar2(32767);
l_result varchar2(32767);
begin
loop
fetch p_cursor into l_value;
exit when p_cursor%notfound;
if l_result is not null then
l_result := l_result || p_del;
end if;
l_result := l_result || l_value;
end loop;
return l_result;
end join;
/
show errors;


The PL/SQL User's Guide says you always have to declare a package that defines a ref cursor; however, the database already defines this as SYS_REFCURSOR in the STANDARD package. The PL/SQL code should be fairly straightforward. There is a limit of 32,767 characters on the output string and the input column.

Since all datatypes can be automatically converted to character strings, you can use any datatype in the cursor—as long as it's one column. For example:

SQL> select join(cursor(select trunc(hiredate,'month') from emp),'|') from
dual;


01-DEC-80|01-FEB-81|01-FEB-81|01-APR-81|01-SEP-81|01-MAY-81|01-JUN-81|01-APR-87|01-NOV-81|01-SEP-81|01-MAY-87|01-DEC-81|
01-DEC-81|01-JAN-82

There's another extra benefit. Since the cursor is part of the SQL statement, you can easily join the query inside the join with the outer query. Here is a query that returns each table and a list of the columns that make up its primary key:

SQL> select table_name,join(cursor(select column_name from user_cons_columns
where constraint_name = user_constraints.constraint_name
order by position)) columns
from user_constraints where constraint_type = 'P';

View the output in Table A.

You can also use this "join" function to compare two sets of ordered data. For example, the following query will check that an index has been created on a foreign key (which helps prevent locking the table and aids master-detail queries):

column status format a7
column table_name format a30
column columns format a40 word_wrapped

select decode(indexes.table_name,null,'missing','ok') status,
constraints.table_name,
constraints.columns
from
(select table_name,
constraint_name,
join(cursor
(
select column_name
from user_cons_columns
where constraint_name = user_constraints.constraint_name
)) columns
from user_constraints
where constraint_type = 'R'
) constraints,
(select table_name, index_name,
join(cursor
(
select column_name
from user_ind_columns
where index_name = user_indexes.index_name
)) columns
from user_indexes) indexes
where constraints.table_name = indexes.table_name (+)
and constraints.columns = indexes.columns (+);


This query works by executing two subqueries: one that queries foreign keys and another that queries indexes. The join between these two queries is on the table name and the list of columns used in creating the foreign key and the index, taken as an ordered list of values.


We'd also like the reverse functionality: to have the ability to take a single comma-delimited value and treat it as if it were a column in a table. We can take advantage of the TABLE SQL function and PL/SQL function tables to do this quite easily, but first, we must define the result type to be a TABLE type of the largest possible string.

create or replace type split_tbl as table of varchar2(32767);
/
show errors;

create or replace function split
(
p_list varchar2,
p_del varchar2 := ','
) return split_tbl pipelined
is
l_idx pls_integer;
l_list varchar2(32767) := p_list;
AA
l_value varchar2(32767);
begin
loop
l_idx := instr(l_list,p_del);
if l_idx > 0 then
pipe row(substr(l_list,1,l_idx-1));
l_list := substr(l_list,l_idx+length(p_del));

else
pipe row(l_list);
exit;
end if;
end loop;
return;
end split;
/
show errors;

With this function, I can run a query like this:

SQL> select * from table(split('one,two,three'));

one
two
three


The PL/SQL procedure will parse its argument and return each part through a PIPELINE; the TABLE function allows it to be used in the FROM statement, so it appears to SQL as if it is a table with one column and three rows. (Remember that the column being returned is named COLUMN_VALUE if you want to use the value elsewhere.)

Here's an example query, which shows a dynamic IN condition in a query. The split function generates a table of values, which can be used on a row-by-row basis.

SQL> select ename from emp
where to_char(hiredate,'YY')
in (select column_value from table(split('81,82')));



View the output in Table B.

If you want, you can join a column and then split it, too:

SQL> select * from table(split(join(cursor(select ename from emp))));

And, you can use this method to merge sets of values:

create table t(a varchar2(200));
insert into t values('81,82');
insert into t values('84,85');

SQL> select * from table(split(join(cursor(select a from t))));

81
82
84
85


These are just simple example functions. You could extend join to enclose values in quotes and escape quotes inside the values. You could extend split to allow a REF CURSOR parameter instead of a single VARCHAR2, so it could split up sets of columns as well.