2013年12月6日 星期五

Angular Js Part III : Filter

原本第三篇是要寫Directive自訂控制項或者是Scope的,
但是那些都必須要再整理過,
因此先寫一篇無關痛癢的Filter吧~

Angular Js提供多種Filter可使用。

  • Currency:用來將數字轉換成貨幣
  • Date:轉換成特定日期格式
  • Filter:篩選機制,有點像是AutoComplete
  • Json:將物件轉換成Json字串。
  • limitTo:限制輸出的長度
  • lowercase、uppercase:轉換為大小寫
  • number:轉換為數字格式,並決定小數點後位數。
  • orderBy:排序,超強。

2013年12月3日 星期二

Angular Js Part II : Controller

繼上一篇Start Angularjs之後,
接著要介紹Angular js的另一個特性Controller。
Controller本身能做的事情大概有二:
1.對scope設置初始值(scope泛指應用程式所使用到的物件模型)
2.在scope上增加額外的處置,簡單來說就是寫程式的區塊。
範例一:
給定初始值,input中會有來自controller的文字。
原始碼:
<!DOCTYPE html>
<html ng-app>
  <head>
    <script src="http://code.angularjs.org/1.2.0/angular.min.js"></script>
    <meta charset="utf-8" />
    <script type="text/javascript">
    //Controller
    function urCtrl($scope){
      $scope.urName="it was inited from controller";
    }
    </script>
  </head>
  <body>
    <!-- Smapel ng-controller -->
    <div class="box" ng-controller="urCtrl">
      Sample ng-controller----------------<br>
      Type in ur Name<input name="input" ng-model="urName"><br>
      Hi~ {{urName}}!!!!
    </div>
  </body>
</html>

2013年11月29日 星期五

C# Timer

C# Timer可以提供定期執行特定行為的實作。
而Timer本身的事件即是觸發新的Thread去執行該行為。
MSDN上的範例相當完整,
大家可去實作看看。
這邊提供幾個特定的範例供參考。

2013年11月15日 星期五

Angular Js Part I : Start


Angular js 是一個相當好用的前端開發工具,
之前我在寫html時,
若要即時更新data通常都必須利用JQuery進行DOM元素的抽換,相當不便;
尤其是在一大堆由程式自動產生的表格,更動某筆資料就更費工了。
Angular js所提供的Binding功能,就立刻解決了這一類的需求。
產生的效果如下:
為了達成即時反應的效果,做法有五種。

  • {{modelName}}(表達式)
  • ng-cloak
  • ng-bind
  • ng-bind-template
  • ng-bind-html

2013年10月28日 星期一

Using Java Custom Type In Oracle

因為PL/SQL本身沒有Mutil Thread 機制,
若需要使用到Mutil Thread 就必須利用JVM,
將任務丟給Java並繼續執行下段Statment。

本次的範例為:輸入指定的隊伍人數,JVM會自動產出隊伍成員,且回傳整支隊伍。

Oracle Function :
CREATE OR REPLACE FUNCTION CreatTeam(Num IN NUMBER)
RETURN TEAMWITHPLAYER
AS
tempNum Number;
BEGIN
    FOR i IN 1..Num
    loop
        SELECT  ROUND(DBMS_RANDOM.VALUE(20,30))into tempNum FROM DUAL;
        --addPlayer(姓名、地址、年齡)都採Random輸出
        AddPlayerToTeam.addPlayer('Name A'||i ,'Taipei No.'||i*10,tempNum);
    end loop;
  
    RETURN AddPlayerToTeam.getAll();
END;

上段程式碼為主程式,藉由輸入的Num數產生所成員數目。
最後再傳回整個Team的資料。

Oracle Package
CREATE OR REPLACE PACKAGE AddPlayerToTeam
            IS
              Procedure addPlayer( NameStr IN VARCHAR2 , AddrStr IN VARCHAR2 , AgeStr IN VARCHAR2 );      
              Function getAll Return TEAMWITHPLAYER;
            End AddPlayerToTeam;

CREATE OR REPLACE PACKAGE BODY AddPlayerToTeam
            IS
              Procedure addPlayer( NameStr IN VARCHAR2 , AddrStr IN VARCHAR2 , AgeStr IN VARCHAR2 )  as language java name 'Kunde.Test.Java.AddPlayerToTeam.addString(java.lang.String,java.lang.String,java.lang.String)';
              Function getAll Return TEAMWITHPLAYER as language java name 'Kunde.Test.Java.AddPlayerToTeam.getLog() return oracle.sql.ARRAY';
            End AddPlayerToTeam;

2013年10月14日 星期一

Oracle DB Call Java Class & ORA-29532

