Beruflich Dokumente
Kultur Dokumente
POPULAR RDBMS
ORACLE
Top seems easy enough to use and it’s not the part of the
ANSI standard for SQL. TOP is not used in Oracle’s language;
instead, there’s ROWNUM.
If you’re coming from SQL Server, ROWNUM doesn’t work as
you may expect. You can’t just replace TOP with ROWNUM.
Another point is that ROWNUM is assigned before the ORDER
BY so, you may want a derived table to get the top rows with
a sort.
SELECT table_nm FROM sys.all_tables WHERE rownum <= 30;
OR for a sorted list
SELECT table_nm FROM (SELECT table_nm FROM
sys.all_tables ORDER BY table_nm ) WHERE rownum <= 30;
Simple isn’t always better!
We can use SQL Server’s TOP operator but it’s only going to
give you the top number or percent. To get the next 5 or next
[n] you’ll have to use OFFSET clause that was introduced in
SQL Server 2012. This is called Pagination and is a very
important feature for web pages or applications that want to
paginate results.
To find the next [n] in Oracle is a breeze with ROWNUM. To
paginate with ROWNUM in Oracle you can simply use two
tables like the following example:
SELECT table_nm FROM (SELECT table_nm , rownum rnum
FROM (SELECT table_nm FROM sys.all_tables ORDER BY
table_nm ) WHERE rownum <= 20) WHERE rnum > 10;
SQL SERVER VS ORACLE: PAGINATION
Paging is a really important feature for web pages and
applications. Without it, you’d be passing large amounts of
data to the application and expecting the application code to
figure out which rows it needed to display.
Thankfully, someone smart came up with a way to do this on
the database so you’re not returning gigs and gigs of data to
the web server to sort through.
SQL SERVER
SQL server 2012 introduced OFFSET for pagination. Let’s
examine the code:
SELECT CustomerId, City, PostalCode
FROM Customer
ORDER BY CustomerId OFFSET 10 ROWS FETCH NEXT 5 ROWS
ONLY
An ORDER BY clause must be specified to use OFFSET. You can
choose to Fetch next [n] or not. Specifying the FETCH NEXT
[n] will limit the rows returned to [n] while using OFFSET
without a FETCH NEXT will only omit the first [n] rows your
offset by. In this case, 10 rows at the front would be ignored.
ORACLE
Paging in Oracle uses the ROWNUM function. ROWNUM is
also used for other tasks like getting the top [n] row. Let’s
examine the code:
SELECT table_nm FROM (SELECT table_nm, rownum rnum
FROM (SELECT table_nm FROM sys.all_tables ORDER BY
table_nm) WHERE rownum <= 20) WHERE rnum > 10;
This can easily be used by an application to programmatically
get the rows you want.
According to my opinion, the OFFSET FETCH feature of SQL
Server is much easier to use. No matter which you’re using
both have the same outcome!
SQL SERVER VS ORACLE: CONVERT STRING TO DATE
SQL SERVER
There are many ways to create a date from a string:
CONVERT()
1. CAST()
2. DATEFROMPARTS()
3. DATETIMEFROMPARTS()
4. DATETIME2FROMPARTS()
5. SMALLDATETIMEFROMPARTS()
6. TIMEFROMPARTS()
7. DATETIMEOFFSETFROMPARTS()
All the above-mentioned functions are used to create a date
from a string and you also have the ISDATE() function which
tests the value to be sure it’s a date.
CONVERT() is straightforward but there’s a catch. Let me
make it sound more clear through an example…
Let’s say you want to convert a string of “MMDDYY” to date.
SELECT CONVERT(date, ‘080902‘)
Result:
2008-09-02
This is the result you get whether you use the format
parameter or not. So now you’re stuck parsing this and
passing the values to one of the FROMPARTS functions to
build your date. This is where Oracle shines.
ORACLE
The TO_DATE() function in Oracle allows a date format to be
passed. BY TO_DATE() function making date conversion really
easy. Let’s see it in action.
SELECT to_date(‘070902’, ‘mmddyy’) FROM dual;
Result:
09-JUL-02
In TO_DATE() function we can pass a date format the types of
strings.So we can pass to the TO_DATE() functions are near
endless. How about ‘‘HHMMIIDDSSYYYY’’?
SELECT to_date(‘02073908532010’, ‘mmddyy’) FROM dual;
Result:
08-JUL-10
Clearly, you’d be placed on some sort of medication if you
were storing your dates in HHMMMIDDSSYYYY string format,
but the greatness that comes out of this is that no matter the
format you can convert to a date as long as you know the
pattern.
CONCLUDING WORDS
Composing the above has helped me understand that there is
in fact not a great deal of difference between SQL Server and
Oracle these days, as far as the functionality that they offer.
They may utilize diverse terminology to portray certain pieces
of functionality. Throughout the years as one supplier has
presented another component the other supplier has
actualized a comparable arrangement of usefulness into their
product. The features have distinctive names in each product,
so it’s not generally simple to see that same functionality
exists; however, for the most part, it’s conceivable to
accomplish a similar functionality on each database platform.
Connect with source url:-
https://www.loginworks.com/blogs/microsoft-sql-server-
vs-oracle-comparison-popular-rdbms/