2011年9月13日 星期二

Oracle 時間日期

轉載這篇文章

http://infolab.stanford.edu/~ullman/fcdb/oracle/or-time.html




Resources
Database Systems: The Complete Book by Hector Garcia, Jeff Ullman, and Jennifer Widom.

A First Course in Database Systems by Jeff Ullman and Jennifer Widom.

Gradiance SQL Tutorial.
Oracle Dates and Times
--------------------------------------------------------------------------------

Overview
DATE Format
The Current Time
Operations on DATE
Further Information

--------------------------------------------------------------------------------
Overview
Oracle supports both date and time, albeit differently from the SQL2 standard. Rather than using two separate entities, date and time, Oracle only uses one, DATE. The DATE type is stored in a special internal format that includes not just the month, day, and year, but also
the hour, minute, and second.
The DATE type is used in the same way as other built-in types such as INT. For example, the following SQL statement creates a relation with an attribute of type DATE:

create table x(a int, b date);

--------------------------------------------------------------------------------
DATE Format
When a DATE value is displayed, Oracle must first convert that value from the special internal format to a printable string. The conversion is done by a function TO_CHAR, according to a DATE format. Oracle's default format for DATE is "DD-MON-YY". Therefore, when you issue the query
select b from x;
you will see something like:
B
---------
01-APR-98
Whenever a DATE value is displayed, Oracle will call TO_CHAR automatically with the default DATE format. However, you may override the default behavior by calling TO_CHAR explicitly with your own DATE format. For example,
SELECT TO_CHAR(b, 'YYYY/MM/DD') AS b
FROM x;
returns the result:
B
---------------------------------------------------------------------------
1998/04/01
The general usage of TO_CHAR is:
TO_CHAR(, '')
where the string can be formed from over 40 options. Some of the more popular ones include:
MM Numeric month (e.g., 07)
MON Abbreviated month name (e.g., JUL)
MONTH Full month name (e.g., JULY)
DD Day of month (e.g., 24)
DY Abbreviated name of day (e.g., FRI)
YYYY 4-digit year (e.g., 1998)
YY Last 2 digits of the year (e.g., 98)
RR Like YY, but the two digits are ``rounded'' to a year in the range 1950 to 2049. Thus, 06 is considered 2006 instead of 1906 , for example.
AM (or PM) Meridian indicator
HH Hour of day (1-12)
HH24 Hour of day (0-23)
MI Minute (0-59)
SS Second (0-59)

You have just learned how to output a DATE value using TO_CHAR. Now what about inputting a DATE value? This is done through a function called TO_DATE, which converts a string to a DATE value, again according to the DATE format. Normally, you do not have to call TO_DATE explicitly: Whenever Oracle expects a DATE value, it will automatically convert your input string using TO_DATE according to the default DATE format "DD-MON-YY". For example, to insert a tuple with a DATE attribute, you can simply type:

insert into x values(99, '31-may-98');
Alternatively, you may use TO_DATE explicitly:
insert into x
values(99, to_date('1998/05/31:12:00:00AM', 'yyyy/mm/dd:hh:mi:ssam'));
The general usage of TO_DATE is:
TO_DATE(, '')
where the string has the same options as in TO_CHAR.
Finally, you can change the default DATE format of Oracle from "DD-MON-YY" to something you like by issuing the following command in sqlplus:

alter session set NLS_DATE_FORMAT='';
The change is only valid for the current sqlplus session.

--------------------------------------------------------------------------------
The Current Time
The built-in function SYSDATE returns a DATE value containing the current date and time on your system. For example,
select to_char(sysdate, 'Dy DD-Mon-YYYY HH24:MI:SS') as "Current Time"
from dual;
returns
Current Time
---------------------------------------------------------------------------
Tue 21-Apr-1998 21:18:27
which is the time when I was preparing this document :-) Two interesting things to note here:
You can use double quotes to make names case sensitive (by default, SQL is case insensitive), or to force spaces into names. Oracle will treat everything inside the double quotes literally as a single name. In this example, if "Current Time" is not quoted, it would have been interpreted as two case insensitive names CURRENT and TIME, which would actually cause a syntax error.
DUAL is built-in relation in Oracle which serves as a dummy relation to put in the FROM clause when nothing else is appropriate. For example, try "select 1+2 from dual;".
Another name for the built-in function SYSDATE is CURRENT_DATE. Be aware of these special names to avoid name conflicts.

--------------------------------------------------------------------------------
Operations on DATE
You can compare DATE values using the standard comparison operators such as =, !=, >, etc.
You can subtract two DATE values, and the result is a FLOAT which is the number of days between the two DATE values. In general, the result may contain a fraction because DATE also has a time component. For obvious reasons, adding, multiplying, and dividing two DATE values are not allowed.

