UTF_FILE and Directories

In case you are maintaining a pl/sql program developed by someone else and that program writes into a file, then basically that file is written to a folder/directory. And since the directories are saved in codes, you have to find the meaning (or location) of those codes. The code below will help you display the information required.

SELECT * FROM ALL_DIRECTORIES;

The query above will display all the directories accessible to the current user. They are folders in the server where you can write your output files. For some reason, I forgot about this twice already and had to scour the web to find it. The problem is, I also forgot the keywords. So, I’m writing it now.

To register new directories, you can follow the example below.

Example
create or replace directory mydir as 'c:\mydirectory';

To use, run the code below.

declare
f utl_file.file_type;
begin
f := utl_file.fopen('MYDIR', 'myfilename.txt', 'w');
utl_file.put_line(f, 'just another line text 1');
utl_file.put_line(f, 'just another line text 2');
utl_file.fclose(f);
end;

Blogging in the Train

With limited time and a couple of blogs at hand, posting regularly becomes a challenge. Aggravated by more work at your day job makes it more difficult. You need to be creative to be able to cope up with this kind of challenging situation. We need to balance our work life, blogging life, and of course our own life.

And one particular technique that I’ve been implementing is blogging while traveling and in my idle time while not at the office or at the comfort of home and internet connection. It feels the gap and make a rather dull travel into something useful.

Benefits

  • Make Time More Useful- while in the train, you don’t have to just count the number of people
    getting in and out of the train. And you can sit down in a corner blogging while your wife is shopping!
  • Keep Tabs on Idea-especially important when something interesting
    crops up while daydreaming inside the train or something happens interesting and worth blogging.

Disadvantages

  • No Sleeping-but you can always skip blogging if you really need to.
  • It’s another manifestation that you are a blog addict!
  • It’s another way to annoy your wife/gf.

Tools to Use

I’m currently using gmail for mobile on a N73 phone. It serves me well as I can email the post directly. However, any text editor available on your phone serves just as well. So any smartphone or pda is suitable.

RowIdToRowIdNum Oracle Function

I’m not exactly sure if there’s an existing function in Oracle to convert ROW_ID into a Row_ID Number format. I already know the formula so I created a function. I’ve been using it for a project numerous times so I needed to create this reusable function.


CREATE OR REPLACE FUNCTION SH_RowIdToRowIdNum(v_rowid VARCHAR2) RETURN VARCHAR2
IS
v_pre VARCHAR2(30):='';
v_series VARCHAR2(30):='';
iCtr INTEGER:=0;
v_char VARCHAR2(1):='';
i_val INTEGER:=0;
i_Sum INTEGER:=0;
v_RowNum VARCHAR2(30):='';
BEGIN

v_series := SUBSTR(v_rowid,instr(v_rowid,'-')+1);
FOR iCtr IN 1..LENGTH(v_series)
LOOP
v_char := SUBSTR(v_series,iCtr*-1,1);

IF INSTR('0123456789',v_char) > 0 THEN
i_val := v_char;
ELSE
i_val := ASCII(v_char)-55;
END IF;
i_Sum := i_Sum + (i_val * power(36, iCtr-1));

END LOOP;
v_RowNum := SUBSTR(v_rowid,1,INSTR(v_rowid,'-')) || i_Sum;
RETURN v_RowNum;
END;

sample usage

SELECT SH_RowIdToRowIdNum('1-5GYG0'), SH_RowIdToRowIdNum('1-IB79I')
FROM dual

output

1-9189216 1-30755718

Reference:

http://onlysiebel.blogspot.com/2009/10/what-is-row-id.html

Oracle Power Function

There are some pl/sql functions that you rarely use and we always forget the syntax.And here’s another example — the power function. You know, that’s the n to the power of x (n^x). Again, I feel a bit ashamed for forgetting this one. Here’s the syntax.
[Read more...]

Samsung Galaxy S II Office365 ActiveSynch Problem [SOLVED]

I just extended my mobile contract with StarHub and since I was given a $100 voucher, I chose Samsung Galaxy S II as my new phone. I didn’t have any plans of getting a new phone but with my HTC Desire acting up lately and a voucher from StarHub, I was somehow ‘forced’ to extend my plan.