參考官方文件:Calling Java Methods in Oracle Database

1.寫了一個test.java,存在D:\Test底下

import java.io.*;
public class test {
   public static void main(String[] args) throws IOException {
   // TODO Auto-generated method stub
   //Hello World!!!!
      System.out.println("Hello World!!!!!!!!!!!");
      BufferedWriter out = new BufferedWriter(new FileWriter("D://output.txt"));
      try {
         String inputLine = "Hello World!!!!!!!!!!!";
         out.write(inputLine);
         out.newLine();
      } catch(IOException e1) {
         System.out.println("Error during reading/writing");
      } finally {
         out.close();
      }
   }
}

2013年10月11日 星期五

First Java Code With Eclipse

痾............為什麼開始寫java呢.................

環境:Windows 8 64 bit

下載並安裝Eclipse。基本上去官網下載即可,然後解壓之後就可以直接使用了。

使用時可以選擇工作區域。

















2013年9月16日 星期一

[Team Foundation Server ] Collection 轉移

若單純想要轉移Collection (project),
MSDN寫得很清楚,
但是我一開始因為有既定的想法,
所以死不照他的做法去做。

以下為必備流程:
1.Detach Collection
從TFS SERVER上面將Collection的鏈結解除,
若不解除,即便轉移到其他的SERVER上,
還是無法附加。
筆者推測是因為該Database有紀錄與其Binding的TFS位置。


2013年9月14日 星期六

Team Foundation Server 轉移

使用Team Foundation Server進行程式的版本控制十分常見,
但若突然想要轉移到其他伺服器又想保留所有紀錄時,
就會變得十分麻煩。
以下稍稍紀錄該注意的事項。
環境:
Windows Server 2012 
Microsoft SQL Server 2012
Microsoft Team Foundation Server 2012

1.在安裝好的Windows Server 安裝 .Net Framework 3.5 
Win Server 2012安裝MS SQL 2012 時,會遇到未安裝.Net Framework 3.5 導致無法完全安裝SQL 2012 ,安裝方法請參考[Windows Server] 在 Windows Server 2012 上安裝 .NET Framework 3.5 ,使用替代方案安裝.Net Framework 3.5

2.依序安裝MS SQL 2012 、TFS 2012
Ps.筆者在安裝MS SQL 2012 時,一直遇到The SQL Server license agreement cannot be located for the selected edition......的問題,結果好像是語系的關係。筆者所用的Windows Server 2012 雖是中文版,但調整呈現語系為英文,解決方法請參考Sql Server 2012 Installation 使用英文MSSQL 2012 安裝即可。

3.使用進階設定TFS 2012,讓新的TFS擁有自己的設定檔,並確定TFS已可使用;接著在TFS上移除功能。使得應用程式層的功能處於未設定。

2013年9月10日 星期二

Linux yum 設定與安裝套件

參考:
How-To:用 yum 進行軟體安裝移除與更新

Yum基本操作:
使用yum可以比較簡易的安裝Linux所需的套件,
yum 會自動下載相依的套件並安裝,
以安裝VNC 為例:

查詢:
# yum search vnc

安裝:
# yum install vnc
許多 yum 操作會詢問使用者是否確定執行(y/n),如果希望 yum 自動確定而無須詢問,可加入 -y 參數,例如:
# yum -y install vnc

更新:
# yum update vnc

移除:
# yum remove vnc

已安裝的套件更新:
# yum update

清除所有 yum 快取資料;
# yum claen all

2013年8月2日 星期五

Oracle UDTs _Object with Collection

C#
--------Object with Collection---------
class LeagueDto : IOracleCustomType
{
    [OracleObjectMappingAttribute("NAME")]
    public virtual string Name { get; set; }
    [OracleObjectMappingAttribute("MEMBERS")]
    public virtual TeamWithPlayer Members { get; set; }

    public virtual void FromCustomObject(OracleConnection con, System.IntPtr pUdt)
    {
        OracleUdt.SetValue(con, pUdt, "NAME", this.Name);
        OracleUdt.SetValue(con, pUdt, "MEMBERS", this.Members);
    }
    public virtual void ToCustomObject(OracleConnection con, System.IntPtr pUdt)
    {
        this.Name = ((string)(OracleUdt.GetValue(con, pUdt, "NAME")));
        this.Members = (TeamWithPlayer)OracleUdt.GetValue(con, pUdt, "MEMBERS");
    }
    [OracleCustomTypeMapping("LEAGUE")]
    public class LeagueFactory : IOracleCustomTypeFactory
    {
        public virtual IOracleCustomType CreateObject()
        {
            return new LeagueDto();
        }
    }
}


