-1

Input Excel/CSV:

enter image description here

SQL Query: -

select 'WWW' as COLUMN_NAME,
    (case when to_char (max(WWW)) = to_char(min(WWW)) and to_char(count(WWW)) = count(*) or to_char(max(WWW)) is null then 'same' else 'diff'end)as COMPARISION_VALUE, to_char(max(WWW))as TRANSACTION1, to_char(min(WWW))as TRANSACTION2 
from ABC 
where  Book ='123'  and UPDATE_DATE='01-JUN-18';

Note: - I am looking to put this SQL query in loop where first row will pass into the SQL query, then it will check the 2nd row, if the cell is blank it will consider the top most value and COLUMN_NAME will iterate as much we have specified. All the above 4 columns should be parameter.

***Output Console: -***
    COLUMN_NAME COMPARISION_VALUE   TRANSACTION1    TRANSACTION2
    WWW            same                test          test

Expected Output: - I want to save all the transaction in excel/CSV one by one

Please find the attached doc for complete Details

enter image description here

APC
  • 144,005
  • 19
  • 170
  • 281
Routray
  • 75
  • 1
  • 12

1 Answers1

0

Your question concatenates Excel/CSV as through they're the same thing. They are not. Excel is a very different thing from CSV. Consequently they are two different requirements.

Excel is a binary format which makes it hard to integrate with SQL (although there are third party libraries which can help). CSV is open and text-based, so it's a lot simpler. With an external table you can query a CSV using SQL. Find out more.

As for output, you've tagged your question [plsqldeveloper]. That is the tag for the Allround Automations IDE, which already has excellent capabilities for exporting to Excel or CSV. If you are using that tool you should not reinvent its features. Oracle SQL Developer also already does this (and I suspect TOAD and most of the other IDEs out there do too).

APC
  • 144,005
  • 19
  • 170
  • 281
  • 1
    Nitpicking: nowadays "Excel" is not a proprietary format any more. Microsoft published the format as an [ISO format](https://en.wikipedia.org/wiki/Standardization_of_Office_Open_XML). `XSLX` is essentially an XML format stored inside a ZIP container - but I do agree it's hard to integrate with SQL ;) –  Jul 23 '19 at 10:33
  • @APC, thanks for the comment, i have mentioned EXCEL or CSV, any should be fine..if excel is complicate i am fine with CSV as well. I am using SQL Developer. – Routray Jul 23 '19 at 10:36
  • so you need to read a file in CSV inside an Oracle database and do some queries based on some data? Can you do other example? – alvalongo Jul 23 '19 at 21:56
  • so you need to read a file in CSV inside an Oracle database and do some queries based on some data? Can you do other example? – alvalongo Jul 23 '19 at 21:56