当前位置: 技术问答>java相关
高分求解不同数据库(如SQL Server、Oracle等)中SQL语句的区别。可加分!!!
来源: 互联网 发布时间:2015-07-28
本文导语: 我想详细了解一下在不同的数据库中,以SQL Server、Oracle、DB2为例,在使用SQL语句时是否有区别,区别主要在哪里,请举例说明(即使是微小区别),希望大家不吝赐教!可加分求解。谢谢! | ...
我想详细了解一下在不同的数据库中,以SQL Server、Oracle、DB2为例,在使用SQL语句时是否有区别,区别主要在哪里,请举例说明(即使是微小区别),希望大家不吝赐教!可加分求解。谢谢!
|
SELECT statements语句:
Oracle和Microsoft SQL Server用的SELECT语句的语法是类似的。
ORACLE:
SELECT [/*+ optimizer_hints*/]
[ALL | DISTINCT] select_list
[FROM
{table_name | view_name | select_statement}]
[WHERE clause]
[GROUP BY group_by_expression]
[HAVING search_condition]
[START WITH … CONNECT BY]
[{UNION | UNION ALL | INTERSECT |
MINUS} SELECT …]
[ORDER BY clause]
[FOR UPDATE]
SQL SERVER:
SELECT select_list
[INTO new_table_]
FROM table_source
[WHERE search_condition]
[ GROUP BY [ALL] group_by_expression [,…n]
[ WITH { CUBE | ROLLUP } ]
[HAVING search_condition]
[ORDER BY order_expression [ASC | DESC] ]
In addition:
UNION Operator
COMPUTE Clause
FOR BROWSE Clause
OPTION Clause
INSERT语句
Oracle和Microsoft SQL Server用的INSERT语句的语法是类似的。
Oracle:
INSERT INTO
{table_name | view_name | select_statement} [(column_list)]
{values_list | select_statement}
Microsoft SQL SERVER
INSERT [INTO]
{
table_name [ [AS] table_alias] WITH ( […n])
| view_name [ [AS] table_alias]
| rowset_function_limited
}
{ [(column_list)]
{ VALUES ( { DEFAULT
| NULL
| expression
}[,…n]
)
| derived_table
| execute_statement
}
}
| DEFAULT VALUES
UPDATE语句:
Transact-SQL支持Oracle的UPDATE绝大多数语法
Oracle:
UPDATE
{table_name | view_name | select_statement}
SET [column_name(s) = {constant_value | expression | select_statement | column_list |
variable_list}
{where_statement}
Microsoft SQL SERVER
UPDATE
{
table_name [ [AS] table_alias] WITH ( […n])
view_name [ [AS] table_alias]
| rowset_function_limited
}
SET
{column_name = {expression | DEFAULT | NULL}
| @variable = expression
| @variable = column = expression } [,…n]
{{[FROM {} [,…n] ]
[WHERE
] }
|
[WHERE CURRENT OF
{ { [GLOBAL] cursor_name } | cursor_variable_name}
] }
[OPTION ( [,…n] )]
DELETE语句:
Oracle:
DELETE [FROM]
{table_name | view_name | select_statement}
[WHERE clause]
Microsoft SQL SERVER
DELETE
[FROM ]
{
table_name [ [AS] table_alias] WITH ( […n])
| view_name [ [AS] table_alias]
| rowset_function_limited
}
[ FROM {} [,…n] ]
[WHERE
{
| { [ CURRENT OF
{
{ [ GLOBAL ] cursor_name }
cursor_variable_name
}
]
}
]
[OPTION ( [,…n])]
Oracle和Microsoft SQL Server用的SELECT语句的语法是类似的。
ORACLE:
SELECT [/*+ optimizer_hints*/]
[ALL | DISTINCT] select_list
[FROM
{table_name | view_name | select_statement}]
[WHERE clause]
[GROUP BY group_by_expression]
[HAVING search_condition]
[START WITH … CONNECT BY]
[{UNION | UNION ALL | INTERSECT |
MINUS} SELECT …]
[ORDER BY clause]
[FOR UPDATE]
SQL SERVER:
SELECT select_list
[INTO new_table_]
FROM table_source
[WHERE search_condition]
[ GROUP BY [ALL] group_by_expression [,…n]
[ WITH { CUBE | ROLLUP } ]
[HAVING search_condition]
[ORDER BY order_expression [ASC | DESC] ]
In addition:
UNION Operator
COMPUTE Clause
FOR BROWSE Clause
OPTION Clause
INSERT语句
Oracle和Microsoft SQL Server用的INSERT语句的语法是类似的。
Oracle:
INSERT INTO
{table_name | view_name | select_statement} [(column_list)]
{values_list | select_statement}
Microsoft SQL SERVER
INSERT [INTO]
{
table_name [ [AS] table_alias] WITH ( […n])
| view_name [ [AS] table_alias]
| rowset_function_limited
}
{ [(column_list)]
{ VALUES ( { DEFAULT
| NULL
| expression
}[,…n]
)
| derived_table
| execute_statement
}
}
| DEFAULT VALUES
UPDATE语句:
Transact-SQL支持Oracle的UPDATE绝大多数语法
Oracle:
UPDATE
{table_name | view_name | select_statement}
SET [column_name(s) = {constant_value | expression | select_statement | column_list |
variable_list}
{where_statement}
Microsoft SQL SERVER
UPDATE
{
table_name [ [AS] table_alias] WITH ( […n])
view_name [ [AS] table_alias]
| rowset_function_limited
}
SET
{column_name = {expression | DEFAULT | NULL}
| @variable = expression
| @variable = column = expression } [,…n]
{{[FROM {} [,…n] ]
[WHERE
] }
|
[WHERE CURRENT OF
{ { [GLOBAL] cursor_name } | cursor_variable_name}
] }
[OPTION ( [,…n] )]
DELETE语句:
Oracle:
DELETE [FROM]
{table_name | view_name | select_statement}
[WHERE clause]
Microsoft SQL SERVER
DELETE
[FROM ]
{
table_name [ [AS] table_alias] WITH ( […n])
| view_name [ [AS] table_alias]
| rowset_function_limited
}
[ FROM {} [,…n] ]
[WHERE
{
| { [ CURRENT OF
{
{ [ GLOBAL ] cursor_name }
cursor_variable_name
}
]
}
]
[OPTION ( [,…n])]
|
他们的数据类型定义有所不同。
各个数据库都支持一些非标准的sql。
举例,oracle插入timedate类型的数据,需要to_date('2002-08-01','yyyy-MM-dd')
各个数据库都支持一些非标准的sql。
举例,oracle插入timedate类型的数据,需要to_date('2002-08-01','yyyy-MM-dd')