Saturday, December 19, 2009

Oracle Application Express 4.0 (APEX 4.0) Early Adopter

Just about everyone has already blogged about it, but APEX 4.0 EA is available now.
What else is there to say that has not already been said?  Not much probably, but I'll point out one new feature: APEX 4.0 is not available in Internet Explorer.  I have it on good authority that this feature will only be in the beta and will not make it into the production release--we can hope, though.  (Thanks to Neelesh Shah for pointing out this new feature.)

Also, check out the new SQL Developer features:

And, of course, Patrick's sample plugin:

Thursday, December 03, 2009

ODTUG Kaleidoscope 2010: APEX Plugin Showcase

One of the best new features of APEX 4.0 is the extensible plugin architecture.  You will be able to create your own item and region types as well as custom dynamic actions (javascript enabled actions on the browser).  You'll be able to add these plugins right in to the builder so they are available to all of your developers.  You will be able to share (or even sell) these with the APEX community.  This is big.

To get you started the fine folks at ODTUG are going to build five fantastic plugins and give them away to anyone who attends Kaleidoscope 2010.  You can check out the details here.

The trick to writing a great plugin is to have a great idea.  I'll have some input into the five plugins.  If there is an APEX item type, region type or dynamic action that you think should be there but isn't, please leave me a comment and let me know. 

Monday, November 30, 2009

Interesting APEX with dblink issue

We recently ran in to a problem when connecting across a database link to a Postgres database.  The query looked like this
select "column1", "column2"
  from "my_schema"."my_long_named_view"@my_db_link