Samsung Galaxy S II is one fine smartphone. There are little problems here and there which was brought about by unfamiliarity with a new Android skin but overall, I’m very impressed with this phone. However, there’s one problem that I can’t solve which is setting up the ActiveSync to my Office365 email. Usually, the setting is as simple as below

Email Address : myemail.addr@mycompany.com
Password : MyPassWord%*&
Domain User : myloginid@mycompany.com
Server : m.outlook.com
Use SSL : Checked

I tried to use this in my brand new phone but it can’t connect to the server. I double-checked the settings and made sure that it was the same with that of my HTC Desire but the error is still the same. So after googling, I realized that it’s a common problem. As it turns out, the server name m.outlook.com no longer works with Samsung Galaxy S II. you have to change it to what exactly your Office365 is residing. But how? Here you go.

1. Login to your Office365 email via OWA. In case you don’t know, the URL is http://outlook.com/owa/mycompany.com

2. From the top-right pull-down menu Options, click on “See All Options”.

3. From the account, click on “Settings for POP, IMAP and SMTP address..”

And then you’ll get your server. So now, you’ll have the following settings
Email Address : myemail.addr@mycompany.com
Password : MyPassWord%*&
Domain User : myloginid@mycompany.com
Server : pod502212.outlook.com
Use SSL : Checked

As I have said, m.outlook.com is working on my HTC Desire which is still on Froyo. I guess something broke with the Gingerbread release or maybe, it’s just the Samsung Galaxy S II that has this problem.

Rowcount on Oracle Dynamic SQLs

A good friend asked me on how to capture the number of affected records on his delete statement. The answer would be as

simple as below:

DELETE FROM my_table
WHERE mycolumn = 'mysearch';

v_rec_count := SQL%ROWCOUNT;

On this case, SQL%ROWCOUNT will return the number of affected records in the immediate preceding statement. It is the

equivalent command for @@rowcount in Sybase/SQL Server.

However in my friend’s case, the DELETE statement is part of the dynamic SQL. Obviously, we cannot use the approach

above as it is. Here’s how to capture the affected records in dynamic SQLs.


vSQL := 'DELETE FROM ' || v_SchemaName || '.' || v_TableName || ' WHERE ' || v_Conditions || ‘;’;
EXECUTE IMMEDIATE ‘BEGIN ’ || vSQL || ‘ :z := sql%rowcount; END; ’ USING OUT nRecCount ;

Basically, we have to capture the rowcount from within the dynamic sql. That means you have to pass the variable via “OUT” parameter to flow the value out of the execute immediate. You can’t just fire nRecCount := sql%rowcount after the execute immediate because with that, the last command that ran is the execute immediate. It will return 1 instead of the actual value from the dynamic sql.

Source :

https://asktom.oracle.com/pls/asktom/f?p=100:11:0::NO::P11_QUESTION_ID:497908700346519628

How To Install Setacl in Linux

First, there’s no setacl in Linux. Instead, it has setfacl. Take note of the f. Second, setfacl is part of the access control list(acl) package so we install the acl intead of setfacl. In that way, we also install getfacl.
[Read more...]

How to Upgrade MySQL 5.0 to 5.5 in CentOS

I upgraded the installed MySQL on my two VPSes about two months ago and I thought I already saved the steps somewhere or at least the saved the URL of the how to. I did not so when I tried to upgrade the Pagudpud Resort‘s (owned by the Jackoleros) database server, I don’t know where to start. The MySQL official website suggests(or at least, that’s how I understand it) that I recompile. I know I did not recompile before so after some fruitless googling, I finally found a working version. But first, thanks to remi for sharing the rpm.
[Read more...]

LAMP Install on VPS : CentOS5+Apache+MySQL+suPHP

Here’s the work-in-progress instructions for setting up a LAMP. It’s been sitting on my draft for ages and I have to publish it because a few of my friends need it.

**** NOTE : If you notice, it’s still a draft. It came from a number of sources but these are the steps I use. So I know it works. **********

[Read more...]

Apache Cannot Allocate Memory Problem

For the past month, I have been encountering some problems with my WordPress installation. I keep getting the Error 500. I checked the log files and here’s what I found.
(12)Cannot allocate memory: couldn't create child process: /opt/suphp/sbin/suphp for
[Read more...]