--------collection---------
class TeamWithPlayer : IOracleCustomType
{
    //Dto是自己的DTO
    public PlayerDto[] Value;
    public virtual void FromCustomObject(OracleConnection con, System.IntPtr pUdt)
    {
        OracleUdt.SetValue(con, pUdt, 0, this.Value);
    }
    public virtual void ToCustomObject(OracleConnection con, System.IntPtr pUdt)
    {
        Value = (PlayerDto[])OracleUdt.GetValue(con, pUdt, 0);
    }
    [OracleCustomTypeMapping("TEAMWITHPLAYER")]
    public class TeamWithPlayerFactory : IOracleCustomTypeFactory, IOracleArrayTypeFactory
    {
        public virtual IOracleCustomType CreateObject()
        {
            return new TeamWithPlayer();
        }
        public virtual Array CreateArray(int length)
        {
            return new PlayerDto[length];
        }
        public virtual Array CreateStatusArray(int length)
        {
            return null;
        }
    }
}
--------DTO---------
class PlayerDto : IOracleCustomType
{
    [OracleObjectMappingAttribute("NAME")]
    public virtual string Name { get; set; }
    [OracleObjectMappingAttribute("ADDRESS")]
    public virtual string Address { get; set; }
    [OracleObjectMappingAttribute("AGE")]
    public virtual decimal Age { get; set; }
    public virtual void FromCustomObject(OracleConnection objCon, IntPtr objUdt)
    {
        OracleUdt.SetValue(objCon, objUdt, "NAME", this.Name);
        OracleUdt.SetValue(objCon, objUdt, "ADDRESS", this.Address);
        OracleUdt.SetValue(objCon, objUdt, "AGE", this.Age);
    }
    public virtual void ToCustomObject(OracleConnection objCon, IntPtr objUdt)
    {
        this.Name = ((string)(OracleUdt.GetValue(objCon, objUdt, "NAME")));
        this.Address = ((string)(OracleUdt.GetValue(objCon, objUdt, "ADDRESS")));
        this.Age = ((decimal)(OracleUdt.GetValue(objCon, objUdt, "AGE")));
    }
    [OracleCustomTypeMappingAttribute("PLAYER")]
    public class PlayerFactory : IOracleCustomTypeFactory
    {
        public virtual IOracleCustomType CreateObject()
        {
            PlayerDto obj = new PlayerDto();
            return obj;
        }
    }
}
-------Main---------
static void Main(string[] args)
{
    Console.WriteLine("Welcome to using C# Custom Object and Oracle User-defined Types:");
    Console.WriteLine("Using DTO & UDTs with procedure to change the Player's age ");
    LeagueDto objLeague = new LeagueDto();
    PlayerDto objPlayer = new PlayerDto();
    objPlayer.Name = "Mr. Syscom";
    objPlayer.Address = "台北市108萬華區峨眉街115號";
    objPlayer.Age = 20;
    PlayerDto objPlayer2 = new PlayerDto();
    objPlayer2.Name = "Mr. Syscom2";
    objPlayer2.Address = "台北市108萬華區峨眉街115號";
    objPlayer2.Age = 30;

    objLeague.Name = "Group 1";
    objLeague.Members = new TeamWithPlayer();
    objLeague.Members.Value = new PlayerDto[2] { objPlayer, objPlayer2 };

    Console.WriteLine("Player1 Age was " + objLeague.Members.Value[0].Age);
    Console.WriteLine("Player2 Age was " + objLeague.Members.Value[1].Age);
    String ConnectionString = ConfigurationManager.ConnectionStrings["ABC"].ConnectionString;

    // Establish the connection with Oracle
    using (OracleConnection objCon = new OracleConnection(ConnectionString))
    {
        // Open the connection
        objCon.Open();
        // Insert the Person object into database table
        using (OracleCommand cmd = new OracleCommand("AlterLeague", objCon))
        {
            cmd.CommandType = CommandType.StoredProcedure; //Database store procedure

            // Oracle Paramater
            OracleParameter objParam = new OracleParameter();
            //Denotes, we are going to pass a custom object
            objParam.OracleDbType = OracleDbType.Object;

            objParam.Direction = ParameterDirection.InputOutput;
            // Note: The UdtTypeName is case-senstive - Should be in upper case
            objParam.UdtTypeName = "LEAGUE";
            // Attach custom object as input parameter
            objParam.Value = objLeague;

            //Attach parameter to command object
            cmd.Parameters.Add(objParam);

            // Insert the UDT into the table
            cmd.ExecuteNonQuery();

            objLeague = (LeagueDto)cmd.Parameters[0].Value;
        }
    }
    Console.WriteLine("After alter the age:");
    Console.WriteLine("Player1 Age is " + objLeague.Members.Value[0].Age);
    Console.WriteLine("Player2 Age is " + objLeague.Members.Value[1].Age);
    Console.ReadLine();        
}
-----Procedure---------
CREATE OR REPLACE procedure
                EEP.AlterLeague(L_LEAGUE IN OUT LEAGUE) as
