Ask Your Question
0

What is the procedure for making multiple lines horizontal in Oracle?

asked 2022-09-01 11:00:00 +0000

plato gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2022-11-28 20:00:00 +0000

bukephalos gravatar image

In Oracle, there are different ways to make multiple lines horizontal. One way is to use the PIVOT function, which rotates rows into columns. Here's a procedure using the PIVOT function:

  1. Use the SELECT statement to gather the data needed for the result set.
  2. Use the PIVOT function with the required column set and the aggregation function to convert values from multiple rows into horizontal columns.
  3. Alias the resulting columns as needed to make them easier to understand and use.
  4. Use the WHERE clause to filter the data if necessary.
  5. Order the result set using the ORDER BY clause if needed.

For example, suppose you have a table named "sales" with columns "region," "product," and "sales_amount." To pivot the data and make the regions horizontal, you can use the following query:

SELECT * FROM ( SELECT region, product, salesamount FROM sales ) PIVOT ( SUM(salesamount) FOR region IN ('North' AS "North", 'South' AS "South", 'East' AS "East", 'West' AS "West") ) ORDER BY product;

This query selects the columns needed for the result set, pivots the rows to columns using the PIVOT function, and aliases the resulting columns with the corresponding region name. Finally, the result set is sorted by product.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-09-01 11:00:00 +0000

Seen: 9 times

Last updated: Nov 28 '22