Oracle: quotes and quote operator

There are several methods to put the quote into the string.

The first (and very traditional) one: use 2 quotes.
[cc lang=”oracle8″]
select ‘This ” is quote’ from dual;
[/cc]
If there are more than one quote, it’s difficult to read and write such strings

The second: use chr(39)
[cc lang=”oracle8″]
select ‘This ‘ || chr(39) || ‘ is quote’ from dual;
[/cc]

The third: put the quote into the variable
[cc lang=”oracle8″]
declare
s_quote varchar2(1) := ”” ;
begin
dbms_output.put_line(‘This ‘ || s_quote || ‘ is quote’ ) ;
end;
[/cc]

And, finally, Oracle 10g has added new feature: quote operator.
[cc lang=”oracle8″]
select q'[This ‘ is quote]’ from dual ;
[/cc]

The general form is q’X string X’. Here X is just some character. If the brackets are used, Oracle expects the closing bracket for the end of the string.

Here are the additional examples:
[cc lang=”oracle8″]
select q'(This ‘ is quote)’ from dual ;
select q’|This ‘ is quote|’ from dual ;
select q’#This ‘ is quote#’ from dual ;
select q’#This ‘ is quote#’ from dual ;
select q’?This ‘ is quote?’ from dual ;
select q’TThis ‘ is quoteT’ from dual ;
[/cc]

Oracle: problem relinking binaries on Solaris

I’ve got the following message relinking the binaries on Solaris:

ld: fatal: dlopen() of support library (libmakestate.so.1) failed with error:

ld.so.1: /usr/ccs/bin/sparcv9/ld: fatal: /usr/lib/libmakestate.so.1: wrong ELF class: ELFCLASS32

The problem was caused by missing 64-bit library libmakestate.so.1 in /usr/lib.

The normal library should look like the following:

[#] file /usr/lib/sparcv9/libmakestate.so.1
libmakestate.so.1: ELF 64-bit MSB dynamic lib SPARCV9 Version 1, dynamically linked, not stripped


If the library does not exist or is incorrect, it should be reinstalled from the package SUNWsprox ( Sun WorkShop Bundled 64-bit make library)

This command checks, if the package is installed in the system:
[#]  pkginfo -i SUNWsprox

After installing the package relink works fine.

PDF file: set the bookmark

Strange enough, Adobe Acrobar Reader does not allow to put the user-defined bookmarks into the PDF file (and this is so simple and necessary thing!)

However, with the help of some “hack” the bookmarks still could be used.

Here is the trick:

  1. Go to PDF Hacks site and download the zip file with the javascript.
  2. Extract the file bookmark_page.js from the archive
  3. Copy the file bookmark_page.js to one of the following folders:
    • %ProgramFiles%\Adobe\Reader\Javascripts
    • %AppData%\Adobe\Reader\Javascripts

    Please, check the real installation path of the Acrobat software, it could be different on Your system.

  4. Restart the Acrobat Reader

Now You have 4 new menu items in the menu “View”. The first two could be called using shortcut “Alt-V-5” and “Alt-V-6” (for English version of Acrobat)
Bookmarks in PDF

The bookmarks are not saved in the PDF itself, so they could be lost, if the PDF file is moved to some other location.

To uninstall the bookmark script, just remove bookmark_page.js from the Javascripts folder and restart the Acrobat Reader.

Some other PDF tricks could be found in this book:
[amazon-product]0596006551[/amazon-product]

Java: minimize Application window

The following method could be used to minimize application window, if java.awt.Frame or its subclass is used:

public void setState(int state)
Parameters:
state – Frame.ICONIFIED if this frame is in iconic state;
Frame.NORMAL if this frame is in normal state.

Example:

// Close window on ESC
// use it in the constructor of the window, extending JFrame
//
KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
rootPane.registerKeyboardAction(new ActionListener() {
public void actionPerformed(ActionEvent e) {
setState(Frame.ICONIFIED);
}
} , stroke, JComponent.WHEN_IN_FOCUSED_WINDOW);

Oracle: eval function

The function takes some expression as the argument and executes it, returning output in the varchar string


create or replace function eval (expr varchar2) return varchar2
as
ret varchar2(4000);
begin
execute immediate 'begin :result := ' || expr || '; end;' using out ret;
return ret;
end;
/

The discussion and examples could be found there

[amazon-product]1590599683[/amazon-product]

Oracle: list of the system events

This piece of code show the list of events, set in the Oracle database


set serveroutput on
declare
event_level number;
begin
dbms_output.enable(20000) ;
for i in 10000..33999 loop
sys.dbms_system.read_ev(i,event_level);
if (event_level > 0) then
dbms_output.put_line('Event '||to_char(i)||' set at level '||
to_char(event_level));
end if;
end loop;
end;