begin
    L_LEAGUE.MEMBERS(1).age:=22;
    L_LEAGUE.MEMBERS(2).age:=32;
end AlterLeague;
Object with collection in Oracle
CREATE OR REPLACE TYPE EEP.LEAGUE AS OBJECT
(
    name varchar2(30),
    MEMBERS TEAMWITHPLAYER
)NOT FINAL
--------Collection in Oracle---------
CREATE OR REPLACE TYPE EEP.TEAMWITHPLAYER AS TABLE OF PLAYER
----------Object---------
CREATE OR REPLACE
TYPE  EEP.PLAYER AS OBJECT
(
    name varchar2(30),
    address varchar2(60),
    age number(3)
)NOT FINAL
----------Result---------

2013年7月19日 星期五

Static Constructor vs Constructor 靜態建構式

參考:MSDN 靜態建構式
靜態建構函式可以用來初始化任何靜態資料,或執行只需執行一次的特定動作。
在建立第一個執行個體或參考任何靜態成員之前,會自動呼叫靜態建構函式。

C# Code
class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("了解Static Constructor 與Constructor");
            ForTestConstractor x = new ForTestConstractor();
            Console.ReadLine();
        }
     }

class ForTestConstractor
    {
         //static Constrator
        static ForTestConstractor()
        {
            Console.WriteLine("static Constructor");
        }
        public ForTestConstractor()
        {
            Console.WriteLine("normal Constructor");
        }
    }
執行結果:

了解Static Constructor 與Constructor
static Constructor
normal Constructor

2013年6月6日 星期四

MVC 4 AjaxBeginForm 用多重按鈕

參考文章:Handling multiple submit buttons on the same form - MVC Razor

一般使用Ajax.BeginForm會搭配Submit button觸發,
要使用多重按鈕
1.必須要指定所有按鈕都有相同的name屬性(name="btn")
2.每個按鈕賦予不同的值(value = "Create" or value = "Update" )
3.在Controller中,除了model的參數外(ModelDto XDto),
還要加上從View傳到Control 的值,參數的命名必須跟name屬性相同(string btn )
4.利用btn當作條件做判斷

--View-----------------------------------------------------------------------------------------------------
@using (Ajax.BeginForm("Create", "DIM", new AjaxOptions { HttpMethod = "POST", Confirm = "確定要變更?", UpdateTargetId = "ajaxBody" }))
{
    @Html.EditorFor(model => model.id)
    

}
--Controller------------------------------------------------------------------------------------------------
// POST: /DIM/Create
[HttpPost]
public ActionResult Create(ModelDto XDto, string btn)
{        
    if (ModelState.IsValid)
    {
        if (btn == "Create")
        {
            db.ModelDto .Add(XDto);
            db.SaveChanges();
        }
        else
        {
            db.Entry(XDto).State = EntityState.Modified;
            db.SaveChanges();
        }
    }
    return RedirectToAction("List");
}

2013年5月20日 星期一

C# .NET 修改系統時間

依賴系統時間執行不同方法的程式,
測試時可能就需要改變系統時間來確定程式是否有問題。

2013年5月14日 星期二

Oracle UT 自製Assert

參考Oracle PL/SQL 5th

Oracle沒有提供UT的元件,
所以必須要自己撰寫類似Assert的檢核機制。
ex.
PROCEDURE ASSERT (description IN VARCHAR2 , expected_value IN VARCHAR2, actual_value  IN VARCHAR2) --驗證用
IS
BEGIN
    DBMS_OUTPUT.PUT(description || ': ');
    IF expected_value = actual_value OR (expected_value IS NULL AND actual_value IS NULL) 
        THEN DBMS_OUTPUT.PUT_LINE('PASSED'); 
        ELSE DBMS_OUTPUT.PUT_LINE('FAILED. Expected ' || expected_value || '; got ' || actual_value); 
    END IF;
END;
PROCEDURE ASSERT (description IN VARCHAR2 , expected_value IN NUMBER, actual_value IN NUMBER) --驗證用
IS
BEGIN
    DBMS_OUTPUT.PUT(description || ': ');
    IF expected_value = actual_value OR (expected_value IS NULL AND actual_value IS NULL) 
        THEN DBMS_OUTPUT.PUT_LINE('PASSED'); 
        ELSE DBMS_OUTPUT.PUT_LINE('FAILED. Expected ' || expected_value || '; got ' || actual_value); 
    END IF;
