If you need to create a dynamic SQL for a select list or any other type of a LOV, your query should not exceed 4000 characters. In case it does, you will get the "ORA-06502: PL/SQL: numeric or value error: character string buffer too small" error. That is the internal limitation of the APEX table storing the item attribute information. In case you can't rewrite your SQL to satisfy this limitation, you may use the package I created for that purpose. It is quite simple and it does the following:
1. It will use the apex_collection package to parse the query and crate a collection
2. It will query the collection and use a pipelined function to return a simple LOV (SELECT d, r FROM table)
You can also use the get_long_dynamic_query function in the package to generate your dynamic SQL. The example at apex.oracle.com I provided extends the query with "dummy" conditions in order to make it long enough and prove the concept.
Tuesday, 19 March 2013
Saturday, 16 March 2013
Formating and Exporting a Report Column
Sometimes you need to format a report column and if you need to do that
in the report SQL, you will be faced with a problem while exporting the
report - the formatted values will be exported 1:1 and you will see
those
ugly html tags among the exported data. In early days of APEX people
recommended using two columns - one to display in a report and hide it
while exporting and one hidden column used for exports only instead. You
would then use a condition like this:
to says not to export or the opposite one:
to say to export.This solution may work with a standard report but it can't be used efficiently with Interactive Reports.
Just in case you didn't know, you can solve that problem easily. See this example at apex.oracle.com. There, I am using a function to format a string and use the value of the current request to see if the report is simply getting rendered on the page or exported. If the report is exported, I will not use the formatting tags and return the values as it was parsed.
apex_application.g_excel_format = FALSE
to says not to export or the opposite one:
apex_application.g_excel_format = TRUE
to say to export.This solution may work with a standard report but it can't be used efficiently with Interactive Reports.
Just in case you didn't know, you can solve that problem easily. See this example at apex.oracle.com. There, I am using a function to format a string and use the value of the current request to see if the report is simply getting rendered on the page or exported. If the report is exported, I will not use the formatting tags and return the values as it was parsed.
Thursday, 14 March 2013
APEX Collections and Joins
APEX Collections is one of the best features of APEX. There are situations where solutions wouldn't be possible if this feature would not be available. However, the collections have some limitations. One of the limitations is if you need to store number values and use those values to join a collection with other tables. The consequences may be that you receive something like
The strange thing with this error is that it may occur sporadic and you can't realy understand why it happens. If you operate on different systems (development, testing, production) you may receive this error on one of the instances and never on the other one. I asked Patrick Wolf about the reasons and he answered that this has to do with the way the cost based optimizer works. If it uses a different plan from the one you would expect, it may find non numeric values in the same column comming from a different collection. In that case the solution is to use the numeric columns in the collection (n0xx) for storing numeric values used in later joins.
ORA-01722: invalid number
The strange thing with this error is that it may occur sporadic and you can't realy understand why it happens. If you operate on different systems (development, testing, production) you may receive this error on one of the instances and never on the other one. I asked Patrick Wolf about the reasons and he answered that this has to do with the way the cost based optimizer works. If it uses a different plan from the one you would expect, it may find non numeric values in the same column comming from a different collection. In that case the solution is to use the numeric columns in the collection (n0xx) for storing numeric values used in later joins.
Wednesday, 13 March 2013
Upgrade to APEX 4.2.1.00.08 - First Impressions
Today one of my customers upgraded their APEX 4.0 to 4.2.1.00.08. The whole process was completed without any issues. After the upgrade there was only one problem we could notice. Our translated applications didn't work for the other languages then the primary language. Trying to run any of the translated applications would result in an internal error. The reason was that the image path wasn't there for any of the tranlations:
After entering the image path and repeating the neccessary translation steps everything worked well.
After entering the image path and repeating the neccessary translation steps everything worked well.
Sunday, 3 March 2013
Reading a file from an URL and storinig it as a BLOB
In this example at apex.oracle.com you can se how you can use an URL (which normaly provides a save/download dialog for saving or opening a document) to store the document directly in your own table as a BLOB. Unfortunatelly the ACL settings at apex.oracle.com do not allow to get this working there and the working example is just a fake, showing only how this should normaly work.
Thursday, 28 February 2013
Oracle and APEX
This is the text of an email I received as a response after creating an account for my workspace and my demo application at apex.oracle.com:
"Thank you so much. Oracle and APEX has the most amazing network of help and solutions. It is impressive."
"Thank you so much. Oracle and APEX has the most amazing network of help and solutions. It is impressive."
Monday, 18 February 2013
APEX Training 15.04. - 17.04.2013
Wie jedes Jahr in den letzten sechs Jahren, veranstalten wir (Dietmar Aust
und ich) unser
- jQuery (Beispiele und Übungen)
- APEX Collections
- Erstellung von komplexen Forms
- APEX und Mehrsprachigkeit
Wir haben dieses Mal einen ganz speziellen Gast zu der Schulung eingeladen - Christian Rokitta aus den Niederlanden. Er ist ein Experte in Sachen Layoutgestalltung und Mobile Applikationen. Die Teilnehmer der Schulung werden sich gemeinsam für eins dieser Themen entscheiden und Christian wird es vortragen.
Unser Highlight sind auf jeden Fall die abendlichen Q & A Session, in denen die Teilnehmer die Gelegenheit bekommen ihre eigenen Projekte vorzustellen und ihre konkrete Probleme mit uns zu diskutieren.
Die Anmeldung zur Schulung finden Sie hier.
Oracle APEX: Knowhow aus der Praxis
Training in Bensheim an der Bergstrasse. Wir werden unsere bisherigen Themen überarbeiten und einige neue Themen hinzufügen. So werde ich auch folgende neue Themen in das Programm der Schulung aufnehmen:
- jQuery (Beispiele und Übungen)
- APEX Collections
- Erstellung von komplexen Forms
- APEX und Mehrsprachigkeit
Wir haben dieses Mal einen ganz speziellen Gast zu der Schulung eingeladen - Christian Rokitta aus den Niederlanden. Er ist ein Experte in Sachen Layoutgestalltung und Mobile Applikationen. Die Teilnehmer der Schulung werden sich gemeinsam für eins dieser Themen entscheiden und Christian wird es vortragen.
Unser Highlight sind auf jeden Fall die abendlichen Q & A Session, in denen die Teilnehmer die Gelegenheit bekommen ihre eigenen Projekte vorzustellen und ihre konkrete Probleme mit uns zu diskutieren.
Die Anmeldung zur Schulung finden Sie hier.
Saturday, 16 February 2013
Count Substring Occurrences in a String
If you write a lot of PL/SQL code, sooner or later you will be faced with a requirement to count the number of occurrences of a substring in a string. In that case you may use this example to help yourself:
http://apex.oracle.com/pls/apex/f?p=31517:282
It will search not only for a single character withing a string but also for a substring of any length up to 4000 characters.
http://apex.oracle.com/pls/apex/f?p=31517:282
It will search not only for a single character withing a string but also for a substring of any length up to 4000 characters.
Thursday, 14 February 2013
APEX Authentication Function
Did you
know that an authentication function in APEX is not used the way a function
actually should be used? Normally, this
function has two input parameters and it will return TRUE or FALSE. However,
you will name this function in your authentication schema by typing it into a
box, without providing any parameters. I have never looked into that but my assumption
is that APEX will probably create a kind of a dynamic function call by providing
the parameters using login items (:p101_username, :p101_password) from your
login page (101).
Now, it may
happen to you that you not just only copy / paste the code in your new
application but you decide for some reason to write your authentication
function from scratch. There is one important thing you shouldn't forget: You
can not name the function input parameters as you like. Otherwise, the function
will not work. It will cause an error like this:
This error
message is a bit confusing and it may make you busy for a while. At least it
does that with me from time to time.
Saturday, 1 December 2012
APEX - Statement of Direction
The new Statement of Direction is touching a couple of interesting things. Here are the three most important:
I think this is quite exciting and I can hardly wait to see it working. Theses are of course only the most important details. We will probably see a lot of other smaller things changing and improving.
I would like to add a couple of wishes to the list if not too late:
- New Multi-Row Edit Region Type – Define a new region type with a modern UI for updating multiple rows of data and allow multiple regions on one page
- Master / Detail / Detail – Provide a wizard interface to define declarative master/detail/detail regions.
- Multiple Interactive Reports – Allow any number of Interactive Reports to be defined on a single page.
I think this is quite exciting and I can hardly wait to see it working. Theses are of course only the most important details. We will probably see a lot of other smaller things changing and improving.
I would like to add a couple of wishes to the list if not too late:
- a wizard for creating tabular forms based on collections
- a wizard for creating single record forms managed by a procedure (package)
- an additional page element feature - update session state on change
- a new page element - simple checkbox
Monday, 5 November 2012
Package for Creating Custom Code
Sometimes you will need to create your own processes for fetching values, validating and updating tables in a form. In some situations the wizard generated form will not be good enough to cover all you need. In that case you need to write your own code. Some programs like TOAD have a routine which generates update or delete procedures for you. However, you need to extend that and it is quite a bit of work. In my Demo Application I made the code available, which does almost all the work for you. This package has a couple of functions able to generate the code which requires only some minor changes. If you ever need to go away from the standard APEX form, you can do that this way:
1. Create the package "create_pkg_from_table" in your schema by running the code from the page I mentioned,
2. Create a form using wizard,
3. Remove the automatic processes and change the standard settings in the page items and use the following setting:
a) Set the "Source Used" to "Only when current..."
b) Set the "Source Type" to "Static Assignment..."
4. Create the custom package related to the table you reference in your form, for fetching, validating, updating and deleting records by running this SQL and executing the output:
1. Create the package "create_pkg_from_table" in your schema by running the code from the page I mentioned,
2. Create a form using wizard,
3. Remove the automatic processes and change the standard settings in the page items and use the following setting:
a) Set the "Source Used" to "Only when current..."
b) Set the "Source Type" to "Static Assignment..."
4. Create the custom package related to the table you reference in your form, for fetching, validating, updating and deleting records by running this SQL and executing the output:
SELECT create_pkg_from_table.create_package ('EMP', 'EMPNO', 1)
FROM DUAL;
5. Finally, run the following SQL to create the calls to the package functions and procedures you will need in your page processes and validations:
SELECT create_pkg_from_table.create_plsql_block ('EMP', 'EMPNO', 1)
FROM DUAL;
The only thing you need to do now is to format that code and paste it in the appropriate process.
Friday, 26 October 2012
Goodbye apexblogs.info
http://www.apexblogs.info was a place I visited daily. A couple of days ago this domain was moved to http://www.odtug.com/apex. I am not sure I understand why but it doesn't matter. The only thing is that from the usability perspective this is now at least two steps back.
The current layout of the page is displaying a couple of logos, advertisements and some general information and the content is not in the focus - 75% of the page is not showing that, what you would actually expect. You need to scroll down to find the content and you need to scroll a lot. There are all together three scrollable regions including the page and if you don't watch you will easily loose the orientation.
Now, the question to ODTUG people would be if this is going to change in the near future. Hopefully there are plans to improve the usability of this popular resource. Otherwise the whole action doesn't make a lot of sense.
Sunday, 14 October 2012
APEX Reporting on Comment Columns
This function may help you if you need to report on columns with a lot of text. It will get rid of the carriage return and will help not to break your reports imported into Excel:
CREATE OR REPLACE FUNCTION x_rep (p_string IN VARCHAR2)
RETURN VARCHAR2
IS
v_string VARCHAR2 (4000);
BEGIN
v_string :=
REPLACE (TRANSLATE (p_string, 'x' || CHR (10) || CHR (13), 'x'),
';',
'/'
);
RETURN v_string;
EXCEPTION
WHEN OTHERS
THEN
RETURN NULL;
END x_rep;
/
Monday, 1 October 2012
My Demo Application
The link to My Demo Application on apex.oracle.com has been changed from
http://apex.oracle.com/pls/otn/f?p=31517:1
to
https://apex.oracle.com/pls/apex/f?p=31517:1
While trying to open the old link you will receive a funny message:
Sunday, 2 September 2012
APEX 4.2
Today, apex.oracle.com was updated to 4.2. My first impression was good - I haven't seen the early adopter this time. If you have an account at apex.oracle.com you can have a look at the new layout of the apex builder. There are a lot of new features to explore in this version. The focus of this version is mobile development. Enjoy.
Sunday, 26 August 2012
Highlight Search Term
APEX can highlight the search string in a report if you enter the substitution string in the column property of your report - Highlight Words. Unfortunatelly it will higlight the first occurence only. If you want to highlight more then only one occurence then you can use this function. The only limitation is the number of characters you can return per column (4000):
FUNCTION get_string_highlight (p_string IN VARCHAR2, p_highlight IN VARCHAR2)
RETURN VARCHAR2
IS
v_string VARCHAR2 (4000);
v_substring VARCHAR2 (4000);
v_trailingstring VARCHAR2 (4000);
v_newstring VARCHAR2 (32000);
v_position NUMBER := 0;
v_length NUMBER := LENGTH (p_highlight);
v_span_start VARCHAR2 (400)
:= '<span style="color:red;font-weight:bold">';
v_span_end VARCHAR2 (400) := '</span>';
BEGIN
IF p_highlight IS NOT NULL
THEN
v_string := p_string;
FOR i IN 1 .. 20
LOOP
v_position := INSTR (UPPER (v_string), UPPER (p_highlight));
IF v_position > 0
THEN
v_substring := SUBSTR (v_string, 1, v_position + v_length);
v_substring :=
SUBSTR (v_string, 1, v_position - 1)
|| v_span_start
|| SUBSTR (v_string, v_position, v_length)
|| v_span_end;
v_string := SUBSTR (v_string, v_position + v_length);
v_newstring := v_newstring || v_substring;
END IF;
EXIT WHEN v_position = 0;
END LOOP;
v_newstring := v_newstring || v_string;
ELSE
v_newstring := p_string;
END IF;
RETURN v_newstring;
END get_string_highlight;
Sunday, 8 July 2012
Count Checked Rows in a Tabular Form
This is a quite simple but still frequently asked question. Here is an example on how to count checked rows in a tabular form. You may need this functionality prior to processing. For example, if you want to inform your user that they didn't select any rows after pressing the "Delete" button.
http://apex.oracle.com/pls/otn/f?p=31517:281
Thursday, 28 June 2012
Text Area with Character Counter in a Tabular Form
This small example shows how to create a textarea in a tabular form with a character counter, similar to the one for the page item of type "Textarea":
http://apex.oracle.com/pls/otn/f?p=31517:276
APEX Tabular Form and ORA-01403: no data found
If you get the "ORA-01403: no data found" error after running your code while updating or validating a tabular form, you will need to find out which array is causing it. This error occurs if the referenced array does not exist - apex_application.g_f01..g_f50. For example, if you use a PL/SQL block similar to this:
1. Firefox
2. Firebug
Activate the firebug and use the HTML option to go over the elements (columns) in your tabular form. Firebug will show the associated array number and you can use that information to correct you code.
DECLARE
vrow BINARY_INTEGER;
BEGIN
FOR i IN 1 .. apex_application.g_f01.COUNT
LOOP
vrow := apex_application.g_f01 (i);
UPDATE dept
SET dname = apex_application.g_f04 (vrow),
loc = apex_application.g_f05 (vrow)
WHERE empno = apex_application.g_f02 (vrow);
END LOOP;
END;
The easiest way to debug is to use:
1. Firefox
2. Firebug
Activate the firebug and use the HTML option to go over the elements (columns) in your tabular form. Firebug will show the associated array number and you can use that information to correct you code.
Subscribe to:
Comments (Atom)












