Friday, April 19, 2013


Dynamically Clean up the target Oracle DB

  1. This job will call a main script. This script will first call a pre-defiend SQL file by replacing the proper DB USERNAME.
    SPOOL /home/tmp/drop.sql
    select 'drop table '||owner ||'.'||table_name||' cascade constraint;' as LBL_SCRIPT from all_tables where owner = upper('#_dbuser_#');
    select 'drop sequence '||sequence_owner||'.'||sequence_name||';' as LBL_SCRIPT from all_sequences where sequence_owner = upper('#_dbuser_#');
    select 'drop PROCEDURE '||object_name||';' as LBL_SCRIPT from ALL_OBJECTS where OWNER = upper('#_dbuser_#') and OBJECT_TYPE IN ('PROCEDURE');
    select 'drop FUNCTION '||object_name||';' as LBL_SCRIPT from ALL_OBJECTS where OWNER = upper('#_dbuser_#') and OBJECT_TYPE IN ('FUNCTION');
    SPOOL OFF
    exit
  2. The script will then try to select out the table,sequence,procedure and function from the target DB and paste it into a sql file by executing the SQL file in previous step.
    #########################################
    #  generate the drop script for existing db
    #########################################
    function generate_drop_script
    {
        echo "generate the drop script"
        sqlplus $dbuser/$dbpassword@ORCL @$gropFile
        echo "remove unwanted lines int the drop script"
        sed -i -e 's/[0-9]*.*row.*//ig' $finalDropFile
        sed -i -e 's/LBL_SCRIPT//g' $finalDropFile
        echo "append exit command to the drop script"
        echo "exit;" >> $finalDropFile
    }
  3. The script will remove those unwanted characters/words from the generated sql file in previous step.
  4. Execute the generated sql file to clean up the DB.

Remotely run the dump file for Oracle

When we have TWO servers
  1. server 1 (client server )
    • Platform - Linux Ret Hat
    • Oracle - Client
  2. server 2 (host server - the target server host the DB) - Linux Ret Hat
    • Platform - Linux Ret Hat
    • Oracle - Full Version
The following are the suggested steps to achieve this.
  1. Ensure the client server's Oracle Client is Administrator Type. If not, please do re-run the runInstaller
  2. This to ensure the Oracle Client provide 'import' and 'export' services.
  3. Add the host server IP into client server's
    • File name - host.allow
      • E.g: /etc/host.allow
      • Line to be added -> nfs: 10.116.1.123
    • File name - hosts
      • E.g: /etc/hosts
      • 10.116.1.123 ORCL dbmain.company.com
  4. Both server need to start the following services
    • portmap
    • netfs
    • nfs
    • E.g : $ /sbin/service nfs start
  5. Add the following line into file etc/exports
    /home linux(rw,sync) linuxd600(rw,sync)
    /u01 10.116.1.123(rw,sync)
  6. Must define the database address for establishing connection instead of pure text such as :-
    $ imp host_user/host.com@'(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST='$DB_HOST')(PORT='$DB_PORT')))(CONNECT_DATA=(SID='$DB_SID')))' FILE=/get/dump/file/directory/dbdump.dmp FULL=y
    • Please define it in tnsnames.ora file E.g: /u01/app/oracle/product/11.2.0/client_1/network/admin/tnsnames.ora
      ORCL=
        (DESCRIPTION =
          (ADDRESS_LIST =
            (ADDRESS = (PROTOCOL = TCP)(HOST = dbmain.company.com)(PORT = 1521))
          )
          (CONNECT_DATA =
            (SID = orcl)
          )
        )
    • No need to restart listener as Oracle Client do not have such services being installed.
  7. Set the proper environment variables
    $ export ORACLE_HOME=/u01/app/oracle/product/11.2.0/client_1
    $ PATH=$PATH:$ORACLE_HOME/bin
    $ LD_LIBRARY_PATH=$ORACLE_HOME/lib:/usr/lib; export LD_LIBRARY_PATH
    $ export CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib
  8. Now is the time to execute the dump file.
    $ imp cnm_developerX/password@ORCL FILE=/get/dump/file/directory/dbdump.dmp FULL=y

Wednesday, February 20, 2013


Oracle SQL update and select for one table


UPDATE Table1 T1 SET
T1.name = (SELECT T2.name FROM Table2 T2 WHERE T2.id = T1.id),
T1.desc = (SELECT T2.desc FROM Table2 T2 WHERE T2.id = T1.id)
WHERE T1.id IN (SELECT T2.id FROM Table2 T2 WHERE T2.id = T1.id);

Wednesday, February 22, 2012

[MYSQL]update concate ignore null

update user_ set
screenName=concat(firstName,IFNULL(lastName, ""))

Wednesday, February 15, 2012

[JAVA] date time comparison

Date date2 = obj.getEndDate();
Date today = new Date();
int results = today.compareTo( date2 );
if ( !( results < 0 ) ) {
throw new IllegalException( " Expired!!!!" );
}

Monday, February 13, 2012

CSS Div Word Wrap


<html>
<head><title></title>
<style type="text/css">
.wrap_div{
white-space: pre; /* CSS 2.0 */
white-space: pre-wrap; /* CSS 2.1 */
white-space: pre-line; /* CSS 3.0 */
white-space: -pre-wrap; /* Opera 4-6 */
white-space: -o-pre-wrap; /* Opera 7 */
white-space: -moz-pre-wrap; /* Mozilla */
white-space: -hp-pre-wrap; /* HP Printers */
word-wrap: break-word; /* IE 5+ */
}
</style>
</head>
<body>
<div style="width:180px;height:154px;border:1px solid red; ">test</div>
<div style="width:180px;height:154px;word-wrap: break-word;white-space: wrap;">
<div style="width:180px;height:154px;float:left;">
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
</div>
</div>
===========

<div style="width:100px;"class="wrap_div">
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
</div>

</body>
</html>

Sunday, December 18, 2011

Wedding Preparation

These are some outstanding stuff that I want to share about my wedding preparation experience. Until the final week only then I realized the most important thing to a bridal is to only choose the best one you love to have it. Because the most happiest thing for a gal is to wear the wedding gown that she loves and to have the wedding that she needs only then consider it is the beginning of a happiness marriage.

I found that it may lead me to a regret in my life if I only listen to others opinions, such as

Wedding preparation is really a tiring process. Summary :-

  1. Wedding date
  2. Restaurant
  3. Slimming
  4. Official Discussion About Married (Ti Qin, 提親)
  5. Chinese Custom Present (Guo Da Li, 過大禮)
  6. Photo Shooting with Album
  7. Photo Shooting on Actual Day
  8. Dai Kam on Actual Day
  9. Make Up artist for bride, groom, bride's maid, mother, mother-in-law
  10. Flower wrapping for car
  11. Bridal bouquets
  12. Corsage for sisters, brothers, groom, mothers and fathers.
  13. Decorations at home

For the past 3 months, we have made several important decisions like choosing the wedding date, restaurant, bridal package, photoshooting venue, ROM date, decorate the bridal room, gor dai lai, bridal car deco, guest list, wedding eve buffet, etc etc.

I am hereby share my experience for some of the items in details:-

  1. Wedding date
    • Depends on how traditional for both families, it is advised to be plan at least 1 year as buffer.
  2. Restaurant
    • It is advised to be chosen and booked at least 1 year as ahead by providing around RM1k as deposit.
    • Please do check what kind of services they do provide to you, such as:-
      • Do they provide simple decoration with groom and bridal name on stage?
      • Do they provide at least one projector to project photos/slide show?
      • Do they organize the sequence of the whole session by providing the flexibilities on changes?
      • Do they provide sound system for playing music?
      • Do they provide MC?
      • How many free invitations card (usually 80% - more than enough as we will be inviting couple) provided? When can be ready?
      • Do they provide banner to display the photo of couple in front of entrance?
      • Don't scare of not enough tables, people do not attending on that day with whatever reasons, restaurant will spare 3 to 5 tables for you (open only need to pay). It is advised to order less tables after you finalized your guest list by utilizing the spare tables. E.g. if you finalized 30 tables (they provide spare 3), then you just order 28 tables.
      • Please do not shy to ask whether people come to attend or not, as a real friends who really wish you happiness will not mind to arrange the time for you. Please do ask their attendance confirmation to finalized the seats.
      • When they able to provide a food test, what kind of dishes are ready to be chosen for adjustment, are they really able to provide the 'exact' dishes and utensils on testing day (as what u eat and see are the same on actual day)?
    • Different location/states providing services differently so you might need to ask all the services and the charges.
    • I had experienced with 2 states with 2 different arrangement and services.
    • Peikin Johor Jaya Restaurant, JB, Johor.
      • Good experience as they provide 2 projectors mounted on ceiling, sequence for whole process, spot light when couple stepped into the hall, sound system, banner at entrance, signature guest book, decoration with names on stage, all these were free. (maybe included in the tables package but you are free of hassle)
      • They do provide 3 spare tables when you order 25 tables, i believe if you order 50 tables will spare 5 tables.
      • They do call you to follow up every single things such as choosing the menu packages, verification on invitation card, banner, etc.
      • 3 months before our wedding date, they provide us to test the foods and exactly same as that day.
      • Even though, end up i had 7 empty tables, they do provide flexibilities for us to make changes. Such as 4 tables combine to be 1 table to enjoy Fo tiao qiang,(Steamed Abalone with Shark's Fin and Fish Maw)- 佛跳墙 plus few new dishes with expensive ingredients.
      • Foods excellent as we even decide to choose this restaurant to celebrate my father's birthday.
      • No regret for a happy marriage ^^

    • XX Restaurant Melaka.
      • BAD experience as they don't provide any projectors, sequence for whole process, spot light when couple stepped into the hall, banner at entrance, signature guest book, decoration with names on stage (basic things), (maybe not included in the tables package but you are full of hassle)
      • You need to arrange the above with another persons if you really need these. (i think you have to as no basic name decoration provided on stage @@)
      • They do provide 2 spare tables ONLY when you order 50 tables.
      • They do NOT call you to follow up every single things such as choosing the menu packages, verification on invitation card, etc.
      • We need to follow up with them (serve them instead of they serving us), to push them to print the invitation cards.
      • 2 WEEKS before our wedding date, they ONLY provide us to test the foods - i) Use the ugly steel utensil to serve you one of the cuisine and told you that ON THAT DAY will use another pretty one (i was thinking how pretty was that? hmm....use your imagination) (ii) Inform us the last cuisine of dessert was not available to be tested and serve you the ICE CREAM (iii) super limited dishes for you to change or even make adjustment ( hmm....i was thinking the testing seem meaningless, u just follow the menu will do)
      • Overall, personal preferences, the food really not that nice, service also not good. Heaven and ground by comparing to other states.
      • You might end up with unhappiness with such a happy event .......
      ..............................to be continued