END;
-------------------------------
<!--more>
所以UT的撰寫時,可以獨立的把上述兩個Procedure撰寫在oracle中,
或者可以直接寫在Declare裡。
ex.
Declare
    A number;--預計資料筆數
    B number;--實際資料筆數(從table撈)
    PROCEDURE ASSERT (description IN VARCHAR2 , expected_value IN VARCHAR2, actual_value  IN VARCHAR2) --驗證用
    IS
    BEGIN
        DBMS_OUTPUT.PUT(description || ': ');
        IF expected_value = actual_value OR (expected_value IS NULL AND actual_value IS NULL) 
            THEN DBMS_OUTPUT.PUT_LINE('PASSED'); 
            ELSE DBMS_OUTPUT.PUT_LINE('FAILED. Expected ' || expected_value || '; got ' || actual_value); 
        END IF;
    END;
    PROCEDURE ASSERT (description IN VARCHAR2 , expected_value IN NUMBER, actual_value IN NUMBER) --驗證用
    IS
    BEGIN
        DBMS_OUTPUT.PUT(description || ': ');
        IF expected_value = actual_value OR (expected_value IS NULL AND actual_value IS NULL) 
            THEN DBMS_OUTPUT.PUT_LINE('PASSED'); 
            ELSE DBMS_OUTPUT.PUT_LINE('FAILED. Expected ' || expected_value || '; got ' || actual_value); 
        END IF;
    END;

BEGIN
       A : =10;(預計10筆)
       SELECT Count(*) INTO B FROM table;
       ASSERT('筆數檢核:',A,B) ;
END;
------------------------------------------------------------------------------------------------
結果(DBMS_OUTPUT):
通過→
筆數檢核:PASSED
失敗→
筆數檢核:FAILED. Expected : 10 ;got 9

2013年5月7日 星期二

2013年5月3日 星期五

2013年4月30日 星期二

使用DBMS_UTILITY.format_error_backtrace

DBMS_UTILITY.format_error_backtrace

For Oracle 10g以上的EXCEPTION TRACE~

Sample from book :
------------------------PK spec-----------------------------
CREATE OR REPLACE PACKAGE EEP.ERRORTEST
AS
    PROCEDURE proc1;
    PROCEDURE proc2;
    PROCEDURE proc3;
END;

2013年4月25日 星期四

Auto increase column in Oracle


Auto increase column
1.      開啟青蛙
2.      點選Sequences
3.      在空白處按右鍵→Creat Sequence


2.      輸入以下資料,按下OK即可,Sequence Name 請輸入你要的 ex: XXXXXX
3.      使用方式:
1.      "INSERT INTO Table VALUES(XXXXXX .NEXTVAL, BrokerId , TermId, SeqNo, Stock, BSCode, MthQty, ’ MthPrice, SendFlag)"
Ex: "INSERT INTO MATCH VALUES(XXXXXX .NEXTVAL,’9898’, ‘A’, ‘0001’, ‘2330’, ’B’, ‘30’, ’20.2’, 'F')";
2.取出目前櫃號:SELECT XXXXXX.CURRVAL FROM DUAL
3.取用一組新的值:SELECT XXXXXX. NEXTVAL FROM DUAL
6. 刪除Sequence


2013年4月11日 星期四

C#DTO collection & Oracle UDTs Collection

C#--- class
class SimpleTable : IOracleCustomType
{

    [OracleArrayMapping()]
   //Dto是自己的DTO
    public Dto[] Value;
    public virtual void FromCustomObject(OracleConnection con, System.IntPtr pUdt)
    {
            OracleUdt.SetValue(con, pUdt, 0, this.Value);
    }

    public virtual void ToCustomObject(OracleConnection con, System.IntPtr pUdt)
    {
        Value = (Dto[])OracleUdt.GetValue(con, pUdt, 0);
        //this.Value = ((Dto[])(OracleUdt.GetValue(con, pUdt, 0)));
    }
    [OracleCustomTypeMapping("TESTTABLE")]
    public class SimpleTableFactory : IOracleCustomTypeFactory, IOracleArrayTypeFactory
    {
        public virtual IOracleCustomType CreateObject()
        {
            return new SimpleTable();
        }

        public virtual Array CreateArray(int length)
        {
            return new Dto[length];
        }

        public virtual Array CreateStatusArray(int length)
        {
            return null;
        }
    }
}

2013年4月10日 星期三

2013年4月3日 星期三

