Archive for May, 2010

Oracle Forms Dropdown List Item values populated from database table

Thursday, May 27th, 2010

Popup LOV boxes that retrieve their list from a database table are relatively easy to set up in oracle forms, the equivalent for a dropdown list item takes a bit more work.

1) First, create a new item in the canvas with item type as ‘List Item’ – or, in my case I changed the item type of an existing ‘text item’ called CONTROL.CAS_UPLOAD to be a ‘list item’.

2) Second, create a procedure like the below. This is a procedure within the form, listed under program units, not a database stored procedure.

The second column selected here is the one that is actually passed into the form control, even although slightly confusingly the box will display the first column value after selection is made. Only the first column is shown in the drop down.

CONTROL.CAS_UPLOAD here is the name of my list item (cas_upload), qualified by block name (control).

PROCEDURE CREATE_Filenames_RG  IS
-- Andrew Fraser v2.2 27th May 2010
-- Populate dynamic lookup

    it_id1   Item := Find_Item('CONTROL.CAS_UPLOAD');  

    group1_id    RecordGroup;

    GRP_status       NUMBER; 

    V_Space varchar2(10) := ''''||'0'||'''';

BEGIN

  group1_id := Find_Group('FILENAMES_RG');  

  IF NOT Id_Null(group1_id) THEN
  	delete_group(group1_id);
  END IF;
  group1_id := Create_Group_From_Query('FILENAMES_RG',
        'SELECT TO_CHAR(f.date_created, ''DD-Mon-YYYY HH24:MI'')||'||''''||' -- '||''''||'||f.file_name , f.file_name '
     ||' FROM filename_table f'
     ||' WHERE f.flag_processed = ''N'''
     ||' ORDER BY f.date_created, f.file_name') ; 

    Grp_status := Populate_Group('FILENAMES_RG');
  	IF Grp_status = 0 THEN
			If Not Id_Null(it_id1) THEN
		  	If Get_Item_Property(it_id1,Item_Type) = 'LIST' Then
	  	 	  Clear_List(it_id1);
	   		  Populate_List(it_id1,'FILENAMES_RG');
  		  END IF;
			END IF;
			END IF;

End;

3) Create/edit triggers to call this:

On form startup:

When-New-Form-Instance on the form as a whole:

-- Andrew Fraser v2.2 27-May-2010
CREATE_Filenames_RG;

And/or on mouse click if you want the database table requeried every single time the user clicks on the dropdown:

When-Mouse-Click on the new item itself:

-- Andrew Fraser v2.2 27-May-2010
Clear_List('CAS_UPLOAD');
Clear_Item;
CREATE_Filenames_RG;

4) Note that hard-coded lists get created with a record group and an associated LOV. Counter-intuitively, these are not used at all in the above method for database lookups.

Service seeddata.regress.rdbms.dev.us.oracle.com is Down

Friday, May 21st, 2010

This alert in Oracle Enterprise Manager Grid Control:

Service seeddata.regress.rdbms.dev.us.oracle.com is Down

Was brute-force fixed for me by running this on the target database:

SQL> exec dbms_service.delete_service('seeddata.regress.rdbms.dev.us.oracle.com')

Metric Collection Error oracle.sysman.emSDK.emd.comm.CommException: java.io.IOException: Cannot establish proxy connection: 503 Service Unavailable java.net.NoRouteToHostException: No route to host

Friday, May 21st, 2010

In Oracle Enterprise Manager Grid Control, the Agents, Hosts, Listeners were all displaying correctly with status of ‘up’.

But the databases reported status of “Metric Collection Error”.

When I tried to configure a database, the configure database page displayed either one of these errors at top of page:

oracle.sysman.emSDK.emd.comm.CommException: java.io.IOException: Cannot establish proxy connection: 503 Service Unavailable

oracle.sysman.emSDK.emd.comm.CommException: java.net.NoRouteToHostException: No route to host

Problem was agent server firewall settings blocking ports.

Fix for me was:

1) on agent server as oracle

cd /software/oracle/product/agent10g/bin
./emctl status agent

Look for “Agent URL” in the output of that command, in my case that was

https://myagentserver.mydomain:3872/emd/main

2) On Grid Control server as oracle, paste that line into a wget command at the command prompt:

wget --no-check-certificate https://myagentserver.mydomain:3872/emd/main

That failed with: “failed: No route to host”, fix was as below:

3) On agent server again – as root

Make backup copy before changing settings:

cd /etc/sysconfig
cp -p iptables iptables.210510
vi /etc/sysconfig/iptables

Add a new line for port 3872 by copying one of the existing lines, e.g.:

-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 3872 -j ACCEPT

Restart with:

/etc/rc3.d/S08iptables restart

This worked for me with Oracle Enterprise Manager Grid Control and Agent both version 10.2.0.5 and both on 32 bit linux.

Purge and regather all optimizer stats

Thursday, May 13th, 2010

Purge and regather all optimizer stats with:

exec dbms_stats.delete_database_stats
exec dbms_stats.delete_system_stats
exec dbms_scheduler.run_job('GATHER_STATS_JOB')

That works provided statistics level has not been changed to none

show parameter statistics_level

You can gather more detailed system stats with:

exec dbms_stats.gather_system_stats('START')
exec dbms_stats.gather_system_stats('STOP')

You can see the system stats with:

set pages 9999 lines 112
col pval2 form a20
select * from sys.aux_stats$;

You can check automatic stats gathering job is scheduled with:

select state, last_start_date from dba_scheduler_jobs where job_name = 'GATHER_STATS_JOB';

This has changed for 11g.
To check if it is scheduled in 11g:

select status, max_duration_last_7_days from dba_autotask_client where client_name = 'auto optimizer stats collection' ;

And to run it in 11g:

exec dbms_stats.gather_database_stats_job_proc

Comments in spfile alter system

Thursday, May 13th, 2010

Comments are used much less often in spfile than they were in old init.ora’s. Syntax for them is like:

SQL> alter system set pga_aggregate_target=1g comment='Andrew Fraser 13-May-2010 was 390m'  scope=spfile sid='*' ;

PLS-00999: implementation restriction (may be temporary) RESULT_CACHE is disallowed on subprograms with OUT or IN OUT parameters

Wednesday, May 5th, 2010

Result cache functions are a good new feature in Oracle 11g, but they only work with normal functions. A function that returns multiple outputs using OUT parameters cannot be made a result cache function, at least not in 11gR1.

Attempting to do so fails with this error: “PLS-00999: implementation restriction (may be temporary) RESULT_CACHE is disallowed on subprograms with OUT or IN OUT parameters“.

It would be possible to work around this limitation by bundling up the output into a single large delimiter separated string, but, for me, performance issues would have to be significant before resorting to that. Good sample code for doing it that way is here.

More details at http://blog.mclaughlinsoftware.com/tag/result_cache/.

Move objects including lobs, xml to new tablespace with dynamic SQL

Monday, May 3rd, 2010

Here objects are moved from tablespace users to tablespace users1:

set pages 9999 lines 132
spool m2.sql
select 'alter table '||owner||'.'||table_name||' move lob('||column_name||') store as ( tablespace users1);'
from dba_lobs where tablespace_name = 'USERS' order by 1
/
select 'alter table '||owner||'.'||segment_name||' move tablespace users1;'
from dba_segments where tablespace_name = 'USERS' and segment_type = 'TABLE' order by 1
/
select 'alter index '||owner||'.'||index_name||' rebuild tablespace users1;'
from dba_indexes where tablespace_name = 'USERS' order by 1
/
spool off
ed m2