Programming

Create a custom Oracle aggregate function that accepts multiple parameters through parameter encapsulation!

0

Why would you want a feature like this?

Scenarios:
- You want to group by but treat a specific value to overrule no matter what else is specified it would look like:

select id, strpref(string_prefered_pars_type(status, status, ‘active’)) from tablename group by id;
(prefer the ‘active’ value above all else)

- The value has a dependency on another column which looks like:

select id, strpref(string_prefered_pars_type(return_column, pref_dependency_column, ‘active’)) from tablename group by id;
(prefer the value from a record which has its pref_dependency_column set to ‘active’)

Naturally with some code changes it enables all kind of fun aggregation features!

Everything below the line is Oracle PL/SQL example code which demonstrates how a custom aggregate function can be created which accepts multiple parameters by encapsulating the parameters in a custom type.

/*
quote:
There is no support for writing custom aggregate functions that accept multiple parameters.

source:
Build Custom Aggregate Functions
By Jonathan Gennick

http://www.oracle.com/technology/oramag/oracle/06-jul/o46sql.html

This example uses a custom type to use a custom aggregate function that accepts multiple parameters through parameter encapsulation!

more references:

Oracle® Database Data Cartridge Developer's Guide, 10g Release 2 (10.2)
11 User-Defined Aggregate Functions

http://download.oracle.com/docs/cd/B10501_01/appdev.920/a96595/dci11agg.htm

*/

create or replace type STRING_PREFERED_PARS_TYPE as object
(
-- Author  : O. Lissenberg
-- Created : 4-11-2009
-- Purpose : Passes parameters to the STRING_PREFERED_TYPE's ODCIAggregateIterate function

-- Attributes
strvalue varchar2(100),
pref varchar2(10),
prefvalue varchar2(10)

-- Member functions and procedures
-- N.a.
)
/
create or replace type string_prefered_type as object
(
retvalue varchar2(4000),

static function ODCIAggregateInitialize(sctx IN OUT string_prefered_type) return number,
member function ODCIAggregateIterate(self IN OUT string_prefered_type, value IN STRING_PREFERED_PARS_TYPE) return number,
member function ODCIAggregateTerminate(self IN string_prefered_type, returnValue OUT varchar2, flags IN number) return number,
member function ODCIAggregateMerge(self IN OUT string_prefered_type, ctx2 IN string_prefered_type) return number
);
/
create or replace type body string_prefered_type is
static function ODCIAggregateInitialize(sctx IN OUT string_prefered_type)
return number is
begin
sctx := string_prefered_type(null);
return ODCIConst.Success;
end;

member function ODCIAggregateIterate(self IN OUT string_prefered_type, value IN STRING_PREFERED_PARS_TYPE)
return number is
begin

IF self.retvalue is null THEN
self.retvalue := value.strvalue;
ELSIF value.pref is not null AND lower(value.pref) = lower(value.prefvalue) THEN
-- only change the return value if the prefered value is found
-- hence otherwise the behavior is "the first non null value is accepted and does not change", which
-- might be nice to change into a max() or min() feature.
self.retvalue := value.strvalue;
END IF;

return ODCIConst.Success;
end;

member function ODCIAggregateTerminate(self IN string_prefered_type, returnValue OUT varchar2, flags IN number)
return number is
begin
-- just return the set value.
returnValue := self.retvalue;
return ODCIConst.Success;
end;

member function ODCIAggregateMerge(self IN OUT string_prefered_type, ctx2 IN string_prefered_type)
return number is
begin
-- this might prove to be difficult, it's easier to disable PARALLEL execution
-- to enable though, a state needs to be added to enable the merge, the state
-- would flag if the current or other context value was set with a "prefered" value.

return ODCIConst.Success;
end;
end;
/
CREATE or replace
FUNCTION strpref(input STRING_PREFERED_PARS_TYPE)
RETURN varchar2
AGGREGATE USING string_prefered_type;
-- PARALLEL_ENABLE (to enable: implement the merge function)
/
select t.id ,strpref(STRING_PREFERED_PARS_TYPE(t.name, t.pref, 'pickme'))
from testgroupby t group by t.id;