C# ARRAY n Oracle UDTs VARRAY

參考網址:http://www.codeproject.com/Articles/33829/How-to-use-Oracle-11g-ODP-NET-UDT-in-an-Oracle-Sto

C#--- class
public class SimpleVarray : IOracleCustomType, INullable
{
    [OracleArrayMapping()]
    public string[] Array;
    private bool m_bIsNull;
    public bool IsNull
    {
        get
        {
            return m_bIsNull;
        }
    }
    public static SimpleVarray Null
    {
        get
        {
            SimpleVarray obj = new SimpleVarray();
            obj.m_bIsNull = true;
            return obj;
        }
    }
    public void ToCustomObject(OracleConnection con, IntPtr pUdt)
    {
        object objectStatusArray = null;
        Array = (string[])OracleUdt.GetValue(con, pUdt, 0, out objectStatusArray);
    }
    public void FromCustomObject(OracleConnection con, IntPtr pUdt)
    {
        OracleUdt.SetValue(con, pUdt, 0, Array);
    }
}

[OracleCustomTypeMapping("EEP.TESTVARRAY")]
public class SimpleVarrayFactory : IOracleCustomTypeFactory, IOracleArrayTypeFactory
{
    public IOracleCustomType CreateObject()
    {
        return new SimpleVarray();
    }
    public Array CreateArray(int numElems)
    {
        return new string[numElems];
    }
    public Array CreateStatusArray(int numElems)
    {
        return null;
    }
}
C#----main
private static void OrderReport()
{  
    SimpleVarray test = new SimpleVarray();
    test.Array = new string[]
    {
        "A","B","C","D", "E","F","G","H",DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
    };
    String ConnectionString = ConfigurationManager.ConnectionStrings["ABC"].ConnectionString;
    using (OracleConnection conn = new OracleConnection(ConnectionString))
    {
        conn.Open();
        using (OracleCommand cmd = conn.CreateCommand())
        {
            try
            {
                cmd.CommandText = "TEST";
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add("V_List", OracleDbType.Array).Direction = ParameterDirection.Input;
                cmd.Parameters[0].Value = test;
                cmd.Parameters[0].UdtTypeName = "TESTVARRAY";
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            Console.WriteLine("1");
            Console.ReadLine();
        }
    }
}
ORACLE TYPE---
TYPE "TESTVARRAY" AS VARRAY(3000) OF VARCHAR(30)

ORACLE STORED PROCEDURE---
PROCEDURE TEST(V_List IN TESTVARRAY) AS
    BEGIN
        INSERT INTO AAAA (A, B,C, D, E, F, G, H, DATETIME) VALUES(V_List(1), V_List(2), V_List(3), V_List(4), V_List(5), V_List(6), V_List(7), V_List(8), to_timestamp(V_List(9), 'yyyy-mm-dd hh24:mi:ss.ff3'));
    END;

2013年4月1日 星期一

C# DTO n Oracle UDTs

參考網址:
http://www.codeproject.com/Articles/141728/Interaction-between-C-Application-and-Oracle-throu
C# DTO
class PersonDto : IOracleCustomType
    {
    [OracleObjectMappingAttribute("PNAME")]
    public virtual string Name { get; set; }
    [OracleObjectMappingAttribute("ADDRESS")]
    public virtual string Address { get; set; }
    [OracleObjectMappingAttribute("AGE")]
    public virtual decimal Age { get; set; }
    public virtual void FromCustomObject(OracleConnection objCon, IntPtr objUdt)
    {
        OracleUdt.SetValue(objCon, objUdt, "PNAME", this.Name);
        OracleUdt.SetValue(objCon, objUdt, "ADDRESS", this.Address);
        if (this.Age > 0) OracleUdt.SetValue(objCon, objUdt, "AGE", this.Age);
    }
    public virtual void ToCustomObject(OracleConnection objCon, IntPtr objUdt)
    {
        this.Name = ((string)(OracleUdt.GetValue(objCon, objUdt, "PNAME")));
        this.Address = ((string)(OracleUdt.GetValue(objCon, objUdt, "ADDRESS")));
        bool AgeIsNull = OracleUdt.IsDBNull(objCon, objUdt, "AGE");
        if ((AgeIsNull == false)) this.Age =
            ((decimal)(OracleUdt.GetValue(objCon, objUdt, "AGE")));
    }
    [OracleCustomTypeMappingAttribute("PERSON")]
    public class PersonFactory : IOracleCustomTypeFactory
    {
        public virtual IOracleCustomType CreateObject()
        {
            PersonDto obj = new PersonDto();
            return obj;
        }
    }
}

2013年3月21日 星期四

Zabbix安裝SOP

環境
OS: Linux RedHat 5.5

1.安裝 RedHat5.5
因為該死的Zabbix只能安裝在Linux系統上,再加上公司決定使用RedHat作為資料庫的系統,所以我們只好安裝這不熟悉的小紅帽(不然筆者超想用Ubuntu)。
首先拿出RedHat光碟片放進光碟機裡開始安裝,
接著安裝細節就不多說了,
這裡提醒一點,
因為之後安裝Zabbix時需要PHP5. MySQL. Apache2..等套件,
而安裝這些套件又需要其他雜七雜八套件的相依性,
所以建議把相關的套件能勾的就勾吧。

2.檢查安裝套件
安裝完RedHat後,
我們要檢查套件是否有安裝,
輸入以下指令來檢查PHP5. MySQL與相關套件是否有安裝:
# rpm -qa | grep mysql
# rpm -qa | grep php
以此類推檢查所需的套件
(zlib-devel. openssl-devel. libxml2-devel. flex. bison. gcc. automake. autoconf. snmp. 
rrdtool. php-gd. php-mysql. php-pear. apache2. mysql. php...),
如果沒有的話就拿出光碟一一的安裝吧,
安裝時可以直接Double Click rpm套件檔安裝,
也可用指令進行安裝:
# rpm -ivh <package name>

2013年3月20日 星期三

看懂AWR


原始出處AWR分析


Host CPU (CPUs: 4 Cores: 2 Sockets: 1)
Load Average BeginLoad Average End%User%System%WIO%Idle
4.94.091.2
  • 在OS來說CPU的使用率=Busy + Idle→所以在這裡Busy%=1-91.2=8.8%
  • 搭著Operating System Statistics看
    • %User = USER_TIME/(BUSY_TIME+IDLE_TIME)*100 
      • 18457/(33590+345995)*100=4.86 
    • %Sys  = SYS_TIME/(BUSY_TIME+IDLE_TIME)*100
      • 15133/379585=3.98
    • %Idle = IDLE_TIME/(BUSY_TIME+IDLE_TIME)*100
      • 345995/379585=91.15

Operating System Statistics

  • *TIME statistic values are diffed. All others display actual values. End Value is displayed if different
  • ordered by statistic type (CPU Use, Virtual Memory, Hardware Config), Name
StatisticValueEnd Value
AVG_BUSY_TIME8,372
AVG_IDLE_TIME86,474
AVG_SYS_TIME3,761
AVG_USER_TIME4,590
BUSY_TIME33,590
IDLE_TIME345,995
SYS_TIME15,133
USER_TIME18,457
RSRC_MGR_CPU_WAIT_TIME0
VM_IN_BYTES66,340,137,790,754,816
VM_OUT_BYTES-144,554,992,965,316,608
PHYSICAL_MEMORY_BYTES8,470,183,936
NUM_CPUS4
NUM_CPU_CORES2
NUM_CPU_SOCKETS1
  • BUSY_TIME + IDLE_TIME = ELAPSED_TIME * CPU_COUNT
  • 至于DB对CPU的利用情况,这就涉及到10g新引入的一个关于时间统计的视图了, v$sys_time_model,简单而言,Oracle采用了一个统一的时间模型对一些重要的时间指标进行了记录,具体而言,这些指标包括:
1) background elapsed time
    2) background cpu time
          3) RMAN cpu time (backup/restore)
