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 8860041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:11:29+00:00 2026-06-14T15:11:29+00:00

Is there a way to set default value of paramter in sqlplus script without

  • 0

Is there a way to set default value of paramter in sqlplus script without user input?

For example, I have an SQL script sessions.sql:

SET VERIFY OFF
SET TERMOUT OFF
DEFINE uname = '&1'

COLUMN search_uname new_value search_uname
SELECT CASE WHEN '&uname' = '' THEN '%' ELSE UPPER('&uname') END AS search_uname 
FROM dual;

SET TERMOUT ON

SELECT sid, serial, username FROM v$session WHERE username LIKE '&search_uname';

And I want to invoke it from sqlplus like this:

SQL> @sessions
Enter value for 1:

       SID    SERIAL# USERNAME
---------- ---------- ------------------------------
    56  20577 CONTEXT
.....
236 rows selected.

SQL> @sessions ""

       SID    SERIAL# USERNAME
---------- ---------- ------------------------------
    56  20577 CONTEXT
.....
236 rows selected.

SQL> @sessions SDE

       SID    SERIAL# USERNAME
---------- ---------- ------------------------------
       113  56675 SDE
       165  64881 SDE
.....
43 rows selected.

SQL> 

I can only pass an empty value for parameter when I am asked to enter it, or I am able to pass an empty parameter after script name through “”. But this behaviour is very annoying. Some kind of IF DEFINED “&1” will be very usefull.

Do you have any tips or tricks how this should be achieved to apply WHERE conditions in sqlplus script wheter parameter is defined or not without unnecessary user interaction?

Solution

According to the article linked by Martin I modified previous script to be working without aksing for parameter values:

SET VERIFY OFF
SET TERMOUT OFF

column 1 new_value 1
SELECT '' "1" FROM dual WHERE ROWNUM = 0;
define uname = '&1'

SET TERMOUT ON

SELECT sid, serial#, username FROM v$session 
WHERE username LIKE UPPER(DECODE('&uname', '', '%', '&uname'));

undefine 1
  • 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-14T15:11:30+00:00Added an answer on June 14, 2026 at 3:11 pm

    Please read "On SQL*Plus Defines" for an answer to your question.

    Quote:

    SQL> COLUMN 1 NEW_VALUE 1
    SQL> COLUMN 2 NEW_VALUE 2
    SQL> COLUMN 3 NEW_VALUE 3
    SQL> COLUMN 4 NEW_VALUE 4
    SQL> SELECT '' "1", '' "2", '' "3", '' "4"
      2    FROM dual
      3   WHERE ROWNUM = 0
      4  /
    
    no rows selected
    
    SQL> DEFINE 1
    DEFINE 1               = "1" (CHAR)
    SQL> DEFINE 2
    DEFINE 2               = "2" (CHAR)
    SQL> DEFINE 3
    DEFINE 3               = "" (CHAR)
    SQL> DEFINE 4
    DEFINE 4               = "" (CHAR)
    SQL> 
    SQL> REM ...but...
    SQL> 
    SQL> DEFINE 5
    SP2-0135: symbol 5 is UNDEFINED
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way to set the default value for a column as an
Is there a way to set a default value on a parameter that was
Is there a way to set the default value of a column to DateTime.Now
On colModel, is there any way to set the default value if the result
Is there an easy way to set a default value for text form field?
Is there any way that can I set default value as Empty.string in Model.
Is there a way to set a default category for tt_news, in such a
Is there a way to set up default function arguments with variables in them
By any chance, is there any easy way to set a default MasterView for
Is there a way to have a default parameter passed to a action in

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.