Note that there are some explanatory texts on larger screens.

plurals
  1. POOracle: SQLPlus Query Concatenate Data With Headers
    primarykey
    data
    text
    <p>I'm trying to not only query different tables in my database and export them into a CSV, but also export data from multiple tables and concatenate them as columns into this CSV.</p> <p>I start with the premise of being able to spool the contents of a table into a CSV file:</p> <pre><code>set colsep ',' set echo off set feedback off set linesize 1000 set sqlprompt '' set headsep off spool file.csv select * from messages; </code></pre> <p>Now I want to grab certain components of multiple tables with no avail (with union and minus):</p> <pre><code>select col1, col2, col3 from messages union select col1, col2 from messagedata union select col1 from extradata; </code></pre> <p>In trying the above method, I'll get <code>ORA -1789 query block has incorrect number of result columns</code> meaning that I'm trying to match up the wrong number of columns (which I'm trying to avoid by just appending columns in my output).</p> <p>And given either <em>union</em> or <em>minus</em> it will error on the wrong datatype, but that being because it's just trying to append it to the columns from my first query.</p> <p>My goal there is to create a query that produces similar output: </p> <pre><code>| col1(messages) | ... | col2(messagedata) | ... | col3(extradata) | ----------------------------------------------------------------------- message ,... ,messagedata ,... ,extradata message ,... ,messagedata ,... ,extradata message ,... ,messagedata ,... ,extradata </code></pre> <p>So two questions:</p> <ul> <li><p>Is it possible for me to concatenate the data from multiple tables into a column output like above? As in create <em>new</em> columns to output instead of appending to existing columns?</p></li> <li><p>How might I give a header to my data (custom or already defined by the identifier in the table) at the top of the column?</p></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload