Friday, February 22, 2019

Oracle: trim, ltrim, and rtrim functions; remove spaces and chars from ends of a string

ltrim: trims a string from the left end.
rtrim: trims a string from the right end.
trim: trims a string from both ends.

By default, they trim the empty spaces away from the ends if you don't specify any particular characters to trim.

For example, you have a string: abcdedcba

      select trim('   abcdedcba ') as st from dual;    or
      select ltrim('   abcdedcba') as st from dual;    or
      select rtrim('abcdedcba   ') as st from dual;    or

       returns :
ST
---------
abcdedcba

To remove the left 'a' of the string:

          select ltrim('abcdedcba', 'a') from dual;

To remove the left 'abc' from the string:

          select ltrim('abcdedcba', 'abc') from dual;
          select ltrim('abcdedcba', 'cba') from dual;
          select ltrim('abcdedcba', 'bca') from dual;

To remove the right 'a' from the string:

          select rtrim('abcdedcba', 'a') from dual;

To remove the right 'ba' from the string:

             select rtrim('abcdedcba', 'ab') from dual;
             select rtrim('abcdedcba', 'ba') from dual;

To remove the 'a' from both ends:

           select trim('abcdedcba', 'a') from dual;

To remove the 'ab' from the left and the 'ba' from the right end:

           select trim('abcdedcba', 'ab') from dual;
           select trim('abcdedcba', 'ba') from dual;

 -----------------------------------------------------------------------------------------------------------------
Watch the blessing and loving online channel: SupremeMasterTV live




If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book for free here.

 
          

Wednesday, February 20, 2019

Solved - CrystalReports: convert Julian date to MM/dd/yyyy format

Say you have a date in Julian format, 2012003, in your database, and you want to display it in a MM/dd/yyyy format in your crystal report.

You pass the Julian date as a startDate parameter to your crystal report.

This is how you convert it into the MM/dd/yyyy format.

          if (length(totext({?startDate})) > 3)
                 DateSerial(truncate({?startDate} / 1000), 1, 1) + ({?startDate} Mod 1000) - 1

 -----------------------------------------------------------------------------------------------------------------
Watch the blessing and loving online channel: SupremeMasterTV live




If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book for free here.


Solved - ORA-28002: the password will expire within 2 days

To fix this error, you can either reset your password or make your password permanent that never expires.

1. Reset your password

          alter user <username> identified by <password>;

2. Make your password permanent

2.1 Find your profile

           select profile from dba_users where username='<username>';

2.2 Alter your password limit

           alter profile <profile name> limit password_life_time unlimited;

 -----------------------------------------------------------------------------------------------------------------
Watch the blessing and loving online channel: SupremeMasterTV live




If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book for free here.

Thursday, February 7, 2019

Thread concurrency: wait() and notify() / IllegalMonitorStateException

When a thread enters a synchronized block, it acquired the lock and becomes the owner of the lock. For example, if you have multiple threads reading from a queue, you do synchronized (queue) and the queue becomes the lock. Once thread T1 enters this synchronized block, it owns the queue lock.

Now, the queue is empty and there is nothing to read, so you want thread T1 to wait until the queue has something. The odd thing is that you cannot call T1.wait() or Thread.currentThread.wait() which will throw an IllegalMonitorStateException. Instead you call queue.wait(), which puts your thread into a Waiting state and makes it release the queue lock.

    synchronized (queue) {
         try {
                while(queue.isEmpty()){
                       queue.wait();
                 }
         } catch (InterruptedException e) {
                 System.out.println("Reader is waking up!");
         }

          Object value = queue.poll();
    }

Similarly, you have to call queue.notify() to change a Waiting thread into a Runnable one.

    synchronized (queue) {
          queue.add(obj);
           queue.notify()
    }

Rule of Thumb: Never use the wait() method together with nested synchronized blocks! A wait() call only releases one lock, and the thread enters the Waiting state holding the other lock, which is prone to deadlock.

When you use synchronized method, the object "this" is the lock. You may call this.wait() or just wait() in the synchronized method to make the thread go to the Waiting state and release the lock. And this.notify() will make a Waiting thread Runnable.

 -----------------------------------------------------------------------------------------------------------------
Watch the blessing and loving online channel: SupremeMasterTV live




If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book for free here.