1) DB time
    2) DB CPU
    2) connection management call elapsed time
    2) sequence load elapsed time
    2) sql execute elapsed time
    2) parse time elapsed
          3) hard parse elapsed time
                4) hard parse (sharing criteria) elapsed time
                    5) hard parse (bind mismatch) elapsed time
          3) failed parse elapsed time
                4) failed parse (out of shared memory) elapsed time
    2) PL/SQL execution elapsed time
    2) inbound PL/SQL rpc elapsed time
    2) PL/SQL compilation elapsed time
    2) Java execution elapsed time
    2) repeated bind elapsed time
  • 紅色的兩個CPU時間才需要注意,並且在Time Model Statistics也可以看到。

2013年3月14日 星期四

.NET Debugging Demos Lab 4: High CPU Hang - Review

原始文章出處:.NET Debugging Demos Lab 4: High CPU Hang - Review

Reproducing the issue:

  1. 重啟IIS (IISReset)
  2. 瀏覽http://localhost/BuggyBits/AllProducts.aspx 
  3. 當瀏覽這個網頁時,觀看工作管理員的CPU使用率
    • Q: What is the CPU usage like for w3wp.exe during the processing of this request?
    • A: Very high, approaching 100% 

Set up a performance counter log:

Prepare to gather a memory dump:

  • 開啟cmd.exe並移至debuggers 目錄並輸入adplus -hang -pn w3wp.exe -quiet -o D:\Dump但不要按下enter

