Oracleʱ¼äÏÔʾ·½·¨Ð޸ļ¼ÇÉ
¡¶Oracleʱ¼äÏÔʾ·½·¨Ð޸ļ¼ÇÉ£¬ÐèÒªÏêϸ´úÂëʾÀý¡·
ÔÚOracleÊý¾Ý¿âÖУ¬Ê±¼äµÄÏÔʾÊdz£¼ûµÄ²Ù×÷ÐèÇóÖ®Ò»¡£Ä¬ÈÏÇéÐÎÏ£¬OracleÊý¾Ý¿âÖÐʱ¼äµÄÏÔʾÃûÌÃÊÇÀο¿µÄ£¬¿ÉÊÇÓÐʱ¼äÎÒÃÇÐèҪƾ֤×Ô¼ºµÄÐèÇó¾ÙÐÐÃûÌû¯ÏÔʾ¡£±¾ÎĽ«ÏÈÈÝÔõÑùÔÚOracleÊý¾Ý¿âÖÐÐÞ¸Äʱ¼äÏÔʾ·½·¨£¬²¢ÌṩÏêϸµÄ´úÂëʾÀý¡£
ÐÞ¸Äʱ¼äÏÔʾÃûÌÃ
ÔÚOracleÊý¾Ý¿âÖУ¬Ê±¼ä×ֶεÄÊý¾ÝÀàÐÍͨ³£ÎªDATE»òTIMESTAMP£¬¶øÕâÁ½ÖÖÀàÐÍÔÚĬÈÏÇéÐÎÏÂÏÔʾµÄÃûÌÃÊÇÀο¿µÄ¡£ÈôÊÇÎÒÃÇÏ£ÍûÐÞ¸Äʱ¼äµÄÏÔʾ·½·¨£¬¿ÉÒÔͨ¹ýʹÓÃTO_CHARº¯Êý½«Ê±¼ä×Ö¶Îת»»ÎªÖ¸ÃüÃûÌõÄ×Ö·û´®¡£TO_CHARº¯ÊýµÄÓï·¨ÈçÏ£º
SELECT TO_CHAR(time_column, 'format') FROM table_name;
µÇ¼ºó¸´ÖÆ
ÆäÖУ¬time_columnΪʱ¼ä×Ö¶ÎÃû£¬formatΪʱ¼äÃûÌû¯Ä£°å¡£ÏÂÃæÊÇһЩ³£ÓõÄʱ¼äÃûÌû¯Ä£°å¼°Æä¼ÄÒ壺
YYYY-MM-DD HH24:MI:SS£ºÄê-ÔÂ-ÈÕ Ê±:·Ö:Ãë
MM/DD/YYYY HH:MI:SS AM£ºÔÂ/ÈÕ/Äê ʱ:·Ö:Ãë ÉÏÎç/ÏÂÕ½Êé
DD-MON-YYYY HH12:MI:SS AM£ºÈÕ-ÔÂ-Äê ʱ:·Ö:Ãë ÉÏÎç/ÏÂÕ½Êé
Ïêϸ´úÂëʾÀý
¼ÙÉèÓÐÒ»¸öÃûΪemployeesµÄ±í£¬ÆäÖаüÀ¨hire_date×Ö¶ÎÌåÏÖÔ±¹¤Èëְʱ¼ä¡£ÎÒÃÇÏ£Íû½«Èëְʱ¼äÒÔ”Äê-ÔÂ-ÈÕ”µÄÃûÌÃÏÔʾ³öÀ´¡£¿ÉÒÔʹÓÃÒÔÏÂSQLÓï¾ä£º
SELECT TO_CHAR(hire_date, 'YYYY-MM-DD') AS hire_date_formatted FROM employees;
µÇ¼ºó¸´ÖÆ
ÔËÐÐÒÔÉÏSQLÓï¾äºó£¬hire_date×ֶν«ÒÔ”Äê-ÔÂ-ÈÕ”µÄÃûÌÃÏÔʾ³öÀ´¡£ÈôÊÇÐèÒªÏÔʾÆäËûÃûÌã¬Ö»ÐèÐÞ¸ÄTO_CHARº¯ÊýÖеÄÃûÌû¯Ä£°å¼´¿É¡£
³ýÁËʹÓÃTO_CHARº¯ÊýÍ⣬»¹¿ÉÒÔͨ¹ýÐ޸ĻỰ¼¶±ð»òϵͳ¼¶±ðµÄʱ¼äÃûÌòÎÊýÀ´ÊµÏÖʱ¼äÏÔʾ·½·¨µÄÐ޸ġ£¿ÉÒÔʹÓÃALTER SESSIONÓï¾äÐ޸ĻỰ¼¶±ðµÄʱ¼äÃûÌòÎÊý£¬»òÕßʹÓÃALTER SYSTEMÓï¾äÐÞ¸Äϵͳ¼¶±ðµÄʱ¼äÃûÌòÎÊý¡£
×ܽ᣺ͨ¹ýÒÔÉÏÏÈÈÝ£¬ÎÒÃÇÏàʶÁËÔõÑùÔÚOracleÊý¾Ý¿âÖÐÐÞ¸Äʱ¼äµÄÏÔʾ·½·¨£¬Ö÷ÒªÊÇͨ¹ýʹÓÃTO_CHARº¯Êý½«Ê±¼ä×Ö¶Îת»»ÎªÖ¸ÃüÃûÌõÄ×Ö·û´®¡£Í¬Ê±£¬ÌṩÁËÏêϸµÄ´úÂëʾÀýÀ´ÑÝʾÔõÑùʵÏÖʱ¼äÏÔʾ·½·¨µÄÐ޸ġ£Ï£ÍûÕâЩ¼¼ÇɶÔÄúÔÚOracleÊý¾Ý¿âÖд¦Àíʱ¼ä×Ö¶ÎʱÓÐËù×ÊÖú¡£
ÒÔÉϾÍÊÇOracleʱ¼äÏÔʾ·½·¨Ð޸ļ¼ÇɵÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