You can add and subtract constants to and from a DATE value, and these numbers will be interpreted as numbers of days. For example, SYSDATE+1 will be tomorrow. You cannot multiply or divide DATE values.

With the help of TO_CHAR, string operations can be used on DATE values as well. For example, to_char(, 'DD-MON-YY') like '%JUN%' evaluates to true if is in June.


--------------------------------------------------------------------------------
This document was written originally by Kristian Widjaja for Prof. Jeff Ullman's CS145 class in Autumn, 1997; revised by Jun Yang for Prof. Jennifer Widom's CS145 class in Spring, 1998; further revisions by Prof. Ullman in Autumn, 1998.

Vb.net 連線至Oracle 連線字串

真是太笨了,這種問題可以困擾很久....


"<" add name="Oracle" connectionstring="Server=xxx.xxx.xxx.xxx:1521/資料庫名稱;User ID=使用者名稱;Password=使用者密碼;Persist Security Info=True" name="Oracle" "> " "<"/add ">"

2011年9月9日 星期五

jsp 呼叫 .Net 所寫的 WebService

這裡需要先當露 jsp 所需要的元件 Axis ,目前本人的環境為 Axis1.4版+Apache Tomcat 6.0+Java 7(?)

下載完後,解壓縮資料夾,把 webapps\axis\WEB-INF\lib 目錄下的所有檔案,複製到 TomCat的 webapps\ROOT\WEB-INF\lib 裡面,同樣的,把 webapps\axis\WEB-INF\classes 複製到TomCat的webapps\ROOT\WEB-INF\classes裡面

編輯環境變數


新增
名稱:AXIS_HOME            值:%TOMCAT_HOME%\webapps\axis
名稱:AXIS_LIB                 值:%AXIS_HOME%\lib
名稱:AXISCLASSPATH  值:%AXIS_LIB%\axis.jar;%AXIS_LIB%\commons-discovery.jar; %AXIS_LIB%\commons-logging.jar;%AXIS_LIB%\jaxrpc.jar; %AXIS_LIB%\saaj.jar;%AXIS_LIB%\log4j-1.2.8.jar; %AXIS_LIB%\xml-apis.jar;%AXIS_LIB%\xercesImpl.jar

嗯。。。。。有點麻煩吧。。。

接下來,把剛剛解壓縮的 Axis目錄打開,把webapps目錄下的axis目錄,整個複製到
TomCat的 webapps 下,在瀏覽器上打

http://自己湯姆貓的網址/axis ,會出現測試網頁


接下來,都沒問題的話,在瀏覽器上打
http://自己湯姆貓的網址/axis/happyaxis.jsp ,會出現測試的結果


沒什麼大問題的話,就可以開始享受寫Code的樂趣了

以下是.net的WebService

VB.net:

    _
    Public Function TestHello(ByVal strName As String) As String
        Try
            My.Computer.FileSystem.WriteAllText("D:\tmp\test.txt", strName & vbCrLf, True)
        Catch ex As Exception

        End Try
        Return "Hello" & strName
    End Function
End Class


我們這次的測試目標擺在最後一個 Function (TestHello),測試方式很簡單,我傳進一個名稱,回傳 『Hello』+ 『傳入名稱』,例如傳入『 Randy笨蛋』,會回傳 『Hello Randy笨蛋』

接下來是JSP的 code

JSP:

需要傳入的套件
org.apache.axis.client.Call
org.apache.axis.client.Service
javax.xml.namespace.QName
java.util.Date
java.text.DateFormat
java.lang.Integer
javax.xml.rpc.ParameterMode

主要的code:

String strEndpoint = "http://localhost/TestWS/service1.asmx";
//注意,這個NameSpace一定要設定,不然傳進的參數永遠都NULL
String strNameSpace="http://localhost/TestWS/";

Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(new java.net.URL(strEndpoint));
call.setUseSOAPAction(true);
call.setSOAPActionURI("http://localhost/TestWS/TestHello");
call.setOperationName(new QName(strNameSpace,"TestHello"));
call.addParameter(new QName(strNameSpace,"strName"), org.apache.axis.encoding.XMLType.XSD_STRING,
javax.xml.rpc.ParameterMode.IN);
call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);
String result;
call.setTargetEndpointAddress(new java.net.URL(strEndpoint));
result=(String) call.invoke(new Object[] {" Randy笨蛋"});


=result


請注意

String strNameSpace="http://localhost/TestWS/";
call.setOperationName(new QName(strNameSpace,"TestHello"));
call.addParameter(new QName(strNameSpace,"strName"), org.apache.axis.encoding.XMLType.XSD_STRING,
javax.xml.rpc.ParameterMode.IN); 