/*
CREATE TABLE "TESTGROUPBY"
(  "ID" NUMBER,
"NAME" NVARCHAR2(10),
"PREF" NVARCHAR2(10) );

insert into TESTGROUPBY (id,name,pref) values (1,'test1','ignoreme');
insert into TESTGROUPBY (id,name,pref) values (1,'test2','pickme');
insert into TESTGROUPBY (id,name,pref) values (1,'test3','ignoreme');
insert into TESTGROUPBY (id,name,pref) values (2,'test4','pickme');
insert into TESTGROUPBY (id,name,pref) values (2,'test5','pickme');
insert into TESTGROUPBY (id,name,pref) values (2,'test6','ignoreme');

select t.id ,strpref(STRING_PREFERED_PARS_TYPE(t.name, t.pref, 'pickme'))
from testgroupby t group by t.id;

drop table TESTGROUPBY;
*/

JQuery Plugin Tip : LiveQuery!

0

http://docs.jquery.com/Plugins/livequery

Code examples will follow shortly ;-D

Fetch Oracle NLS Settings, Install Oracle Full Client in Zend Server.

1

Note that these results were not the ones I’d hoped for, the result was the installation of the full Oracle Instant client in PHP instead of the light version.

SELECT * FROM NLS_DATABASE_PARAMETERS;

PARAMETER VALUE
1 NLS_LANGUAGE AMERICAN
2 NLS_TERRITORY AMERICA
3 NLS_CURRENCY $
4 NLS_ISO_CURRENCY AMERICA
5 NLS_NUMERIC_CHARACTERS .,
6 NLS_CHARACTERSET WE8ISO8859P1
7 NLS_CALENDAR GREGORIAN
8 NLS_DATE_FORMAT DD-MON-RR
9 NLS_DATE_LANGUAGE AMERICAN
10 NLS_SORT BINARY
11 NLS_TIME_FORMAT HH.MI.SSXFF AM
12 NLS_TIMESTAMP_FORMAT DD-MON-RR HH.MI.SSXFF AM
13 NLS_TIME_TZ_FORMAT HH.MI.SSXFF AM TZR
14 NLS_TIMESTAMP_TZ_FORMAT DD-MON-RR HH.MI.SSXFF AM TZR
15 NLS_DUAL_CURRENCY $
16 NLS_COMP BINARY
17 NLS_LENGTH_SEMANTICS BYTE
18 NLS_NCHAR_CONV_EXCP FALSE
19 NLS_NCHAR_CHARACTERSET AL16UTF16
20 NLS_RDBMS_VERSION 9.2.0.7.0

To replace the light with the full client in Zend Server, put the “oraociei11.dll” (full) into the __ZendServerInstallPath__\ZendServer\bin directory and remove or rename the “oraociicus11.dll” (light). These libraries can be found in oracle client installation.

Zend Code Generator on Google Code

4

I started a project to create a zend code generator. It’s a pretty basic 3 layer model that it generates right now, tests included. Take a look at http://code.google.com/p/zend-code-generator/

Quick and Dirty RegEx Tester in Zend Framework.

0

1 public function indexAction()
2 {
3 Zend_Layout::startMvc();
4 self::getFrontController ()->setParam ( “noViewRenderer”, true );
5
6 $subject = $this->_getParam(“subject”,”");
7 $pattern = $this->_getParam(“pattern”,”//”);
8 $result = preg_match_all($pattern, $subject, $matches);
9
10 $form = new Zend_Form();
11 $subjectElement = new Zend_Form_Element_Text(“subject”);
12 $subjectElement->setValue($subject);
13 $form->addElement($subjectElement);
14
15 $patternElement = new Zend_Form_Element_Text(“pattern”);
16 $patternElement->setValue($pattern);
17 $form->addElement($patternElement);
18
19 $form->addElement(“submit”,”send”);
20
21 echo $form;
22 echo Zend_Json::encode($matches);
23 }

Thanks for the html conversion of this code:
http://www.phpdebutant.com

Regex Tutorial/Reference:
http://www.phpro.org/tutorials/Introduction-to-PHP-Regex.html

Google Favicon PHP Proxy.

0

A little code snippet to fetch and cache favicons via the google s2 favicon service.
It uses the PHP Zend framework to store and retrieve the favicons from a (MySQL) database …

http://ingol.nl/code/FaviconProxy.htm

Exploring jQuery Grids

0

Grids:
FlexiGrid
jqGrid

Google App Engine Supports JAVA!

0

App Engine is unveiling its second language (first = Python): Java. Today’s release includes an early look at our Java runtime, integration with Google Web Toolkit, and a Google Plugin for Eclipse, giving you an end-to-end Java solution for AJAX web applications.

http://code.google.com/appengine/

Go to Top