Articles Comments

Oracle DBA & All IT » Function » ย้อนวันเวลาด้วย fixed_date

ย้อนวันเวลาด้วย fixed_date

             การกำหนดวันที่ให้คงที่เสมอให้กับ SYSDATE  แทนที่วันที่ปัจจุบันของโฮสต์ มีประโยชน์สำหรับการทดสอบระบบ โดยค่าที่ได้จะอยู่ในรูปแบของวันที่ โดยไม่มีเวลามาให้ด้วย หรือจะ Set ค่าทั้งวันที่และเวลาเลยก็ได้ ทั้งนี้ขึ้นอยู่กับว่าเราอยากจะให้ SYSDATE สำหรับการทดสอบเฉพาะเจาะจงแค่ไหน

            ซึ่งการ Set ค่า fixed_date จำช่วยให้ Testing ไม่จำเป็นต้องไปแก้ไขข้อมูลใน Table ต่างๆ เพื่อที่จะทำให้สามารถทดสอบระบบย้อนหลังไปวันที่เราต้องการได้

            โดยจากตัวอย่างด้านล่างเราจะย้อนเวลาจากวันปัจจุบัน ไปเป็นวันที่ 14 Aug 05 10:00:00  ซึ่งเมื่อเราทำการ set แล้ววันที่ในระบบจะคงอยู่วันนี้ตลอดไปจนกว่าเราจะ set fixed_date ให้กลับมาเป็นวันเวลาปกติ

 /* กำหนด format ของ SYSDATE ที่เราต้องการแสดง */

ALTER SESSION set nls_date_format = 'DDMonYY HH24:MI:SS';
 Session altered.
/* แสดงค่า SYSDATE จากระบบ โดยจะเป็นวันที่และเวลาปัจจุบันที่ดึงจากโฮสต์ */
select SYSDATE from dual; 
SYSDATE
----------------
08Aug05 11:01:35 
/* ทำการ Set ค่า SYSDATE ให้เป็นวันที่ ที่เราต้องการใช้ในการทดสอบระบบ */
ALTER SYSTEM SET fixed_date = '2005-08-01-14:00:00';
System altered.
 /* แสดงค่า SYSDATE หลังจากที่เรา set fixed_date โดยจะเป็นวันที่และเวลาที่เรากำหนดไว้ */
select SYSDATE from dual;
SYSDATE
---------------
14Aug05 10:00:00
/* การ set ค่า fixed_date ให้กลับเป็นวันที่ปัจจุบันตามโฮสต์ */

ALTER SYSTEM SET fixed_date = NONE;

PRIVILEGE : Alter system

Syntax FIXED_DATE = [YYYY-MM-DD-HH24:MI:SS (or the default Oracle date format) | NONE]

       หวังว่า parameter ตัวนี้จะช่วยให้ Testing ทำงานง่ายขึ้นนะคะ สำหรับทำการทดสอบระบบก่อนขึ้นระบบจริง

.. Preview : 7654

Written by

บอกเล่าสิ่งที่พบเจอมาในการทำงาน ประสบการณ์การทำงานด้าน DBA ถ่ายทอดกันด้วยภาษาง่ายๆ บ้านๆ " ทุกอย่างไม่อยาก แต่... แค่ตั้งใจไม่พอ ต้องลงมือทำ และทำ GoodLuck " Fanpage: www.facebook.com/DBAor .. "Oracle Database Consultant " ..

Filed under: Function

  • Thank you for the learning expierience. I’ll subscribe to you rss and follow you.

    • I love reading these articles because they’re short but ifnoarmtive.

  • I agree with your point,nice article,thanks.I will continue to read your articles.

    • Wow, your post makes mine look feelbe. More power to you!

    • Shoot, who would have thoghut that it was that easy?

  • Have you ever considered creating an e-book or guest authoring on other sites? I have a blog based on the same theme if you’re interested.

    • I really cuoldn’t ask for more from this article.

    • I am totally wowed and preaperd to take the next step now.

  • I am happy that I detected this website , precisely the right information that I was looking for! .

  • These topics are so cnoufsnig but this helped me get the job done.