Tuesday, December 22, 2009

Edit Oracle DMBS JOBS

oracle version: oracle 9.2
tools: OEM, sqldeveloper

今天發現oracle上一些排程的時間都莫名其妙的往後延了許多,導致影響其他系統的資料正確性,所以動工將一些固定排程的時間做個修正。

一開始理所當然的打開OEM想直接做編輯(Database => DB_NAME => Distributed => Advanced Replication => Administration => [Tab] DBMS Jobs)。結果... 我猜因為中文語系的關係,導致oracle自己一直無法解析時間參數,丟出error。

其實之前已經某一次要新增排程時就遇過這個問題了,所以只好轉戰sql developer,自己寫PL/SQL = =。不過還是一直有一些細節沒注意到,try了好幾次才ok。

首先要注意的是,一定要是該job的owner才有辦法修改他,就算是dba也不行= =! 以DBA身分查詢"DBA_JOBS"這個view,的確可以看見所有已經在系統內的排程,但若是查詢"USER_JOBS"這個view,會發現沒有東西,以DBA身分去修改屬於別人的JOB時,會遇到"ORA-23421"的錯誤,說明如下:

ORA-23421: job number string(%s) is not a job in the job queue
Cause:There is no job visible to the caller with the given job number
Action:Choose the number of a job visible to the caller

所以,請先確定是用該JOB的owner登入資料庫,此時再去查詢"USER_JOBS"可看見屬於他的排程。
接下來要做的是: "修改"已經存在的排程,這邊不討論新增o刪除。

   1:  begin dbms_job.change(

   2:      job => 777, 

   3:      next_date=>to_date('1-1-2010 00:00:00', 'dd-mm-yyyy hh24:mi:ss'),

   4:      interval=> '/*Each Month*/ Add_months(sysdate, 1)',

   5:      what=>

   6:          '--Your PL/SQL here:

   7:          Declare

   8:              v_year number(4);

   9:              v_month number(2);

  10:              v_day number(2);

  11:          begin

  12:              v_year := to_number(to_char(sysdate,''YYYY''));

  13:              v_month := to_number(to_char(sysdate,''MM''));

  14:              v_day :=to_number(to_char(sysdate,''DD''));

  15:   

  16:              --call pre-defined store procedure

  17:              my_store_procedure(v_year, v_month, v_day);

  18:          end;'

  19:  );

  20:  end;

