search
HomeDatabaseMysql TutorialPL/SQL 类型格式转换

PL/SQL 类型格式转换

TO_NUMBER(char[,'format_model']) 字符转换到数字类型
TO_DATE(char[,'format_model']) 字符转换到日期类型
格式说明符:要与前边要转换的字符串的格式要相同才能转换(匹配问题:格式和位数)。
TO_CHAR(date[,'format_model'[,nlsparams]])
第二个参数可以省略,不指定格式,按系统默认格式输出。
区分大小写。
使用FM(在格式控制符前添加)符号可以去掉空格或是首位的零。
如果指定了NLSPARAMS,则它控制返回字符串的月和日分量所使用的语言。格式为:
'NLS_DATA_LANGUAGE=language',language指需要的语言。
例:
select to_char(sysdate,'FMyyyy-mm-dd') from dual;
格式控制符的类型:
YYYY 四位的年
YEAR 年的拼写
MM 2位数字的月
MONTH 月的全名
MON 月名的前三个字符
DY 星期名的前三个字符
DAY 星期名的全称
DD 2位的天
时间格式控制符:
HH24:MI:SS AM
HH12:MI:SS PM
通过“”来实现加入特殊字符的格式控制符。
SELECT TO_CHAR(SYSDATE,'FMyyyy"年"mm"月"dd"日"') from dual;
DDSPTH
~~
DD是格式控制符。
TH是序数词,将日期转换成英文的序数词拼写。
SP是基数词,将日期转换成英文的基数词拼写。
TO_CHAR(NUM[,'format_model'[,nlsparams]])转换数字
将NUMBER类型参数NUM转换成VARCHAR2类型。如果指定FORMAT,它会控制整个转换。
如果没有指定FORMAT,那么结果字符串中将包含和NUM中有效位的个数相同的字符。NLSPARAMS用来指定小数点和千分符及货币符号。它的格式可为:'NLS_NUMERIC_CHARS=' ' dg ' 'NLS_CURRENCY= ' 'string' ' '
d和g分别代表小数点和千分符。STRING代表货币符号。
数字格式控制符:
9 代表一位数字(替换符。有,数字显示;没有。不什么都显示。)
0 代表一位数字(有数字,显示;没有,强制显示0。)
$ 美圆符号
L 本地货币
. 小数点
, 千分符
B 当整数部分为0时,将整数部分填充为空格。 例:B999
MI 返回带有后继符号而不是前导负号的负数值,正数值将带有后继的空格。999MI
S 返回一个前导符号或后继符号,正数为+,负数为-。 S9999 或 9999S
PR 使用尖括号返回负数。正数将有前导或后继空格。999PR
D 在指定位置返回一个小数点。两侧的9的个数指定了最大的位数。99D9
G 在指定位置返回千分符,G可以在FORMAT_model中出现多次。9G999G9
C 在指定位置返回ISO货币符号。C可以在FORMAT_model中出现多次。C99
L 在指定位置上返回本地货币符号。 L99
V 返回一个被乘以10的N次方的数值,这里N是V后边9的个数。99V99
EEEE 使用科学记数法返回该数值。9.99EEEE
RM 使用大写的罗马数字表示返回该数值。 RM
rm 使用小写的罗马数字表示返回该数值。 rm
FM 返回不含前导和后继空格的数值。 FM99.09
格式控制符位数一定要大于或等于NUMBER的位数,不能小于。
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
MySQL BLOB : are there any limits?MySQL BLOB : are there any limits?May 08, 2025 am 12:22 AM

MySQLBLOBshavelimits:TINYBLOB(255bytes),BLOB(65,535bytes),MEDIUMBLOB(16,777,215bytes),andLONGBLOB(4,294,967,295bytes).TouseBLOBseffectively:1)ConsiderperformanceimpactsandstorelargeBLOBsexternally;2)Managebackupsandreplicationcarefully;3)Usepathsinst

MySQL : What are the best tools to automate users creation?MySQL : What are the best tools to automate users creation?May 08, 2025 am 12:22 AM

The best tools and technologies for automating the creation of users in MySQL include: 1. MySQLWorkbench, suitable for small to medium-sized environments, easy to use but high resource consumption; 2. Ansible, suitable for multi-server environments, simple but steep learning curve; 3. Custom Python scripts, flexible but need to ensure script security; 4. Puppet and Chef, suitable for large-scale environments, complex but scalable. Scale, learning curve and integration needs should be considered when choosing.

MySQL: Can I search inside a blob?MySQL: Can I search inside a blob?May 08, 2025 am 12:20 AM

Yes,youcansearchinsideaBLOBinMySQLusingspecifictechniques.1)ConverttheBLOBtoaUTF-8stringwithCONVERTfunctionandsearchusingLIKE.2)ForcompressedBLOBs,useUNCOMPRESSbeforeconversion.3)Considerperformanceimpactsanddataencoding.4)Forcomplexdata,externalproc

MySQL String Data Types: A Comprehensive GuideMySQL String Data Types: A Comprehensive GuideMay 08, 2025 am 12:14 AM

MySQLoffersvariousstringdatatypes:1)CHARforfixed-lengthstrings,idealforconsistentlengthdatalikecountrycodes;2)VARCHARforvariable-lengthstrings,suitableforfieldslikenames;3)TEXTtypesforlargertext,goodforblogpostsbutcanimpactperformance;4)BINARYandVARB

Mastering MySQL BLOBs: A Step-by-Step TutorialMastering MySQL BLOBs: A Step-by-Step TutorialMay 08, 2025 am 12:01 AM

TomasterMySQLBLOBs,followthesesteps:1)ChoosetheappropriateBLOBtype(TINYBLOB,BLOB,MEDIUMBLOB,LONGBLOB)basedondatasize.2)InsertdatausingLOAD_FILEforefficiency.3)Storefilereferencesinsteadoffilestoimproveperformance.4)UseDUMPFILEtoretrieveandsaveBLOBsco

BLOB Data Type in MySQL: A Detailed Overview for DevelopersBLOB Data Type in MySQL: A Detailed Overview for DevelopersMay 07, 2025 pm 05:41 PM

BlobdatatypesinmysqlareusedforvoringLargebinarydatalikeImagesoraudio.1) Useblobtypes (tinyblobtolongblob) Basedondatasizeneeds. 2) Storeblobsin Perplate Petooptimize Performance.3) ConsidersxterNal Storage Forel Blob Romana DatabasesizerIndimprovebackupupe

How to Add Users to MySQL from the Command LineHow to Add Users to MySQL from the Command LineMay 07, 2025 pm 05:01 PM

ToadduserstoMySQLfromthecommandline,loginasroot,thenuseCREATEUSER'username'@'host'IDENTIFIEDBY'password';tocreateanewuser.GrantpermissionswithGRANTALLPRIVILEGESONdatabase.*TO'username'@'host';anduseFLUSHPRIVILEGES;toapplychanges.Alwaysusestrongpasswo

What Are the Different String Data Types in MySQL? A Detailed OverviewWhat Are the Different String Data Types in MySQL? A Detailed OverviewMay 07, 2025 pm 03:33 PM

MySQLofferseightstringdatatypes:CHAR,VARCHAR,BINARY,VARBINARY,BLOB,TEXT,ENUM,andSET.1)CHARisfixed-length,idealforconsistentdatalikecountrycodes.2)VARCHARisvariable-length,efficientforvaryingdatalikenames.3)BINARYandVARBINARYstorebinarydata,similartoC

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft