How to convert Oracle queries to SQL Server

Source: Internet
Author: User
When converting an oracle query to an SQL Server, you must be careful about some issues that are not easy to notice. We know that T-SQL is from SQL Server Language The Oracle language engine is PLSQL.

ANSI SQL-92 standards are extended to provide additional support. The application you created Program Almost all of these complementary features are used. This article describes the most common and non-standard Oracle extensions.

Convert these extensions for use in the SQL server environment.

Column Selection

Use PLSQL Run When querying data, the from clause is required, which is the same as that of SQL Server. The SELECT statement must select the target data table. In the Oracle database, there is a special table dual. Dual

Oracle is created together with the data dictionary. All users can access the table with the name dual. There is only one dummy column in this table, which is defined as the varchar2 (1) type and has a row of value x.

Selecting data from the dual table is often used to calculate the constant expression through the SELECT statement. Because dual only has one row of data, the constant is returned only once.

The dual query in Oracle is as follows:

Select 'x' from dual

The equivalent SQL Server Query looks like this:

Select 'x'

Connection

Oracle uses | as the connector, while SQL server uses the plus sign: +.

The Oracle query is as follows:

Select 'name' | 'last name'

From tablename

The corresponding SQL Server query is as follows:

Select 'name' + 'last name'

   Number Trade-offs

Oracle Database has a trunc function, which returns n digits of the M-bit decimal number. If M is omitted, n is 0 digits. The m value can be negative, indicating that the M digit on the left of the decimal point is truncated.

In SQL Server, you can use round or floor.

Oracle query:

Select trunc (15.79, 1) "truncate" from dual;

The following are SQL Server versions of similar queries:

Select round (15.79, 0) rounded,

Round (15.79,) truncated

Select floor (round (15.79, 0 )),

Floor (round (15.79 ))

When converting an oracle query to an SQL Server, you must be careful about some issues that are not easy to notice. We know that T-SQL is the language engine of SQL Server, while Oracle's language engine is PLSQL.

ANSI SQL-92 standards are extended to provide additional support. The Application Almost all programs use these complementary features. This article describes the most common and non-standard Oracle extensions.

Convert these extensions for use in the SQL server environment.

Column Selection

When PLSQL is used to perform data queries, the from clause is required, which is the same as that of SQL Server. The SELECT statement must select the target data table. In the Oracle database, there is a special table dual. Dual

Oracle is created together with the data dictionary. All users can access the table with the name dual. There is only one dummy column in this table, which is defined as the varchar2 (1) type and has a row of value x.

Selecting data from the dual table is often used to calculate the constant expression through the SELECT statement. Because dual only has one row of data, the constant is returned only once.

The dual query in Oracle is as follows:

Select 'x' from dual

The equivalent SQL Server Query looks like this:

Select 'x'

Connection

Oracle uses | as the connector, while SQL server uses the plus sign: +.

The Oracle query is as follows:

Select 'name' | 'last name'

From tablename

The corresponding SQL Server query is as follows:

Select 'name' + 'last name'

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.