2013年3月12日 星期二

.NET Debugging Demos Lab 3: Memory - Review

原始文章:
.NET Debugging Demos Lab 3: Memory
.NET Debugging Demos Lab 3: Memory - Review

Set up a performance monitor log

  1. 開啟http://127.0.0.1/Links.aspx 頁面
  2. 開啟效能監視器(所有程式→系統管理工具)
    1. 執行→新增資料收集器集合工具→名稱lab3-memory、手動建立
    2. 勾選效能計數器
    3. 新增(抽樣間隔1秒):
      1. .NET CLR Memory的w3wp
      2. Process的w3wp
    4. 根目錄→可以自選(ex. D:\Logs)
    5. 執行身分(工作管理員權限)
    6. 點選儲存後開啟

WinDbg_!address 說明文件


The following filter values specify memory regions by the way that the target process is using them.
Filter value Memory regions displayed
VAR Busy regions. These regions include all virtual allocation blocks, the SBH heap, memory from custom allocators, and all other regions of the address space that fall into no other classification.
Free Free memory. This includes all memory that has not been reserved.
Image Memory that is mapped to a file that is part of an executable image.
Stack Memory used for thread stacks.
Teb Memory used for thread environment blocks (TEBs).
Peb Memory used for the process environment block (PEB).
Heap Memory used for heaps.
PageHeap The memory region used for the full-page heap.
CSR CSR shared memory.
Actx Memory used for activation context data.
NLS Memory used for National Language Support (NLS) tables.
FileMap Memory used for memory-mapped files. This filter is applicable only during live debugging.

2013年3月11日 星期一

WinDbg_DumpHeap說明

0:000> !help DumpHeap
-------------------------------------------------------------------------------
!DumpHeap [-stat]
          [-strings]
          [-short]
          [-min <size>]
          [-max <size>]
          [-thinlock]
          [-startAtLowerBound]
          [-mt <MethodTable address>]
          [-type <partial type name>]
          [start [end]]

!DumpHeap is a powerful command that traverses the garbage collected heap,
collection statistics about objects. With it's various options, it can look for
particular types, restrict to a range, or look for ThinLocks (see !SyncBlk
documentation). Finally, it will provide a warning if it detects excessive
fragmentation in the GC heap.

2013年3月8日 星期五

.NET Debugging Demos Lab 2: Crash - Review

文章原始出處:.NET Debugging Demos Lab 2: Crash - Review

Reproduce the problem

  1. 開啟http://127.0.0.1/Reviews.aspx頁面
  2. Click Refresh按鈕後,將會crash w3wp.exe。Note:如果你有Visual Studio,它可能會引起Debugg視窗,選擇no即可。

2013年3月7日 星期四

.NET Debugging Demos Lab 1: Hang - Review

Note:Debug的結果跟Thread ID會因為操作的速度以及基礎環境而有所出入。原作者使用W2k3,而作者我是用Win7。
原始出處.NET Debugging Demos Lab 1: Hang - Review

Reproduce the problem:

  1. 瀏覽http://localhost/BuggyBits/FeaturedProducts.aspx
    • 顯示這個頁面需要五秒,可以在頁面下看到開始跟執行時間。
  2. 開啟五個相同的頁面,並且盡量同時重整頁面(reflash)
    • 留意每個頁面的執行時間,並且確認開始時間是幾乎相同的(如果沒有,就代表可能沒有先執行一開始說的reg)
    • Q:執行時間分別為多少?
    • A:依序應該是5s、9.3s、13.96s、17.99、21.53(會有出入,不過如果看到的都是5s那就表示,你沒有幾乎同時的送出request)
    • Q:從工作管理員觀看w3wp.exe的CPU使用率,是高還是低?
    • A:非常低,根本就是0

2013年3月6日 星期三

.NET Debugging Demos - Information and setup instructions

翻譯自Tess  .NET Debugging Demos - Information and setup instructions
希望有需要的人可以看得懂

.NET Debugging Demos

這一系列的Debugging Demos目的在協助體驗Debugging在.Net application中最常見的Hang/performance, memory and crash 狀況。

因為範例是用ASP.NET,所以在開發及範例的環境下需要有IIS以及.net framework 2.0,
所有的範例都是使用同一個網站。

Note: 這些範例將會導致高CPU使用率,高記憶體使用率以及Crash,所以必須確保你只有安裝這個範例,避免其他的網站或應用程式所發生的hanging及Crashing干擾學習Debugging。