Quick tips

Oracle – Escaping character ‘_’ in LIKE clause

How should you know, underline(‘_’), in LIKE, is considered a wildcard that means “any character”. Query will replace underline by any other character where ‘_’ is.

Following table bellow:

+---------+
|  WORD   |
+---------+
| COLUMN  |
+---------+
| BEE     |
| SEE     |
| FEE     |
| SHE     |
| _EE     |
+---------+

And running

select column from word where column LIKE '_EE';

Results

+---------+
| COLUMN  |
+---------+
| BEE     |
| SEE     |
| FEE     |
| _EE     |
+---------+

Besides “_EE“, expected initially, “BEE“, “SEE” and “FEE” has been returned.

We have to use escape after LIKE to include ‘_’ at the search. Escape needs a character to transform it in a wildcard that ignores the next one, thus, the new wildcard should be added before ‘_’, like this.

select column from word where column LIKE '\_EE' escape '\';

Now, the result will be:

+---------+
| COLUMN  |
+---------+
| _EE     |
+---------+

I hope this helps some one else! 🙂


A easy way to compile many objects in Oracle database

When compiles an object that is referenced by many others, they stay invalidated until Oracle compile they again and sometimes it fails.

So, here’s a tip to compile several invalid packages, procedures and/or functions and fix this.

There is a command to compile all invalid objects under an user, the command is:

exec dbms_ultility.compile_schema(<USER>)

Replace  <USER> for user, or for user name where invalid objects are.

This command is slow and not compiles objects invalidated by coding error. To find which are invalid you need runs the query below:

select object_name
from all_objects
where status = 'INVALID'

Invalid objects will be listed.


Why to use File.separator and File.pathSeparator

Java programmers knows about methods quoted in title, but many doesn’t care with them.

These methods are useful for programmer that do not knows wich characters represents file separator and path separator at OS that supports your application.

Linux/Unix, the methods File.separator and File.pathSeparator returns “/” and “.”, while in Windows, these methods returns “\” (or “\\” – escape) and “;”.

In recent case, the code below threw exception FileNotFoundException running over Linux, but not running over Windows:

String appPath = ctx.getRealPath();
String filePath = appPath + "\\" + "WEB-INF/classes/my/application/packages/";

File file = new File(filePath, "report.pdf");
OutputStream out = new FileOutputStream(file);
...

Worked in both systems after to replace “\\” by File.separator in line 2:

String appPath = ctx.getRealPath();
String filePath = appPath + File.separator + "WEB-INF/classes/my/application/packages/";

File file = new File(filePath, "report.pdf");
OutputStream out = new FileOutputStream(file);
...

Utilization of these methods, besides a good practice, is very usefull when same version of an application is running over differents operacional systems.


Fixing WordPress error “Allowed memory size of…”

I’ve just updated my WordPress to version 3.2, when update has been finished a page with error code 500 was displayed. In log file had many entry of Fatal error: Allowed memory size of 33554432 bytes exhausted

To know if it your problem too, edit file error_log in wp-admin directory and and take a look at last rows.

The following process fixed this for me, but your host server should allow sizing PHP memory at runtime.

Open and edit file wp-settings.php at root of WordPress directory and put the row bellow after “<?php”:

define('WP_MEMORY_LIMIT', '64M');

Here I’ve set up to 64MB to PHP, but how to know amount of MB to set up?

In error message, the long number means amount of bytes allocated to PHP: “Fatal error: Allowed memory size of 33554432…”. This number represents 32MB (do this calculation to converts byte in megabytes 33554432 / (1024^2) = 32).

Just set a number greater than the result in line above.


Installing .apk packages at Android SDK emulator

Sometimes our applications depends of third-part applications for tests or to access resources of emulator that aren’t available by default.

In directories of SDK, commonly in platform-tools, there is an executable called adb, with it we’ll to install third-part applications.

You will need an application (.apk). Browse internet or copy from your Android smartphone using applications like AppSaver.

– Run the emulator, you can use SDK Manager or Eclipse plugins.

– Using DOS Command (Windows) or terminal (Linux), open directory platform-tools and run commando line below:

$ adb install <.apk path>

This message will be displayed

$ adb install Application.apk
125 KB/s (1091937 bytes in 8.474s)
        pkg: /data/local/tmp/Application.apk
Success

Now, the third-part application is available at emulator menu, like have installed in your smartphone.

Agora o aplicativo estará disponível no menu do emulador. 😉

 


  • Advertisement

  • Advertisement

  • Copyright © 1996-2010 André L. S.. All rights reserved.
    iDream theme by Templates Next | Powered by WordPress