Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8735927
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:11:04+00:00 2026-06-13T10:11:04+00:00

I am trying to export some data using sqlplus and the Oracle spool functionality.

  • 0

I am trying to export some data using sqlplus and the Oracle spool functionality. The problem is that the SQL input file where I am defining my export is not letting me parameterize the table name from which I am exporting data — it wants a literal 🙁

Calling sqlplus in a shell script:

sqlplus $USER/$PASSWD@$ORADB<<!

@export.sql $OUT_FILE $SOME_VAR $ENV

exit
!

export.sql:

set heading off
set head off
set term off
set tab off
set embedded on
set feedback off
set pagesize 0
set linesize 800
set trimspool on
set verify off

spool &1

SELECT '&2|' || some_col
FROM &3_TABLE
/
spool off

When $ENV is set to ‘dev’, I get

Enter value for 3_TABLE 

whereas I want it to use dev_TABLE. When I unparameterize the table names in the sql file, the output runs fine. Also note that there is param &2, which is $SOME_VAR from the shell and it gets displayed evaluated fine. The only problem is in the FROM statement.

Is there any way to tell the sql input file to replace the parameterized table names before running SQL?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T10:11:05+00:00Added an answer on June 13, 2026 at 10:11 am

    The problem is that SQL*Plus is treating the whole string after the &, up to the next whitespace or simlar, as the substitution variable name. Clearly that isn’t what you want here.

    Fortunately they’ve thought of this, and you can denote the end of the variable name with a .:

    FROM &3._TABLE
    

    (At least, that works for named variables, and I’m almost sure it will for positional ones… if not then you’d need to define a new variable set to &3 as a workaround).

    It is in the documentation, but blink and you’ll miss it:

    If you wish to append characters immediately after a substitution
    variable, use a period to separate the variable from the character.


    There’s a related effect that you may want to bear in mind for the future. If the next character after the substitution variable is a . anyway – between the schema and table, or between table and column, for example – then that will be interpreted as the substitution terminator. Say you were passing the schema separately as &4, with value 'scott'; this:

    FROM &4.&3._TABLE
    

    looks reasonable but would be substituted as scottdev_TABLE, which won’t be recognised. So in that instance you need to have an extra one:

    FROM &4..&3._TABLE
    

    which would be substituted as scott.dev_TABLE.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to export some data from a SQL Express table to Access
I'm trying to transfer some old SQL Server data using Excel into SQL Server.
I need to export some data using SQL Server 2000's BCP utility. Sometimes my
I am using Oracle SQL Developer and trying to export a table to a
I'm trying to export from SQL Server to Oracle a table that consists of
I am trying to export some data to Excel. I am using OLEDB 12.
I am trying to export some data like the name of the user to
I'm trying to use the primefaces dataExporter to export some data and I have
I am trying to use SDO2SHP.exe in order to export some spatial data from
I am trying to create a csv file of some data. I have wrote

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.