Total Pageviews

2014/08/18

Oracle Reserved Word: UID

Problem
Assume we would like to retrieve information from UAA001V1 (Oracle database view). Here has its schema.

We can utilize this SQL statement to retrieve all information (including all column) : 
SELECT *
FROM UAA001V1;
Here is the result:

But if I would like to retrieve UID column only:
SELECT UID
FROM UAA001V1;
Then it will show 84, WHY?

Root Cause & Soltion
Owing to UID is reserved word for Oralce, so it will mislead Oracle returns an integer that uniquely identifies the session user (the user who logged on). That's why it return 84 this weird integer.

What we need to do is to add double quote before and after UID as following:
SELECT "UID"
FROM UAA001V1;
Then we can get the expected outcome:


Reference
[1] http://docs.oracle.com/cd/B19306_01/em.102/b40103/app_oracle_reserved_words.htm
[2] http://docs.oracle.com/cd/B12037_01/server.101/b10759/functions188.htm

2014/08/12

java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal result

Problem
As I execute the following code snippet
   public static void main(String args[]) {  
     BigDecimal one = new BigDecimal(1);  
     BigDecimal two = new BigDecimal(2);  
     BigDecimal three = new BigDecimal(3);  
     System.out.println(one.divide(two));  
     System.out.println(one.divide(three));  
   }  

The console showed:
0.5  
 Exception in thread "main" java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal result.  
      at java.math.BigDecimal.divide(BigDecimal.java:1616)  
      at gov.nta.fms.web.rest.Fms421rResource.main(Fms421rResource.java:204)  

Why one.divide(two) is working fine?  But failed to execute one.divide(three) ?

Root Cause
Because I am not specifying a precision and a rounding-mode. 
BigDecimal is complaining that it could use 10, 20, 5000, or infinity decimal places, so it cannot be able to show me the exact representation of the number.

We need to assign its scale and rounding mode, please check the following code snippets:
   public static void main(String args[]) {  
     BigDecimal one = new BigDecimal(1);  
     BigDecimal two = new BigDecimal(2);  
     BigDecimal three = new BigDecimal(3);  
     System.out.println(one.divide(two));  
     System.out.println(one.divide(three, 2, BigDecimal.ROUND_HALF_UP));  
   }  


Here is java doc:
The console showed:
 0.5  
 0.33  

Reference
[1] http://docs.oracle.com/javase/7/docs/api/java/math/BigDecimal.html#divide(java.math.BigDecimal,%20int,%20int)

2014/07/29

四項成功選股原則

筆記一下漫步華爾街一書提到的四項成功選股原則:

  • 只購買至少維持五年盈餘成長超過平均的股票

  • 不購買股價高於合理價值的股票
    • 透過本益比來判斷,目前價格是否超過其價值。作者不斷強調,只要買進本益比低,就算成長未實現且盈餘下跌,損失也有限;但是如果預測成真,就可以賺錢,藉此增加勝算
  • 購買有故事題材的股票
    • 如iPhone概念股、雲端概念股等等
  • 盡可能減少進出
    • 頻繁進出股市者,平均來說獲利率都偏低,但是記得要汰弱留強。
    • 投資普通股票和債券的持有期越長,風險就越低,但是你得有耐性忍受過程中,投資價值逐年波動的情形

2014/07/27

2014/07 Travel

石碇千島湖


石碇雲海國小


基隆八斗子忘憂谷

基隆八斗子忘憂谷

2014/07/11

[iReport] How to format text style in text field

Requirement
The first row in this report, the report name will be appended "總預算\n" before report name. And "總預算" should be bold font. 


Solution
Step 1. Set Text Field Expression

Step 2. Set properties Markup = styled for this text field.

Reference



[iReport] How to apply conditional formatting to your text fields

Requirement
In iReport, I wish to apply different formats to my text fields based on different conditions. For instance, when "融資項目別"== "特別預算" then the font should be bold font.

Solution
You can apply "Conditional Styles" to fulfill this requirement.
Step1. Add new Style

Step2. Add new Conditional Style

Step3. Edit Condition Expression

Step4. Set Bold attribute to be true

Step5. Select text fields and apply this style

Step6. Test


Reference
[1] http://community.jaspersoft.com/wiki/how-apply-conditional-formatting-your-text-fields

2014/07/08

ORA-30926: unable to get a stable set of rows in the source tables when Merging tables

Problem
When I executed the merge SQL statement in my web application
MERGE INTO FMS434FB T1 USING
  (SELECT ACCYR AS ACCYR,
          MONTH AS MONTH,
          ASP AS ASP,
          AMT7,
          AMT9,
          AMT7+AMT9 AS ACC_AMT9
   FROM FMS434FB
   WHERE ACCYR||MONTH = :LAST_YYY_MM) T2 ON(T1.ACCYR||T1.MONTH = :YYY_MM
   AND T1.ASP=T2.ASP) WHEN MATCHED THEN
UPDATE
SET T1.AMT7 = T2.ACC_AMT9

It throw this exception
1:  Caused by: java.sql.SQLException: ORA-30926: unable to get a stable set of rows in the source tables when Merging tables  
2:       at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:447) ~[oracle.jdbc-11.2.0.4-java-6.jar:11.2.0.3.0]  
3:       at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:396) ~[oracle.jdbc-11.2.0.4-java-6.jar:11.2.0.3.0]  
4:       at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:951) ~[oracle.jdbc-11.2.0.4-java-6.jar:11.2.0.3.0]  
5:       at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:513) ~[oracle.jdbc-11.2.0.4-java-6.jar:11.2.0.3.0]  
6:       at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:227) ~[oracle.jdbc-11.2.0.4-java-6.jar:11.2.0.3.0]  
7:       at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:531) ~[oracle.jdbc-11.2.0.4-java-6.jar:11.2.0.3.0]  


Root Cause
ORA-30926 results from the using statement has duplicate data.
Therefore, as I execute this part of SQL statement
SELECT ACCYR AS ACCYR,
       MONTH AS MONTH,
                ASP AS ASP,
                AMT7,
                AMT9,
                AMT7+AMT9 AS ACC_AMT9
FROM FMS434FB
WHERE ACCYR||MONTH = :LAST_YYY_MM
It really has duplicated data !



2014/07/06

本益比的計算

漫步華爾街的作者提到:
選擇低本益比的股票比較好,如果成長實現,將帶來加倍利潤;若成長失敗,損失也有限

本益比計算公式如下

本益比=股價/EPS,所以股價=本益比 * EPS

先到網站上查詢最近五年的最高與最低本益比,算出最高本益比平均最低本益比平均以及平均本益比

再從網站上查詢最近四季的EPS總和

再推算出,當本益比是多少的時候,股價應該落在哪邊

例如本檔股票目前本益比是13.77

若按照目前的本益比,大致落在低本益比此區間,目前股價是27.95,可搭配K線來看進場時機

雖然分析工具很多,但是還是回歸漫步華爾街作者所說的,你無法預測未來成長與盈餘、你也無法有100%可以賺錢的分析工具、你只能降低失敗機率,這樣才能提升你賺錢的機率,故作者建議選擇低本益比的股票,勝算較高

參考資料
[1] http://www.cmoney.tw/finance/f00041.aspx?m=3&s=2034
[2] http://jsjustweb.jihsun.com.tw/z/zc/zca/zca_2034.djhtm
[3] http://www.cnyes.com/twstock/profile/2034.htm