SQL*PLUS: Setting a concrete RETURN CODE

I don't know how to force a concrete EXIT CODE for in a SQL*PLUS process.
I use "WHENEVER SQLerror EXIT SQL.SQLCODE" and a "EXIT SQL.SQLCODE;" at the end of the process.
But I need to be able to exit the process with a sqlcode "54" or "23" or whatever I want...
Any suggestions?
WHENEVER SQLerror EXIT SQL.SQLCODE
DECLARE
BEGIN
END;
EXIT SQL.SQLCODE;
-------------------------------------------------------

You can just do EXIT n to exit with integer return code n.
$ sqlplus dqm
SQL*Plus: Release 10.2.0.3.0 - Production on Mon Jan 11 11:48:46 2010
Copyright (c) 1982, 2006, Oracle.  All Rights Reserved.
Enter password:
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
SQL> exit 54
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
$ echo $?
54

Similar Messages

  • Preference equivalents for relevant SQL*Plus set commands?

    I know that the SQL*Plus set command is not supported in Raptor (as per http://www.oracle.com/technology/products/database/project_raptor/sql_worksheet_commands.html), but there are a number of set options that are relevant.
    For example, set define (for which "set define off" is covered in Ampersand in scripts We have a number of existing SQL scripts where we have set the define character to something apart from & to avoid issues where this is a required value in the code.
    Setting server output size is another option - as per set serveroutput on size unlimited .
    Is there any proactive plan to provide preferences equivalent to the set options that are relevant (to either SQL scripts or the various output tabs)? Or is the exclusion of the SQL*Plus set command only for the current version and it will be included later? From the discussion on the forums so far, it seems as though you are looking at each set option as it is raised, rather than being proactive about it.
    Even if Raptor does provide preferences, it would still be useful for the equivalent set commands to work. Lets say that we do get a preference for the define character - 99% of the time, scripts want this to be & - however there are some where the script wants it to be $ (or whatever). With a preference, I need to know what the script wants and change the preference before running the script and then change it back afterwards.

    Hi Turloch,
    When is this script executed ?
    In 3.1EA2 I created a sql script where a variable is defined and set this script as you suggested.
    Script:
    define varname=abc
    When I open a connection, a worksheet is automatically opened. I run this statements:
    select '&varname' from dual;
    define varname=xyz
    select '&varname' from dual;
    Running the first select statement results in a popup window for entering a value for the substitution variable, while I was expecting the value abc as the result of the query.
    See also this blog where the login script is explained.
    But in my SQL Developer 3.1EA2 64-bit on Windows 7 it doesn't work like that.
    Is this a bug?
    Dennis

  • W'azup with SQL Developer barfing on SQL*Plus "set" commands

    Check out this short script and the results it generates, as pasted below.
    I can't find anything in the SQL Dev documenation re: what SQL*Plus set commands it supports and which it considers "passe." I'm particularly puzzled by the "column ... format ..." command getting ignored.
    set heading off
    set pagesize 0
    set linesize 80
    set feedback off
    prompt ...start...
    column x format a5
    select 'abcdefghij' x from dual;
    prompt ...end...
    line 1: SQLPLUS Command Skipped: set heading off
    line 2: SQLPLUS Command Skipped: set pagesize 0
    line 3: SQLPLUS Command Skipped: set linesize 80
    ...start...
    X ----------
    abcdefghij 1 rows selected
    ...end...

    For supported SQL*Plus commands: SQL Developer Help > SQL Developer Concepts and Usage > Using the SQL Worksheet > SQL*Plus Statements Supported and Not Supported in SQL Worksheet.
    The "column ... format ...." command is not supported. A workaround is to use substr in your select statement.
    See also How to set a column size in sqldeveloper?

  • Display TTITLE in SQL*Plus when no rows returned

    I need a SQL*Plus query that would display the TTITLE with Date. My query looked like this at first:
    column TODAY noprint NEW_VALUE p_date
    set feedback off
    select to_char(sysdate, 'mm/dd/yyyy') today from dual;
    set feedback on
    ttitle left 'query.sql' -
    center 'Department Listing ' -
    right 'Date: ' p_date skip 1
    select dept_code, dept_name
    from department
    where dept_code between 200 and 300
    When I run this query, if there's data returned, the title would display on every page.
    When there's no rows selected, the title would NOT display.
    So I moved the ttitle statements to ABOVE the select date section. When there's no rows selected the title would be displayed, where there's data selected, the title would be display TWICE on the first page which is very annoying.
    Then I added TTITLE OFF after the select date section and the query looked like this:
    column TODAY noprint NEW_VALUE p_date
    ttitle left 'query.sql' -
    center 'Department Listing ' -
    right 'Date: ' p_date skip 1
    set feedback off
    select to_char(sysdate, 'mm/dd/yyyy') today from dual;
    set feedback on
    ttitle off
    select dept_code, dept_name
    from department
    where dept_code between 200 and 300
    when no rows selected, the title displayed.
    when rows selected, the title displayed, ONLY ON THE FIRST PAGE.
    Does anyone have any creative ideas to get the ttitle to display: with or without return results, ONCE and on EVERY page?
    Thanks in advance!!!
    Jane

    Hi Jane,
    Just check out this answer might helps u.
    In the final code what u have written u placed the ttitle off above the sql statement for dept.
    Just note these points
    1.U r telling the TTITLE OFF before SQL For Department
    2.In both cases(With Data/Without Data) u r able to see the title once that is of select statement for date.
    so there is no title for Select statement for department
    What ur code telling is U have written a TTITLE that is for Selection of Date not for the Selection of department.
    So in both cases u r getting the title once.
    Put the TTITLE OFF at the end that is after Select stmt of department
    then u will get title for each page.
    In the first Script u told that it is displaying twice(annoying)
    It will display like that only coz there are two select statements in ur Script.
    TTITLE means it will display once on each page per query.
    one is for select statement of date(it will display once because that query result is max of one line)
    second is for select statement for Department(it will display one title in each page)
    so u will find two titles on first page.
    Hope this will clear u
    Revert back for any more clarifications
    Regards
    Kiran

  • How to exit from SQL*Plus based on the return value of a SQL select stment?

    Hi
    I have a SQL script executed from SQL*Plus. I would like to know if SQL*Plus
    supports any kind of branching or exiting from script execution based on a
    returned value of a SQL select statement. I am on 9i.
    Regards,
    Tamas Szecsy

    in sqlplus, you have whenever
    ex:
    whenever sqlerror exit failure
    insert into ...
    -- if this fails, then you will be out
    insert into ...
    -- if this fails, then you will be out
    whenever sqlerror continue
    insert into ...
    -- if this fails, this continues
    insert into ...and you have PL/SQL
    declare x number;
    begin
    select count(*) into x from emp;
    if (x=14) then null; end if;
    end;
    /note that you can mix those in some case
    -- exit if there is no row in emp
    whenever sqlerror exit 1
    var dummy number
    exec select count(*) into :dummy from emp having count(*)!=0

  • SQL * PLUS - setting wrap on for column

    hi all, i am playing around with sql plus and i encountered the following problem.
    1) is length 10 the default column length for columns with number datatype in sqlplus, i done a select statement and all my column for number have a length of 10
    2) why cant i format the length of a number column. i type column empno format 999
    although my numbers become #### but "empno" and a length of 10 is still shown at the column name instead of just "emp"
    3) how come a column name canot be wrapped
    when i set wrap on.
    set wrap on
    column ename format a3
    only the values of ename are wrap
    but the column name "ename" isnt wrap
    into ena
    me
    thanks.

    Some examples :
    TEST@db102 > select 1234567890123 from dual;
    1234567890123
       1.2346E+12
    TEST@db102 > set numwidth 15
    TEST@db102 > /
      1234567890123
      1234567890123
    TEST@db102 > col ename for a3 wrapped
    TEST@db102 > select ename from emp where empno=7902;
    ENA
    FOR
    D
    TEST@db102 > You can find everything in the documentation

  • Sql Plus  Setting where It must  searching Scripts

    Hi
    How can I to define inside Sql Plus with command , where It must search scripts
    Why when I put :
    @myscript.sqland inside there is other scripts, It not found
    unable to open file "CONTIG_PS_LOC_ITM_TYPE.SQL"CONTIG_PS_LOC_ITM_TYPE.SQL is in same directory myscript.sql

    Hey
    inside the your first script you can execute the second one as "@@CONTIG_PS_LOC_ITM_TYPE.SQL"
    for the first script you can give the absolut path or the default path is $ORACLE_HOME/rdbms...
    Regards

  • SQL Plus: Set pagesize and line size

    Can anyone help me make my output look better...... output below....what do I need to set?
    CUST_ID
    CUS_NAME
    1
    Leroy
    2
    Rama
    3
    Riley
    4
    Adena
    5
    Stuart
    6
    Jena
    7
    Tanisha
    8
    Shellie
    9
    Ignacia
    10
    Reuben

    btw you can use ** tags for preserving formatting code and results in this forum. See the FAQ for more formatting help.                                                                                                                                                                                                                                                           

  • COPY command in SQL*Plus 8.1.6 returns ORA-65535

    The COPY command in the windows version of SqlPlus (SQLPLUSW) does not work any more. I get the following error
    << Array fetch/bind size is 5. (arraysize is 5)
    Will commit after every array bind. (copycommit is 1)
    Maximum long size is 80. (long is 80)
    ERROR:
    ORA-65535: Message 65535 not found; product=RDBMS; facility=ORA >>
    Interestingly, I can run the same COPY command successfully if I use SQLPLUS.exe ( the command line version ). No error & it completes the copy.
    I recently changed my Oracle client from 7.3 to v8.1.6.
    I had not encountered this problem with the same command in v7.3.

    You may have run into bug 1504702. As a workaround you will need to use command line, as you've already figured out. I don't think a patch is available for Windows yet, although there is for Solaris (in the 8.1.7.4 patch set).
    Alison

  • SQL PLUS set column output side by side

    I am trying to match my colum data with my row so when i query the data at least its readable side by side inside of top and bottom
    cus_id
    cus_name
    999996
    Allen
    999997
    Cameran
    I want the ouput to look like this
    cus-id cus_name
    999996 Allen
    999997 Cameran
    thanks
    Edited by: user11232525 on Dec 10, 2009 10:37 AM

    i tried that the the ouput this look messy - see below
    CUS_ID
    CUS_NAME
    999901
    Eaton
    999902
    Lane
    999903
    Cody
    thanks

  • SQL Plus giving SP2-0024: Nothing to change error

    I'm just about to lose my mind.
    I'm running the following in SQL Plus -
    set echo off
    set feedback off
    set linesize 1000
    set sqlprompt ''
    spool c:\TEMP2\App_Eng1.csv replace
    Select A.OBJECTOWNERID||','||B.OBJECTVALUE1 from PSPROJECTITEM B, PSAEAPPLDEFN A
    Where B.PROJECTNAME = 'PRJ732075'
    and B.SOURCESTATUS = 2
    and B.TARGETSTATUS = 1
    and B.OBJECTVALUE2 = ' '
    and B.OBJECTTYPE=33
    and A.AE_APPLID = B.OBJECTVALUE1
    spool off
    and I get the following in return -
    SQL> set echo off
    SQL> set feedback off
    SQL> set linesize 1000
    SQL> set sqlprompt ''
    spool c:\TEMP2\App_Eng1.csv replace
    SP2-0024: Nothing to change.
    Select A.OBJECTOWNERID||','||B.OBJECTVALUE1 from PSPROJECTITEM B, PSAEAPPLDEFN A
    2 Where B.PROJECTNAME = 'PRJ732075'
    3 and B.SOURCESTATUS = 2
    4 and B.TARGETSTATUS = 1
    5 and B.OBJECTVALUE2 = ' '
    6 and B.OBJECTTYPE=33
    7 and A.AE_APPLID = B.OBJECTVALUE1
    8
    spool off
    SP2-0042: unknown command "off" - rest of line ignored.
    Why am I getting these errors?
    Also, when I clear the SQL, rerun the SQL and try to open the App_Eng1.csv file
    I get a window telling me the file is locked. The only way for me to unlock the file is to shutdown the SQL Plus window. Why is this?
    All I am trying to do is to download data from an Oracle table to an Excel spreadsheet. Is there a relatively easy way to do this using SQL Developer code or should I continue to fight with SQL Plus? I'm trying to automate a process so I don't want to use the manual steps like the DTS Import by Excel.
    Any help? Please?

    Thanks for the info. I have another issue. I'm not sure that my Spool Off command is being recognized. Here's the script I'm running -
    set echo off
    set feedback off
    set linesize 1000
    set sqlprompt ''
    SELECT COUNT(*) FROM PSPROJECTITEM;
    spool c:\TEMP2\App_Eng1.csv replace
    Select A.OBJECTOWNERID||','||B.OBJECTVALUE1
    from PSPROJECTITEM B, PSAEAPPLDEFN A
    Where B.PROJECTNAME = 'PRJ732075'
    and B.SOURCESTATUS = 2
    and B.TARGETSTATUS = 1
    and B.OBJECTVALUE2 = ' '
    and B.OBJECTTYPE=33
    and A.AE_APPLID = B.OBJECTVALUE1;
    spool off
    Most of the time the App_Eng1.csv file is telling me that it can't be opened because it's being used by another user, even after I close SQL Plus. I have to physically perform the Spool Off command from the menu. But even then the csv file is blank. Any ideas?

  • Return code 139

    Hi i am executingthe below script in unix:
    sqlplus -s ${SQL_USERID} <<EOF
    whenever sqlerror exit sql.sqlcode
    begin
    UPDATE statement
    end;
    EOF
    rc=$?
    echo $rc
    i am getting the return code as 139.
    What does it mean?
    How to make the query to be successful?
    Thanks

    My wild guess would be:
    ORA-00907: missing right parenthesis
    Whose idea was it to return sql.sqlcode though? The return code of Unix commands is an 8 bit number and can only go up to 255 (i.e. binary 11111111), which is fine for distinguishing between 0 (success) and 1 (failure) etc, after which it wraps around to 0 again. This means your 139 is mod(actual_error_code,256), and my guess is 907:
    $> sqlplus username/pass
    SQL*Plus: Release 11.2.0.1.0 Production on Thu Jun 2 18:59:41 2011
    Copyright (c) 1982, 2010, Oracle.  All rights reserved.
    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    SQL> select (1 from dual;
    select (1 from dual
    ERROR at line 1:
    ORA-00907: missing right parenthesis
    SQL> exit sql.sqlcode
    Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    $> print $?
    139Just for fun, here are the valid error codes that could give you 139:
    begin
       for r in (
          select rownum as oracle_error
               , mod(rownum,256) as return_code
               , cast(null as varchar2(200)) as message
          from   dual
          connect by rownum <= 20000
       loop
          if r.return_code = 139 then
             r.message := sqlerrm(r.oracle_error * -1);
             if r.message not like 'ORA-%: Message ' || r.oracle_error || ' not found;%' then
                dbms_output.put_line(r.message);
             end if;
          end if;
       end loop;
    end;
    ORA-00139: duplicate attribute
    ORA-00395: online logs for the clone database must be renamed
    ORA-00907: missing right parenthesis
    ORA-01163: SIZE clause indicates  (blocks), but should match header
    ORA-01419: datdts: illegal format code
    ORA-01675: max_commit_propagation_delay inconsistent with other instances
    ORA-01931: cannot grant  to a role
    ORA-02187: invalid quota specification
    ORA-02443: Cannot drop constraint  - nonexistent constraint
    ORA-03211: The segment does not exist or is not in a valid state
    ORA-06027: NETASY: channel close failure
    ORA-06539: target of OPEN must be a query
    ORA-07563: sldext: $PARSE failure
    ORA-08331: Wait operation timed out
    ORA-10635: Invalid segment or tablespace type
    ORA-10891: disable column pruning in ANSI join transformation
    ORA-12171: TNS:could not resolve connect identifier:
    ORA-12427: invalid input value for  parameter
    ORA-12683: encryption/crypto-checksumming: no Diffie-Hellman seed
    ORA-13195: failed to generate maximum tile value
    ORA-13451: GeoRaster metadata scaling function error
    ORA-13707: Either the start snapshot  or the end snapshot  is incomplete or missing key statistics.
    ORA-15243:  is not a valid version number
    ORA-16011: Remote File Server process is in Error state.
    ORA-16267: Cannot instantiate a Logical Standby during a switchover
    ORA-16523: operation requires the client to connect to instance ""
    ORA-16779: the destination parameter of a database is set incorrectly
    ORA-19595: archived log  already included in backup conversation
    ORA-19851: OS error while managing auxiliary databaseBy the same logic, you will notice that ORA-00256, ORA-01024, ORA-01280, ORA-01536 etc return 0, making you think your script succeeded when it actually failed with 'space quota exceeded for tablespace' etc.
    Edited by: William Robertson on Jun 2, 2011 7:13 PM

  • A question about the impact of SQL*PLUS SERVEROUTPUT option on v$sql

    Hello everybody,
    SQL> SELECT * FROM v$version;
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
    PL/SQL Release 11.2.0.1.0 - Production
    CORE    11.2.0.1.0  Production
    TNS for Linux: Version 11.2.0.1.0 - Production
    NLSRTL Version 11.2.0.1.0 - Production
    SQL>
    OS : Fedora Core 17 (X86_64) Kernel 3.6.6-1.fc17.x86_64I would like to ask a question about the SQL*Plus SET SERVEROUTPUT ON/OFF option and its impact on queries on views such as v$sql and v$session. Here is the problem
    Actually I define three variables in SQL*Plus in order to store sid, serial# and prev_sql_id columns from v$session in order to be able to use them later, several times in different other queries, while I'm still working in the current session.
    So, here is how I proceed
    SET SERVEROUTPUT ON;  -- I often activate this option as the first line of almost all of my SQL-PL/SQL script files
    SET SQLBLANKLINES ON;
    VARIABLE mysid NUMBER
    VARIABLE myserial# NUMBER;
    VARIABLE saved_sql_id VARCHAR2(13);
    -- So first I store sid and serial# for the current session
    BEGIN
        SELECT sid, serial# INTO :mysid, :myserial#
        FROM v$session
        WHERE audsid = SYS_CONTEXT('UserEnv', 'SessionId');
    END;
    PL/SQL procedure successfully completed.
    -- Just check to see the result
    SQL> SELECT :mysid, :myserial# FROM DUAL;
        :MYSID :MYSERIAL#
           129   1067
    SQL> Now, let's say that I want to run the following query as the last SQL statement run within my current session
    SELECT * FROM employees WHERE salary >= 2800 AND ROWNUM <= 10;According to Oracle® Database Reference 11g Release 2 (11.2) description for v$session
    http://docs.oracle.com/cd/E11882_01/server.112/e25513/dynviews_3016.htm#REFRN30223]
    the column prev_sql_id includes the sql_id of the last sql statement executed for the given sid and serial# which in the case of my example, it will be the above mentioned SELECT query on the employees table. As a result, right after the SELECT statement on the employees table I run the following
    BEGIN
        SELECT prev_sql_id INTO :saved_sql_id
        FROM v$session
        WHERE sid = :mysid AND serial# = :myserial#;
    END;
    PL/SQL procedure successfully completed.
    SQL> SELECT :saved_sql_id FROM DUAL;
    :SAVED_SQL_ID
    9babjv8yq8ru3
    SQL> Having the value of sql_id, I'm supposed to find all information about cursor(s) for my SELECT statement and also its sql_text value in v$sql. Yet here is what I get when I query v$sql upon the stored sql_id
    SELECT child_number, sql_id, sql_text
    FROM v$sql
    WHERE sql_id = :saved_sql_id;
    CHILD_NUMBER   SQL_ID          SQL_TEXT
    0              9babjv8yq8ru3    BEGIN DBMS_OUTPUT.GET_LINES(:LINES, :NUMLINES); END;Therefore instead of
    SELECT * FROM employees WHERE salary >= 2800 AND ROWNUM <= 10;for the value of sql_text I get the following value
    BEGIN DBMS_OUTPUT.GET_LINES(:LINES, :NUMLINES);Which is not of course what I was expecting to find in v$sql for the given sql_id.
    After a bit googling I found the following thread on the OTN forum where it had been suggested (well I think maybe not exactly for the same problem) to turn off SERVEROUTPUT.
    Problem with dbms_xplan.display_cursor
    This was precisely what I did
    SET SERVEROUTPUT OFFafter that I repeated the whole procedure and this time everything worked pretty well as expected. I checked SQL*Plus documentation for SERVEROUTPUT
    and also v$session page, yet I didn't find anything indicating that SERVEROUTPUT should be switched off whenever views such as v$sql, v$session
    are queired. I don't really understand the link in terms of impact that one can have on the other or better to say rather, why there is an impact
    Could anyone kindly make some clarification?
    thanks in advance,
    Regards,
    Dariyoosh

    >
    and also v$session page, yet I didn't find anything indicating that SERVEROUTPUT should be switched off whenever views such as v$sql, v$session
    are queired. I don't really understand the link in terms of impact that one can have on the other or better to say rather, why there is an impact
    Hi Dariyoosh,
    SET SERVEROUTPUT ON has the effect of executing dbms_output.get_lines after each and every statement. Not only related to system view.
    Here below what Tom Kyte is explaining in this page:
    Now, sqlplus sees this functionality and says "hey, would not it be nice for me to dump this buffer to screen for the user?". So, they added the SQLPlus command "set serveroutput on" which does two things
    1) it tells SQLPLUS you would like it <b>to execute dbms_output.get_lines after each and every statement</b>. You would like it to do this network rounding after each call. You would like this extra overhead to take place (think of an install script with hundreds/thousands of statements to be executed -- perhaps, just perhaps you don't want this extra call after every call)
    2) SQLPLUS automatically calls the dbms_output API "enable" to turn on the buffering that happens in the package.Regards.
    Al

  • SQL*PLUS HTML reports

    Hi how to add javascripts to the HTML reports generated using SQL*plus :
    SET MARKUP HTML ON SPOOL ON
    If we want to modify the dynamically generated HTML page by SQL*PLUS how does one do that??
    Please help

    If you create a script containing the following it should work:
    set markup html on spool on
    spool <your file>
    run sql-commands here
    spool off
    set markup html off

  • OCA-30002 Error, SQL-Plus 8.0.5, Oracle8i Lite

    I had install Oracle8i lite and Developer 6.0
    After installing "Required Support Files" v.8.0.5.1.0 (from
    Developer) instead "Required Support Files" v.8.0.5.0.0 I cant
    start SQL-Plus. It raise Error code OCA-30002 when trying
    connect to system/dummy@ODBC:POLite.
    This problem exist on Windows 95 and Windows NT.
    null

    Order by cannot be used in a subquery while for inline view it is supported but in Oracle8i, release 8.1 and up
    Khurram

Maybe you are looking for

  • Error message when submitting PS job in Tidal

    Did anyone see this error message? I submitted a PeopleSoft job and got this message org.apache.xerces.dom.ElementNSImpl cannot be cast to org.w3c.dom.html.HTMLAnchorElement All I can find in the log is where it changes the status to 66, Error Occurr

  • Why isn't the plugin checker working anymore?

    I check for updates to my plugins very often. The Plugin Check page has been saying that all my plugins are up to date. However, twice now I've clicked the button to check anyway, and found that a plugin was not up to date after all. Why isn't the Pl

  • 1 set of speakers for tv and streaming

    I was going to buy an AppleTV and connect a set of external speakers to my tv, so any devices connected to the tv will use those speakers, but what if I want to stream audio from an ipod or macbook to those same speakers? I could buy a A/V receiver t

  • APO and BW Reporting

    I have a requirement to report from APO, I would request if someone can post documentation related to that. I would also like to know how it is different from usual BW reporting. Thanks for help in advance.

  • Moving mail folders from a profile on a crashed xp drive to a profile on a windows 7 drive

    I have not been able to figure out how to get my current TB (win 7) to read the mail folders I had copied over from a TB profile on a crashed xp drive. I cannot use backup/restore, because I can't run TB on the xp drive. I created a new local folder