SQL字符串日期处理.doc
来源:互联网 发布:爱看电视直播软件 编辑:程序博客网 时间:2024/04/29 15:27
Table 8.2. Commonly Used Text-Manipulation Functions | |
Function | Description |
LEFT() (or use substring function) | |
LENGTH() (also DATALENGTH() or LEN()) | |
LOWER() | |
LTRIM() (LCASE() if using Access) | |
RIGHT() (or use substring function) | |
RTRIM() | |
SOUNDEX() | |
UPPER() (UCASE() if using Access) |
SELECT cust_name, cust_contact
FROM Customers
WHERE SOUNDEX(cust_contact) = SOUNDEX('Michael Green');
日期转换
SELECT order_num
FROM Orders
WHERE DATEPART(yy, order_date) = 2004;
In Access use this version:
SELECT order_num
FROM Orders
WHERE DATEPART('yyyy', order_date) = 2004;
Here is the PostgreSQL version that uses a similar function named DATE_PART():
SELECT order_num
FROM Orders
WHERE DATE_PART('year', order_date) = 2004;
MySQL has all sorts of date manipulation functions, but not DATEPART(). MySQL users can use a function named YEAR() to extract the year from a date:
SELECT order_num
FROM Orders
WHERE YEAR(order_date) = 2004;
Oracle has no DATEPART() function either, but there are several other date manipulation functions that can be used to accomplish the same retrieval. Here is an example:
SELECT order_num
FROM Orders
WHERE to_number(to_char(order_date, 'YY')) = 2004;
SELECT order_num
FROM Orders
WHERE order_date BETWEEN to_date('01-JAN-2004')
AND to_date('31-DEC-2004');
In this example, Oracle's to_date() function is used to convert two strings to dates. One contains the date January 1, 2004, and the other contains the date December 31, 2004. A standard BETWEEN operator is used to find all orders between those two dates. It is worth noting that this same code would not work with SQL Server because it does not support the to_date() function. However, if you replaced to_date() with DATEPART(), you could indeed use this type of statement.
Table 8.3. Commonly Used Numeric Manipulation Functions | |
Function | Description |
ABS() | |
COS() | |
EXP() | |
PI() | |
SIN() | |
SQRT() | |
TAN() |
Refer to your DBMS documentation for a list of the supported mathematical manipulation functions
- SQL字符串日期处理.doc
- SQL日期处理、短日期
- SQL 日期字符串
- SQL 日期处理
- SQL 中的日期处理
- SQL:数据库日期处理
- sql日期处理
- sql日期处理
- SQL日期处理方法
- SQL常用日期处理
- SQL日期处理函数
- oracle sql 日期处理
- SQL:数据库日期处理
- SQL日期处理
- SQL时间/日期处理
- sql日期处理
- SQL时间日期处理
- sql server 日期处理
- WinXP最新应用技巧十则
- [VB.NET]浅谈MDI窗体的多窗体编程
- 世界上最美的十条路
- SQL存储过程
- 将ASP生成的报表导出到EXCEL文件
- SQL字符串日期处理.doc
- C++程序员如何用D编程
- 网页上贴代码的格式
- 计算机端口详解zt
- 如何列举网络中的SQL-Server服务器
- 中国二十五首必听的网络原创歌曲
- 一个不大注意的小错误
- 分享:Hierarchy Datagrid 解决方案 (转)
- Hibernate、iBATIS 与 BLOB