Kiran P has Published 107 Articles

How to detect if a given year is a Leap year in Oracle?

Kiran P

Kiran P

Updated on 04-Dec-2020 11:00:47

4K+ Views

Problem:You need to determine if any given year is a leap year.Solution:There are numerous ways of solving this problem.These include calculations to determine whether February 29 exists in the year, or whether March 1 is the 61st or 62nd day of the year.ExampleSELECT to_number(to_char(sysdate, 'YYYY')) Year,   CASE     ... Read More

How to view storage configuration of Oracle database?

Kiran P

Kiran P

Updated on 04-Dec-2020 10:59:35

707 Views

Problem:You want to find out some indroductory information about the database.Solution:Every Oracle programmer/ DBA has at one point or another during their career inherited a database someone else have already set up.You needs to find out some introductory information about the database to learn more about it.Idenitfy the host details ... Read More

How to use Oracle aggregate function XMLAGG ?

Kiran P

Kiran P

Updated on 04-Dec-2020 10:54:05

14K+ Views

You want to use Oracle aggregate function XMLAGG for string aggregation.?Solution:ExampleSELECT class_id,   rtrim(xmlagg(xmlelement(x, first_name   || ' '   || last_name , ', ') ORDER BY first_name).extract('//text()').getstringval(), ', ') AS "names" FROM students GROUP BY class_id;OutputCL_MATH         ANDERSON DANIEL, MARTINEZ CHRISTOPHER, TAYLOR PAUL, THOMAS MARK, WILSON ... Read More

How to perform string aggregation/concatenation in Oracle?

Kiran P

Kiran P

Updated on 04-Dec-2020 10:52:16

5K+ Views

Problem Statement:You want to perform string concatenation as a comma delimited text in oracle.Solution:Oracle has few methods to perform string aggregation. The most common usuage you popularly find on internet is to convert multiple rows to a single row with a delimiter.Starting Oracle version 11.2, a new built-in function is ... Read More

How to assign ranks to the query results in Oracle?

Kiran P

Kiran P

Updated on 04-Dec-2020 10:51:05

734 Views

Problem Statement:You want to assign a number/rank representing their positions in the result.Solution:Oracle provides the RANK analytic function to generate a ranking number for rows in a result set. To demonstrate we will rank students by fees, from highest paid down. The following SELECT statement uses the rank function to ... Read More

How to cache query results in Oracle?

Kiran P

Kiran P

Updated on 04-Dec-2020 10:49:31

3K+ Views

Problem Statement:You want to improve the performance of frequently used queries.Solution:We have to use Oracle’s result cache to store the query results of frequently used SQL, so they can be retrieved quickly for future use when the same query has been executed.The result cache is new additon to Oracle 11g, ... Read More

How to optimize the INSERT statement using direct-path insert technique in Oracle?

Kiran P

Kiran P

Updated on 04-Dec-2020 10:46:58

3K+ Views

Problem Statement:You are performing a INSERT statement, and it is performing slower than needed. You want to optimize the INSERT statement.Solution:By using the APPEND or APPEND_VALUES hint with INSERT statement, we can significantly speed up the process of performing an insert operation on the database. Here is an example of ... Read More

How to perform Schema Registration and XML Validation in Oracle ?

Kiran P

Kiran P

Updated on 04-Dec-2020 10:45:21

2K+ Views

Problem Statement:You want to enforce XML schema validity on XML data stored in your database.Solution:Oracle provides the DBMS_XMLSCHEMA.REGISTERSCHEMA function to define XML schemas within the Oracle database. Inorder to validate the xml data generated, we need to register the schema. While registering the schema, the format must match the xml ... Read More

How to generate XML with nested values ?

Kiran P

Kiran P

Updated on 04-Dec-2020 10:43:13

2K+ Views

Problem Statement:You want to generate a complex XML document with nesting values at different levels.Solution: Oracle has quite a number of functions and procedures for generating XML from regular data. To demonstrate the usage, I will be using the studentdata. We will assume we would like to use the student_id ... Read More

How to extract Key XML Elements from an XML Document in Oracle?

Kiran P

Kiran P

Updated on 04-Dec-2020 10:42:05

7K+ Views

Problem Statement:You need to extract a portion/subset of elements values from an XML document.Solution:We can leverage Oracle’s EXTRACT function which supports XMLTYPE datatype. EXTARCT function provides the ability to preserve XML element name and attribute constructs by returning the results as an XMLTYPE value.Assume, we have below XML in a ... Read More

Previous 1 ... 4 5 6 7 8 ... 11 Next
Advertisements