It works fine from sql*plus and sql Developer, but when running the same query in Application Express (in an app or in the SQL Workshop) we got this error:
ORA-28500: connection from ORACLE to a non-Oracle system returned this message: [Generic Connectivity Using ODBC]DRV_QspecDescribe: DB_ODBC_RECORD (189): ; [OpenLink][ODBC][PostgreSQL Server] current transaction is aborted, commands ignored until end of transaction block (SQL State: S1000; SQL Code: 1) ORA-02063: preceding 2 lines from MY_DB_LINK
Dave Rydzewski came up with the solution.  Shorten the name of the view in Postgres and change the query to look like this (note two fewer double quotes "):
select "column1", "column2"
  from "my_schema.short_v"@my_db_link
I'm still not sure what APEX does to make it blow up.  I wonder how many people use APEX with a db link to Postgres.

Tuesday, November 24, 2009

VMware pc2mac

I thought tonight was going to be the night.  I purchased a macbook pro about 6 weeks ago.  I've slowly been getting familiar with the mac, and realizing that I'll probably still need a PC image at least occasionally.  Last night I installed VMware Fusion for the mac (nice that it's called Fusion, that way it almost has something to do with this Oracle blog).  Tonight I was to create the image from my work laptop and test it out on the macbook.  Alas, try as I might, I still don't have an image.  This is my story.

I read the VMware readme (yep, I do that kind of thing).  I learned about pc2mac, the utility that lets you stream the image right off your running pc and onto an image on your mac.  I read the guides.  I installed the pc2mac utility on my PC, restarted my PC and the VMware Fusion PC Migration Agent screen opened right up.  I ran VMware on the mac and followed the instructions, typed in the four-digit passcode, the administrator password, clicked continue, and got an error:

Converter failed to connect to remote machine.
An error occured while transferring data
I tried a few times, but did not get any further.  I decided to come back later, but first, I returned to the PC to close out the migration agent.  Noticing the checkbox "Run the VMware Fusion PC Migration Agent Every time I start my PC", I realized that I probably don't want this to every time.  I unchecked the box.

Returning later to try again, I could not find a way to start up that migration assistant.  I googled.  I rebooted, re-installed pc2mac, rebooted, uninstalled, rebooted, reinstalled, rebooted.  Mind you, this was the PC I was rebooting--not a quick affair, much like this blog post.  I'll cut to the chase, even an uninstall and reinstall would not bring up that screen again.  I finally found the trick though.  Edit the registry:

HKEY_CURRENT_USER > Software > VMware, Inc. > PC Migration Agent
Edit RunAtStartup and change from 0 to 1.

Of course, the change from 0 to 1 was just a guess, but it worked.

Now, at 11:06pm, I'm back to having a pc2mac utility that will run the first screen, but it still does not work.  Now that's progress.  Oh, and my wife just said, "How do I find your blog?"  Good night everybody.

[Update: 25 Nov 2009, 4:53pm]  I also had an issue logging an issue with VMware.  The first problem was that I could not register the product.  The VMware registration website kept giving an error that it was not a valid code despite the fact that it was in the email and the product installation accepted it.  I was able to log a customer service issue about not being able to register, but I was not able to log a technical issue without first registering.

I called and spoke with an extremely helpful support rep.  She told me they were having issues with some registration numbers and offered to create the technical ticket for me.  She was so helpful that I went back to the VMware site to drop a note to anyone that would accept it.  This is the note I typed:

I recently purchased VMware Fusion.  I generally know my way around technology, but just registering my VMware software on the website was impossible (truly, as there is currently a bug in your system).  After quite a bit of frustration, though, I finally called and spoke with a support representative.  I'm sorry that did not get her full name, but she created a new SR for me, 1459858086, and it has been assigned to SGARDNER.

This support rep was very helpful, polite and overall reflected very well on VMware.  Though my issue has not been resolved, I had a very positive experience speaking with this rep.  If you have the ability to commend her I hope you will.
That's not bad, right?  Unfortunately, though, it never went anywhere.  The only page I could find a place type the note was here:
The page never allowed me to pick a Country or State.  It just kept showing "loading..." without ever showing a country.  Of course, those fields are mandatory.

Sorry friendly support rep, I'm afraid that note won't make it anywhere.

Wednesday, November 04, 2009

Looking for APEX Developers

I have a client in the northeast of the US. If you are really good with the Oracle DB, pl/sql and APEX, and live or want to move to the US Northeast, send me your info and I'll pass it along. Please send an email with your resume to me (anton) at work (



Wednesday, September 30, 2009

Cloning an Oracle Schema

When I started this blog I decided I would only blog about things you could not find reasonably easily with a simple google search. This post violates that rule. Cloning a schema is something that I do fairly frequently but not frequently enough that I remember the exact syntax. First I googled it every time, later I created a little text file with the commands. Having already gone to the trouble to write a text file, I might as well just paste it in here. I use datapump. In the example below I want to export the SCOTT schema which has all of its data in the USERS tablespace. I want to import it into a database (either the same or another Oracle database) as the user SCOTT2 in the tablespace USERS2. That means I need to change both the database schema and tablespace. Here are the commands (replace values as appropriate for your env):
export ORACLE_HOME=/opt/oracle/product/oracle10g
export ORACLE_SID=c2dev1
./expdp system/ dumpfile=scott.dmp schemas=scott
Note: this will create the file scott.dmp in the location $ORACLE_HOME/admin/dpdump. You can create a different directory for it, but for my purposes this is sufficient.

That is all it takes to do the export.
If you plan to import into the same database it can stay in the same location.

To do the import into a different database you will need to copy the scott.dmp file to the right location for the other database.
cp $ORACLE_HOME/admin/c2dev1/dpdump/scott.dmp /mynas/scott.dmp
Then I ssh to the target machine and copy to the new target location
cp /mynas/scott.dmp $ORACLE_HOME/admin/c2dev2/dpdump/scott.dmp

export ORACLE_HOME=/opt/oracle/product/oracle10g
export ORACLE_SID=c2dev2
./impdp system/ dumpfile=scott.dmp remap_schema=scott:scott2 remap_tablespace=USERS:USERS2
That should do it. This should make it easy for me to do in the future and hopefully help someone else along the way.

Tuesday, September 29, 2009

APEXposed 2009 - A request for input

I will be speaking at APEXposed 2009 in Atlanta, GA on 10 & 11 November. Some of you have certainly seen the How to Hack an APEX Application presentation. I will be giving a revised version of that. It is difficult to find interesting things because the APEX developers keep adding features to make it harder for developers to get into trouble, but I'll have a few items of interest, plus the old standby's.

My second talk is APEX and the Oracle Database.
The power of APEX is partly the immense scope of capabilities present in the Oracle database. In this presentation I am going to show how to use many of these capabilities within APEX. Below are a few topics I have in mind.
  • Oracle Text (Intermedia)
  • Spacial
  • SQL Analytics
  • File Compression
  • owa routines
  • utl_inaddr
  • External Tables
  • Virtual Private Database
I'd love to get additional ideas--if you have any favorites, please let me know!

Wednesday, June 10, 2009

Migrating Portal Repository with change in DN

Another in a long line of very esoteric issues...

If you are migrating a portal repository, possibly from Production back into Dev or vice versa you may run into the following error when running ptlconfig

STEP 1 : Populating Portal seed in OID
Creating Lightweight User Accounts and Groups in OID
Portal schema version is:
Error code : -6502
Error message: ORA-06502: PL/SQL: numeric or value error
ERROR: creating lightweight users and groups in OID ... exiting

PL/SQL procedure successfully completed.

This happens if you have changed the base dn of your OID. For example, you might have had a dn of dc=concept2completion,dc=net
and then decided to change to dot com

or possibly you removed a sub-domain
changed to

In either case, you will get the error listed above. The problem is that the script secoidd.sql relies on the dn stored in the table wwsub_model$. Below is an extract of secoidd.sql

if l_subscriber_dn is null then
-- The control should never reach here as the subscriber DN
-- should be available in the wwsub_model$ table.
So, if you get into this position, you will need to update the value in the dn column of wwsub_model$.

Seems like such a simple solution. So simple that I have now gone to the process of figuring it out three times.

Monday, June 08, 2009

SQL for Date Spanned Data

I was recently presented with a sql challenge. Although I came up with something that works, I'm not convinced it is the best solution. This is a very long post that is mostly question, but possibly a helpful example. The details are below.

I was given a table with the following columns
ID -- Primary Key
DIVISION -- Identifier of a Division
START_DATE -- Date when the Division starts
END_DATE -- Date when the Division ends

If you want to try this yourself, I added all the create statements and sample data creation to the end of this note.

The data has an implicit concept of a "span." A Division may have many spans. The start date of a new span is typically one day after the end date of the previous span. In this case a Division has a contiguous span. Spans never overlap; that is, a single division never has a row with a start date between the start and end date of another row of the same division (and never has an end date between the start and end of another row of the same division).

Below is some sample data:

Id, Division, Start_date, End_date

10 1 09-JUN-2009 10-JUN-2009
11 1 11-JUN-2009 12-JUN-2009
12 1 13-JUN-2009 14-JUN-2009 -- Note the following row is not contiguous
14 1 17-JUN-2009 18-JUN-2009
15 1 19-JUN-2009 20-JUN-2009

If this were the total data set then Division 1 would have 5 spans, but only two contiguous spans (09 - 14 Jun and 17 - 20 Jun).

The challenge was to create a sql statement to only return contiguous spans by division. I immediately thought of a CONNECT BY but the challenge was to determine the START WITH condition.

[Update: In response to this post Alex Nuijten came up with a better method than any described below. Take a look here: ]
I came up with two ways to do this. I'm still not certain if there is a better solution. The first is far better and uses some SQL analytics to determine the START WITH condition. If you were to use a WHERE clause, it should go in the WITH section as identified. My example is below.

with span_info as (select s.division, s.start_date, s.end_date
, (s.start_date -lag(end_date, 1) over (partition by s.division order by start_date)) new_span
-- null or > 1 indicates a new contiguous span
, (lead(start_date, 1) over (partition by s.division order by start_date) - s.end_date) end_span
-- the end_span is not needed, just left for example
-- null or > 1 indicates the end of a contiguous span
from spantest s
-- a WHERE clause would go HERE, not in the main SELECT below
order by 1, 2 )
select division
, connect_by_root start_date span_start -- start of a contiguous span
-- , start_date -- start of the last span of a contiguous span
, end_date -- end of the contiguous span
-- , new_span, end_span, connect_by_isleaf
from span_info
where connect_by_isleaf = 1
-- gets only "leaf" recodes, i.e. the end of a contiguous span
start with nvl(new_span,1000) > 1
-- gets beginning of a contiguous span
connect by
prior end_date + 1 = start_date
-- connects spans, the 1 here and in the "start with" can be changed together
and prior division = division
-- ensures spans are for the same division
order by 1, 2

My second idea is to use an exists command to determine if the the first there exists a row with an end_date equal to start_date - 1 for the division. I can write the statement, but I'm not sure how to get the combination of the DIVISION and the START_DATE in to the START WITH. I could do some concatenation, but I don't like that at all. The code is below, but DO NOT RUN THE QUERY; it is very slow.

-- ************ DO NOT RUN THIS QUERY
select division
, connect_by_root start_date span_start -- start of a contiguous span
-- , start_date -- start of the last span of a contiguous span
, end_date -- end of the contiguous span
-- , new_span, end_span, connect_by_isleaf
from spantest
where connect_by_isleaf = 1
-- gets only "leaf" recodes, i.e. the end of a contiguous span
start with to_char(start_date,'yyyymmdd') ||'~' || division in
(select to_char(st2.start_date,'yyyymmdd') ||'~' || st2.division
from spantest st2
where not exists
(select 1 from spantest st3
where st3.division = st2.division
and st3.end_date = st2.start_date + 1
and !=
-- gets beginning of a contiguous span
connect by
prior end_date + 1 = start_date
-- connects spans, the 1 here and in the "start with" can be changed together
and prior division = division
-- ensures spans are for the same division
order by 1, 2

This is a lot of code and no-one other than me may ever read it. If you do, though, and have other ideas, I would love to hear them.

-- ********* Create Statements and sample data




before insert on "SPANTEST"
for each row
if :NEW."ID" is null then
select "SPANTEST_SEQ".nextval into :NEW."ID" from dual;
end if;


-- create sample data for 10 Divisions
for i in 1..20 loop
insert into spantest (division, start_date, end_date)
select 1, trunc(sysdate + (rownum*2 - 1)),trunc(sysdate + (rownum*2)) from all_tables;
end loop;

-- create span gaps on the 15th of each month
delete from spantest where
to_char(start_date,'dd') = '15'

Wednesday, May 06, 2009

Locating a Corrupt PDF (or many types of corrupt files) in a BLOB

I recently had a client pose the following question to me.
We have a system that generates pdf's based upon data from our Oracle database. The pdf's are then stored in a BLOB column in a table. We recently realized that at least one of those pdf's was corrupt. Is there a way within Oracle to determine if others are corrupt?

I initially thought about trying to write a script that would pull each blob, run it through some kind of pdf validator and write a log entry if it were bad. Hmmm, use plsql and call out to a validator on the O/S? Write a java routine to do the same thing? What validator would I use?

Then I had an idea--Oracle Text (formerly Intermedia and Context). I could create a context index on the blob column and see if there are any errors.

CREATE INDEX myIndex ON my_table(my_blob) INDEXTYPE IS ctxsys.context;

If the Oracle Text engine is unable to index the blob it writes a log entry to the view ctx_user_index_errors including the rowid. Depending on the database version you might have issues with very recent versions of the pdf, but that was not an issue in our case as every pdf was created by the same pdf generator.

I think Oracle Text is underused. This is just one more example of how to make it work for you.

Saturday, May 02, 2009

Oracle SQL Delimiter

It's been a while since I made a real post, one that has some technical merit. This one just barely qualifies.

There is a nice classic report type "Function Returning a SQL Query" which allows you to write a block of code that returns a select statement. That select statement is the basis for the report. I often use it to simplify building a where clause. It might look something like this:

l_q varchar2(32767); -- This is the return variable. It will hold a select statement

l_q := 'select department, employee
from dept d, emp e
where d.deptno = e.deptno ';

if :P1_DEPTNO is not null then
l_q := l_q || ' and d.deptno = :P1_DEPTNO ';
end if;

-- insert more if statements like above

return l_q;

With Interactive Reports this has become less likely, but it still happens.

Sometimes, though, the query is a bit more complicated, something like this:

l_q := 'select department, employee,
to_date(to_char(e.hiredate,''yyyymm'' ||''01''),''yyyymmdd'') first_day_of_month
from dept d, emp e
where d.deptno = e.deptno
and e.status in (''NEW'', ''PENDING'', ''FOO'')
and d.status = ''NEW'' ';

if :P1_DEPTNO is not null then
l_q := l_q || ' and d.deptno = :P1_DEPTNO ';
end if;

-- insert more if statements like above

return l_q;

You get the idea, a lot of strings and a lot of double ticks (''). There is an easier way, though: a custom SQL Delimiter. Usually a single tick (') indicates the start of a string. If you use a tick within it, you need two ticks ('') to escape it (see code above). But you can avoid that with a custom delimiter. You turn it on with q', that's all, just the letter q followed by a tick. The trick is that the very next character is the delimiter, and a few are special. You end the statement with followed by a tick. Examples are the easiest, so here are a few:

1. l_q := q'! I don't need to escape the ' in the word don't !';
In this case the ! is the special character. q'! starts the string and !' ends it.

2. l_q = q'{ I don't need to escape the ' in the word don't }';
This is a little different. If your special character is { then you use }' to turn it off. It is pretty obvious which are special: [], {}, <>.

So, the code above becomes:

l_q := q'{ select department, employee,
to_date(to_char(e.hiredate,'yyyymm' ||'01'),'yyyymmdd') first_day_of_month
from dept d, emp e
where d.deptno = e.deptno
and e.status in ('NEW', 'PENDING', 'FOO')
and d.status = 'NEW' }';

if :P1_DEPTNO is not null then
l_q := l_q || ' and d.deptno = :P1_DEPTNO ';
end if;

-- insert more if statements like above

return l_q;

You can use this just about anywhere in sql or pl/sql where you want a string.

Friday, April 10, 2009

What is this?

First, I apologize, this is my third post in a row that is not technical. I promise I will get back to the real purpose of this blog in my next post.

Now, on to the question. Does anyone recognize this device? I found it in my closet the other morning. I suspect I probably took it out of a bag after a trip, or picked it up instead of stepping on it in one of my kids' rooms. I probably knew what it was at the time, probably thought I would stick it there for a few days and deal with it later. Now it is later, though, and I have no idea what it is or where it came from.

It takes 3 AAA batteries. It has no identifying markings of any kind. Inside the battery compartment there is no writing. When I turn it on it makes a very high pitched, very low volume whining noise. There is nothing on the sides that are not shown in the two images above. You now know as much as I do about this thing.

If you know what this is, really know what it is, please post a comment. Thanks.

Update: We have a winner! I won't publish the answer here, in case you want to guess. Check out the comments for the answer.

Thursday, April 09, 2009

Going Viral

This is a chart of traffic on
As you can see, yesterday crapmanagement "went viral," more than doubling its former high (which was mostly me testing the web logging capabilities).

Wednesday, March 25, 2009

Oracle Portal and APEX RSS Feeds and Traffic Analysis

I try to avoid advertising in this blog, but I'm going to break that rule as I have had a few inquiries lately on these topics. C2 has new product offerings that provide RSS feeds for Oracle Portal and APEX. For details, contact C2. C2 also has a web traffic capture and reporting tool. This tool can be used on any site, but has a few specific capabilities related to Oracle Portal and Application Express. Again, for details, contact C2.

And just an update on my last post -- the fine folks on the APEX team released patch 833890 to solve this import issue. You can get the patch at

Wednesday, March 11, 2009

APEX 3.2 Gives Error on Import - ERR-3331

Just a quick note regarding the 3.2 import process... APEX added a number of enhancements and checks during the import of an application. The downside is that these introduced some negative performance characteristics. If you are importing a medium to large size app you are likely to get either a timeout or an error message:
ERR-3331 This page was already submitted and can not be re-submitted.

Oracle has confirmed the problem and a fix is in the works. I'll update this post when the patch is available.

The good news is that the application will import anyway. After you get the error, just go back to the builder and check to make sure the import was successful.

25-Mar-2009: More good news -- the fine folks on the APEX team released patch 833890 to solve this issue. You can get the patch at

Monday, March 09, 2009

APEX 3.2 - save state before branching

Just a quick note about a little known new feature in APEX 3.2: save state before branching. When creating a branch and setting items with values, you now have the option to either pass those values in the URL or to have APEX set them into session state prior to doing the branch.

Thursday, March 05, 2009

Application Express (APEX) 3.2

We went through the upgrade to 3.2 last night and it was very smooth. We had a couple minor challenges but that is because of our unique environment.

1. We have an SSO configuration. APEX does not specify the owner of the package wwv_flow_custom_auth_sso when it generates the return link for SSO. This means that the APEX_PUBLIC_USER (or whatever user your DAD is configured to use) must have a synonym to wwv_flow_custom_auth_sso. You can also create a public synonym so long as one does not exist for another application.

2. I noticed that some of our custom stylesheets give a slightly different look with date picker items. This may be due to a change in the way APEX 3.2 generates date pickers. I'll look into it and post anything I find.

3. Apex has a new database schema. It has finally moved to APEX_030200. [ removed a comment about the version that was wrong... thanks Patrick! ]

A very easy install, really. Thanks to the APEX team once again!

Friday, January 16, 2009

APEX - Application Express 3.2, More than a Forms Conversion Release

Application Express 3.2 has been advertised as a Forms Conversion release, but I've recently been looking over an additional category of enhancements that are due to be in the next early adopters release. It probably comes as not surprise to those who know me that the category is security. Below is a partial list of the enhancements as I understand them. Once I get my hands on the EA release I'll provide more significant commentary, but I like what I see so far.

Declarative authentication timeouts by session length and idle time

Only allow a developer to stay logged into the APEX builder for a specified period of time or time spent idle. This is handled server side, so just hacking the local cookie won't bypass the timeout--nice!

HTML Form settings for Password pages (autocomplete=off)
Does what it says.

Reduced privilege of APEX schema
No change to functionality, or really even to security as long as your FLOWS_xxx schema is secure, but any time you can skinny down privs to the minimum required it closes the possibility of a loophole.

Database monitoring disabled by default

Seems to make sense.

Declarative session state encryption
Now this makes great sense. APEX has a reasonably good security model in place to protect session state information, but we all know where session state is stored, in a single table in the FLOWS_XXX schema. I've never liked the idea that my SSN make hang out in that table for some DBA to look at, or possibly have some rogue developer write some hidden page that let's them go peek at my session state. Allowing a developer to indicate that an item be encrypted when saved in the database without having to worry about encrypting and decrypting the item greatly reduces the developer's burden--or more likely, means it will actually happen.

New Password item types that do not save state
In short, never persist this password data into the APEX sessions state table. I love the idea, though I wonder if a checkbox giving all items this option might not be better. We'll see how this turns out . . .

Ability to specify HTTPS for the APEX instance
In short, only allow the APEX builder to run when the browser is communicating via HTTPS.

OK, so how about one feature that is not on the list? Who would like a "Scratch" item type--an item that is never rendered, never posted and not settable on the URL? It would just be a place to store session state, somewhat like an application item that has session state protection enabled, but the item is on a page. Let me know what you think.