傳錯了,所有String 的參數都是NULL,所有Integer的參數都是0,意思是萬劫不復,永不超生的地獄就此展開,永遠的一路靠北--邊走。。。Debug到天荒地老也是沒結果,就跟把正妹一樣,而且這裡的錯誤是沒錯誤訊息....就如同被女生拒絕也不知道,被發好人卡卻又可以約出去玩,超級大大大好人,別再犯這個錯,親愛的網友們,注意這個微不足道的小重點吧。。


所以我們期望的結果是『Hello Randy笨蛋』

以下就是執行結果



出現的是『Hello Randy�³J 』,沒錯,編碼問題,編碼問題本人有時間在試試 @@...

2011年8月8日 星期一

在痞客邦嵌入Youtube 影片

利用iFrame的威力

"<" iframe width="640" height="510" src="http://www.youtube.com/embed/影片ID?rel=0&autoplay=1&feature=player_detailpage " frameborder="0" allowfullscreen ">""<"/iframe">"

至於影片ID如何取得,很簡單,如果影片網址如下


http://www.youtube.com/watch?v=SR6iYWJxHqs&feature=view_all&list=PL987F6AA6CF979795&index=3

影片ID就等於 SR6iYWJxHqs

ps:使用時,把"<"改成 <、">"改成 >

2011年7月1日 星期五

Windows server自動登入

1. Start Regedt32.exe, and then locate the following registry subkey:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon
2. Using your account name and password, double-click the DefaultUserName entry, type your user name, and then click OK.
3. Double-click the DefaultPassword entry, type your password, and then click OK.

NOTE: If the DefaultPassword value does not exist, follow these steps:

a. Click Add Value on the Edit menu.
b. In the Value Name box, type DefaultPassword, and then click REG_SZ for the Data Type
c. Type your password in the String box, and then save your changes.
Also, if no DefaultPassword string is specified, Windows automatically changes the value of the AutoAdminLogon key from 1 (true) to 0 (false), which disables the AutoAdminLogon feature.
4. Click Add Value on the Edit menu, enter AutoAdminLogon in the Value Name box, and then click REG_SZ for the Data Type.
5. Type 1 in the String box, and then save your changes.
6. Quit Regedt32.
7. Click Start, click Shutdown, and then click OK to turn off your computer.
8. Restart your computer and Windows. You are now able to log on automatically.
http://support.microsoft.com/default.aspx?scid=kb;en-us;310584

2011年6月22日 星期三

vb.net 動態載入 UserControl

 Private Function LoadUserControl(ByVal FormName As String) As UserControl
        Dim ProjectName As String =
        Reflection.Assembly.GetExecutingAssembly.GetName.Name
        Try
            Dim tyOfStringVariable As Type = Type.GetType(ProjectName & "." &
            FormName)
            Dim ucObject As Object = Activator.CreateInstance(tyOfStringVariable)
            'DirectCast(ucObject, UserControl).StartPosition = FormStartPosition.CenterParent
            'DirectCast(ucObject, Form).ShowDialog()
            Return DirectCast(ucObject, UserControl)
        Catch ex As Exception
            ' TODO
            Throw New Exception("UserControl Not Exist!")
        End Try
        Return Nothing
    End Function

2011年6月10日 星期五

有關於單一執行個體

在vb裡面可以勾選『單一執行個體』,但是小弟在Server 2008 R2 X64 某些客戶機器底下,發現這個功能完全破功,只好用手動的在程式裡面加上功能

在Form load裡面

      Dim intTimes As Integer
        Dim strMeName() As String
        Dim strName As String
        intTimes = 0
        '取出名字,包涵檔名路徑
        strMeName = Split(Application.ExecutablePath, "\")
        '真正的名字是在最後一個
        strName = strMeName(strMeName.Length - 1).ToUpper
        '不要.exe結尾
        strName = Split(strName, ".EXE")(0)
        '偵測有無執行過了
        For Each p As Process In Process.GetProcesses()
            Try
                For Each m As ProcessModule In p.Modules
                    If Mid(m.ModuleName, 1, strName.Length).ToUpper = strName Then
                        intTimes = intTimes + 1
                    End If
                Next
            
            Catch ex As Exception
            End Try
        Next
        Try
            '如果有兩個人,就離開
            If intTimes > 1 Then
                '自殺
                '離開並關閉執行緒
                Environment.Exit(Environment.ExitCode)
                Application.Exit()
            End If
        Catch ex As Exception
        End Try


這樣無論OS版本為何,幾個User登入,都可以確保只有一隻程式在跑