就先從... "修改"說起吧,如Line #1所見,請使用change。
  1. job: job number, user jobs這個view裡的job欄位
  2. next_date: 下次執行時間
  3. interval: 執行頻率,多久執行一次
  4. what: 排程內容(通常是執行某個store procedure,如Line #17)
請注意以上除了job以外,他們的值都有放在一對單引號(' ')裡面!

其餘部分:
Line#4:/*Each Month*/ 這是註解= =
Line#17: 是此排程最主要要執行的store procedure,但因為他需要其他參數,所以有一些前置作業(Line #12~ Line #14)先來取得這些參數
Line#12:這邊要特別注意的是!!!! to_char這個函式原本其實只要寫成這樣: to_char(sysdate, 'YYYY') 就好(就是他的format只要放在單引號內),但是因為這些what語法已經先放在一對單引號內了,如果這邊使用單引號會讓資料庫以為這是what內容的結尾,所以必須在每個單引號前面再加上一個單引號!!! Line #13, Line #14同理

以上,大概是全部要注意的地方了~

Monday, December 21, 2009

[Study] Maintaining Tablespaces and Data Files

這章拖超久的= = 距上次大概一個月了吧!!!
讀到最後一點都不想整理PPT了,只好給他草草了事orz..


Friday, December 11, 2009

Get the display value of DropownDatawindow

如題。

PowerBuilder 裡有一個相當方便的東西就是dropdowndatawindow(dddw)。要取到他的值(data value)很容易,但是要抓到顯示的值(display value)倒是第一次。

displayValue = dw_1.Describe("Evaluate('LookUpDisplay(column_name) ', row#))

一行搞定XD 不過裡面用了很多東西= =。


LookUpDisplay
DescriptionObtains the display value in the code table associated with the data value in the
specified column.
SyntaxLookUpDisplay(column)
Return ValueString. Returns the display value when it succeeds and the empty string (“”) if
an error occurs.


Evaluating DataWindow expressions in the Describe function
DescriptionThe Describe function provides a way to evaluate DataWindow expressions outside their usual context.
Syntaxdwcontrol.Describe ("Evaluate ( 'expression' , rownumber ) " )


Tuesday, December 01, 2009

ARCn: Log actively being archived by another process

今天去關心我親愛的資料庫時,發現他在凌晨兩點相當勤奮的狂丟archive log出來= = 行為相當怪異,所以就去翻翻alert log看看是否有怪訊息,看看似乎也沒什麼error,就是在那個時間相當密集的出現如下訊息:

ARCn: Beginning to archive log# 2 thrd# 1 seq# 24
ARCn: Unable to archive log# 2 thrd# 1 seq# 24
Log actively being archived by another process

嗯... what happened XD?!
再Ask Tom裡找了一些相關文章,其中有某篇算是回答了我的問題:
It is just a side effect of having more then one archiver.

If automatic archiving is turned on then all of the archiver process will try to archive this logfile, however they will not be able to aquire the lock 'kcrrlt', the lock to protect multiple arch processes from archiving the same logfile.

The failing process process will write to the trace/alert message that it was unable to archive the logfile.

The file is successfully archived by some other process.


嗯... 所以其實好像,也沒什麼XD,後來我發現這樣的訊息一直都會出現啦~ 只是沒有像今天凌晨一直連續出現。所以其實問題應該是... "凌晨兩點幹嘛一直勤勞的丟log!? 是誰一直在用系統@_@!?" 這樣XD

好哩~ 這個問題就到這邊。原本看了一些文件想整理一下,不過現在好懶= = 就先這樣吧~ :P

Ref:
Monday, November 16, 2009

[Study] Maintaining Redo Log Files



Friday, November 06, 2009

WSS 3.0 Open links In New Window

這兩個禮拜一直在替WSS換長相,摸出了一些心得。不過今天不講這些XD
講一下WSS的超連結,預設行為都是開在同一個頁面,但是對於那些專門做連結的清單、或是就是要另開新視窗的連結而言,若無法改變WSS行為,操作起來就相當麻煩。

Entonces, 該如何設定讓WSS的特定頁面的超連結行為為開新視窗呢?
  1. 移駕至該頁面
  2. 點選右上角"網站動作" > "編輯頁面" > "新增網頁組件"
  3. 選擇"內容編輯器網頁組件" > 新增
  4. 組件新增至頁面上後,點選內容的"開啟工具窗格"
  5. 點選"原始檔編輯器...",會跳出一個空白對話框,在裡面貼上以下程式:

       1:  <script language="JavaScript">

       2:   

       3:  //add an entry to the _spBodyOnLoadFunctionNames array

       4:  //so that our function will run on the pageLoad event

       5:   

       6:  _spBodyOnLoadFunctionNames.push("rewriteLinks");

       7:   

       8:  function rewriteLinks() {

       9:   

      10:       //create an array to store all the anchor elements in the page

      11:       var anchors = document.getElementsByTagName("a");

      12:   

      13:       //loop through the array

      14:   

      15:       for (var x=0; x<anchors.length; x++) {

      16:       //does this anchor element contain #openinnewwindow?

      17:   

      18:            if (anchors[x].outerHTML.indexOf('#openinnewwindow')>0) {             

      19:               //store the HTML for this anchor element

      20:               oldText = anchors[x].outerHTML;

      21:                

      22:               //rewrite the URL to remove our test text and add a target instead

      23:               newText = oldText.replace(/#openinnewwindow/,'" target="_blank');

      24:   

      25:               //write the HTML back to the browser              

      26:               anchors[x].outerHTML = newText;

      27:            }

      28:       }

      29:  }

      30:   

      31:  </script>


  6. 儲存後,另外在"版面配置"區段下將"隱藏"方框勾選起來即可套用,並結束編輯頁面。
  7. 最後,針對該頁面需要在新視窗開啟的超連結網址後面全部加上"#openinnewwindow"即可!!!
稍微說明一下上面那段javascript主要在做什麼:
首先,第7點說的在網址後面加上"#openinnewwindow"字樣其實是跟程式互相配合的,行18即是尋找所有超連結網址裡是否有這個字樣,如果有找到,就把他換成" target=_blank"這樣而已XD 所以有該字樣的 <A>tag行為就會變成以新視窗開啟了~


Tags