InterviewSolution
| 1. |
Usage of Timestamp Datatype in PL/SQL? |
|
Answer» The data type TIMESTAMP stores the year, month, DAY, hour, minute, and second. TIMESTAMP extends the data type DATE. The FOLLOWING is the syntax: TIMESTAMP[(precision)Here, Precision: The number of digits in the fractional part of the seconds field. Optional. The following is an example: DECLARE mydate TIMESTAMP(2); BEGIN mydate := '20-Dec-2018 07:48:53.275'; DBMS_OUTPUT.PUT_LINE( TO_CHAR(mydate )); END; /The output: 20-DEC-18 07.48.53.28 AM In PL/SQL, you can also find a datatype: TIMESTAMP WITH TIME ZONEThe above datatype includes a time-zone displacement. The time-zone displacement is the difference between LOCAL time and COORDINATED Universal Time (UTC,) formerly Greenwich Mean Time (GMT). This difference is in hours and minutes. The following is the syntax: TIMESTAMP[(precision)] WITH TIME ZONEHere, Precision: The number of digits in the fractional part of the seconds field. Optional. Let us see an example: DECLARE mydate TIMESTAMP(2) WITH TIME ZONE; BEGIN mydate := '10-Dec-2018 11:28:55.114 AM +03:00'; DBMS_OUTPUT.PUT_LINE( TO_CHAR(mydate )); END; /The output: 10-DEC-18 11.28.55.11 AM +03:00 |
|