Semicolon and / in SQL Plus scripts?

Anyone,
Seem to have some confusion over the use of / and ; inside PL SQL Scripts run in SQL Plus.
I seem to get two commits thereby two rows on INSERT clase that has a ; and a /.
i.e.
/* Insert record into table for recording statistics on the runtime of this script */
INSERT INTO MYTABLE ( col1, col2) VALUES ( value1, value2);
COMMIT;
/The above will get two of the same rows in the table. Is this an issue with SQL Plus settings? What do people typically use? I have a combination of SQL and DDL in my scripts and I need / for the DDL typically as I understand. How do othere intermix these and what standard is used.

Dave, here are the very basics.
The SQL language does not have command separators as only a single command at a time can be issued. Thus the following is invalid SQL:
SELECT * FROM emp;
The semicolon as command separator (or terminator) is not valid SQL. This is valid SQL:
SELECT * FROM emp
PL/SQL is a programming language similar to Pascal, C and Java. Multiple commands are used in a program. These need to be separated so that the parser/compiler can know where a command starts and where it ends. In PL/SQL the semicolon is used.
The following is invalid PL/SQL as it is missing command separators:
declare
i integer
begin
i := 1234
endThe following is valid PL/SQL :
declare
i integer;
begin
i := 1234;
end;SQL*Plus is an Oracle CLI (command line interface) client. It can submit both SQL and PL/SQL to the database. It needs to know when you have stopped entering commands into its input buffer and to submit what you've entered to the database.
SQL*Plus uses two characters for this. The semicolon and the forward slash. If you want to submit the above SELECT to Oracle using SQL*Plus, SQL*Plus needs to know when to submit its input buffer's content - thus:
SQL> SELECT * FROM emp;
Or:
SQL> SELECT * FROM emp
SQL> /
When using PL/SQL in SQL*Plus, SQL*Plus "understands" that the semicolons you use are for the PL/SQL language - not an instruction from you to it to submit its buffer to Oracle for execution.
The forward slash can also be at anytime used to resubmit the current SQL*Plus input buffer again. E.g.
SQL> SELECT * FROM emp;
.. now do the last SQL (or PL/SQL) in the buffer again
SQL> /[i]

Similar Messages

  • How to detect client OS from SQL*Plus script

    Sometimes in a SQL*Plus script I need to execute OS commands e.g.
    host rm tempfile.bufHowever of course Windows has no "rm" command by default, so I have to edit the script to use
    host del tempfile.bufNow if I could define &DELETE (for example, "cat"/"type" is another) as a substitution variable, I could just use
    host &DELETE tempfile.bufMaybe I need more coffee but all I could come up with was something like this:
    def rm=rm
    def cat=cat
    spool sqlplus_windows_defs.cmd
    prompt echo def rm=del
    prompt echo def cat=type
    spool off
    host .\sqlplus_windows_defs > sqlplus_windows_defs.sql
    @sqlplus_windows_defs.sql
    host &rm sqlplus_windows_defs.cmd
    host &rm sqlplus_windows_defs.sqlthe idea being that you first define the variables for nix ("rm" and "cat"), then attempt to create and execute a Windows command file containing DOS versions ("dele" and "type"), which does not run under nix. Unfortunately the OS failure message (".sqlplus_windows_defs: not found" in Unix) appears on the screen despite SET TERM OFF, so I'm back where I started.
    I know there are various ways to get the server OS, and you can get the SQL*Plus version with &_SQLPLUS_RELEASE and so on, but I can't see a way to determine the client OS. Any suggestions?

    Thanks guys. This seems to work in Windows XP - will try on Unix when I get a chance:
    col DELETE_COMMAND new_value DELETE_COMMAND
    col LIST_COMMAND new_value LIST_COMMAND
    def list_command = TYPE
    def delete_command = DEL
    SELECT DECODE(os,'MSWIN','TYPE','cat') AS list_command
         , DECODE(os,'MSWIN','DEL','rm')   AS delete_command
    FROM   ( SELECT CASE WHEN UPPER(program) LIKE '%.EXE' THEN 'MSWIN' END AS os
             FROM   v$session
             WHERE  audsid = SYS_CONTEXT('userenv','sessionid') );
    host &LIST_COMMAND xplan_errors.lst
    host &DELETE_COMMAND xplan_errors.lstIf the user doesn't have access to v$session it will just default to the Windows commands.
    http://www.williamrobertson.net/code/xplan.sql

  • Execute SQL*PLUS script from VB6?

    I'm using VB6 to connect to oracle 10 with oracle client 8i, I can establish the connection without any problems.
    If I run a SQL statement from VB it works prefect, but when I try to run a SQL Plus script from VB I get error ORA-00900, "invalid SQL statement". Everything works fine in oracle SQLPLUS.
    Is there anything I have missed about running SQL*PLUS script from VB6? Is'nt it the same as a SQL statement?

    Thanks for you answer Justin,
    This is a short variant of SQL*Plus I wanna execute from VB and transfer the result into a listview in VB.
    If this is possible from VB, can you show me how I should do?
    COLUMN customer_1 NEW_VALUE customer_1 NOPRINT
    COLUMN customer_2 NEW_VALUE customer_2 NOPRINT
    SELECT customer customer_1
      FROM (
            SELECT customer,
                   ROW_NUMBER() OVER(PARTITION BY customer ORDER BY CustomerTotalSales DESC) CustomerTotalSalesRank
              FROM (
                    SELECT  customer,
                            SUM(SalesQty) OVER(PARTITION BY customer) CustomerTotalSales
                      FROM  CustTable
                      WHERE year_month BETWEEN 200709 AND 200801
    WHERE CustomerTotalSalesRank = 1
      AND ROWNUM = 1
    SELECT customer customer_2
      FROM (
            SELECT customer,
                   ROW_NUMBER() OVER(PARTITION BY customer ORDER BY CustomerTotalSales DESC) CustomerTotalSalesRank
              FROM (
                    SELECT  customer,
                            SUM(SalesQty) OVER(PARTITION BY customer) CustomerTotalSales
                      FROM  CustTable
                      WHERE year_month BETWEEN 200709 AND 200801
    WHERE CustomerTotalSalesRank = 2
      AND ROWNUM = 1
    SET VERIFY OFF
    SELECT  year_month,
            SUM(
                CASE CustomerTotalSalesRank
                  WHEN 1
                    THEN
                      SalesQty
                    ELSE
                      NULL;
                END
               ) "&customer_1",
            SUM(
                CASE CustomerTotalSalesRank
                  WHEN 2
                    THEN
                      SalesQty
                    ELSE
                      NULL;
                END
               ) "&customer_2"
    FROM  (
             SELECT  year_month,
                     SalesQty,
                     ROW_NUMBER() OVER(PARTITION BY customer ORDER BY CustomerTotalSales DESC) CustomerTotalSalesRank
               FROM  (
                      SELECT  customer,
                              year_month,
                              SalesQty,
                              SUM(SalesQty) OVER(PARTITION BY customer) CustomerTotalSales
                        FROM  CustTable
                        WHERE year_month BETWEEN 200709 AND 200801
      WHERE CustomerTotalSalesRank <= 10
      GROUP BY year_month
      ORDER BY year_month
      /

  • SQL Plus Script Execution Time

    Anyone,
    Is there an easy way to start a timer inside a SQL Plus script that shows exact run time at end of script completion?
    Right now I use the TIME option and have a time as the prompt start and then one at end but would like if the SQL Plus script could simply put a begin/end/run time for me as last output. TIMING is to much since I have many things execute and do not wnat to see every individual runtime.
    Thanks in advance,
    Miller

    http://download-east.oracle.com/docs/cd/B19306_01/server.102/b14357/ch12047.htm#i2699704
    You can use TIMING with a named timer
    SQL> timing start script_time
    SQL> select 1 from dual;
             1
             1
    SQL> /
             1
             1
    SQL> /
             1
             1
    SQL> timing stop
    timing for: script_time
    Elapsed: 00:00:07.37
    SQL>

  • Oracle 8i SQL and PL/SQL plus

    hi everybody, i am trying from two weeks to install oracle 8i SQL and PL/SQL plus on my PC on both Windows 2000 & XP and I installed every java runtime environment I found "the old and the new" but the SETUP insists on not working though it worked on the instructor's PC smoothly without problems.

    If you are getting any errors, you should tell us. Also, you should let us know what version you are trying to install.
    A very common problem at the moment is with Pentium 4 processors. If you have a Pentium 4, search the forums to find the answer.
    Alison

  • SQL*Plus script with a dynamic SPOOL File Location?

    Anyone,
    I have a numbr of SQL Plus scripts that I need to run many times but each run against a different database. Each script SPOOLS the output like this:
    spool c:\temp\BUILD_ASSET.lis
    spool c:\temp\BUILD_WORKORDER.lis
    etc
    (each spool is a seperate script run)
    The spool is at the top of each BUILD SQL Script.
    Example:
    set time on
    SET FEEDBACK ON
    SET ECHO ON
    SET TIMING ON
    spool c:\temp\BUILD_ASSET.lisBut I need each run to go into its own directory based on the database I am connected to. Like this:
    CONNECT DB1
    @C:\temp\BUILD_ASSET.SQL =====> spool c:\temp\DB1\BUILD_ASSET.lis
    @c:\temp\BUILD_WORKORDER.SQL =====>  spool c:\temp\DB1\BUILD_WORKORDER.lis
    etc
    CONNECT DB2
    @C:\temp\BUILD_ASSET.SQL =====> spool c:\temp\DB2\BUILD_ASSET.lis
    @c:\temp\BUILD_WORKORDER.SQL =====> spool c:\temp\DB2\BUILD_WORKORDER.lisIs there a way to dynaically code this without having to create a version of the BUILD scripts for every single DB I connect to?
    I would like to have one big script that executes all the individual BUILD scripts.
    Seems very easy in concept but I can not see an easy way. I would appreciate any help I can get.
    Thanks in advance,
    Miller

    column db new_Value db
    select sys_context('userenv','db_name') db from dual;
    spool c:\temp\&db\file.lis

  • How to control logic flow in SQL Plus script

    Hi
    I have the requirement below:
    Before I start running an SQL script, I need to ensure that I am connecting as a particular user. If I am not that user, then the script should show a msg "Error - Invalid User - Log in as <<username>>"
    Let's say i am executing a script A.sql.
    SQL > @<path>a.sql
    But before this script is executed -- i shall check for the user:
    block begins...
    select user into var1 from dual
    if upper(var1) != 'ABCUSER' then
    -- display the error message and stop execution of this script
    else
    @<path>a.sql (*it executes what i want :) )
    end if;
    block ends...
    How do I write this code using an SQL script ? Pls sugges

    Hi,
    As Centinul said, SQL*Plus is poorly equipped to deal with problems like this. If possible, try to do what you want outside of SQL*Plus.
    If you really have to do it in SQL*Plus, here are two ideas:
    (1) run a script conditionally
    (2) deliberately raise an error
    (1) Using SQL*Plus substitution variables, you can decide which of several scripts to run as a sub-script, based on the results of some query.
    For example, if a.sql is the script that only user ABCUSER is allowed to run, then write two other very short scripts:
    (a) warning.sql, such as the following:
    --  warning.sql
    PROMPT  You are not authorized to do this.
    QUIT(b) step_1.sql, which decides whether a.sql or warning.sql should be run, and does it:
    --     step_1.sql - Decide whether a.sql or warning.sql is to be run next, and do it.
    --     (a) decide:
    COLUMN  script_name_col     NEW_VALUE     script_name
    SELECT     CASE
              WHEN  USER = 'ABCUSER'
              THEN  'a.sql'
              ELSE  'warning.sql'
         END     AS script_name_col
    FROM     dual;
    --     do:
    @&script_nameYou may want to use @@, or specify a complete path name.
    (2) Deliberately raise an error, either in a separate script or in a.sql itself, like this:
    WHENEVER     SQLERROR     EXIT
    SELECT     CASE
              WHEN  USER = 'ABCUSER'
              THEN  NULL
              ELSE  TO_NUMBER ('This will raise ORA-01722')
         END     AS "Welcome!"
    FROM     dual;
    WHENEVER     SQLERROR     NONE
    -- continue with the original a.sql

  • Detecting clientside NLS_LANG setting in SQL*Plus script

    Our company has developed an application that uses an Oracle database as it backend. Companies can buy our application and run it against their own Oracle installation.
    A new version of our application often requires an update to the Oracle database schema.
    Together with new application files we send our customers an update.sql script they must run against their database using SQL*Plus.
    This update script may contain international characters like é for example:
    UPDATE SHOPS SET DESCRIPTION = 'Café'
    WHERE SHOP_ID=1We save the SQL-script file in windows-1252 encoding so the character é is encoded as 0xE9 in the script file.
    When the DBA running the upgrade script has set NLS_LANG=.WE8MSWIN1252 this works perfectly.
    When the DBA has set his NLS_LANG=US7ASCII the é gets replaced by an upside-down question mark. Other NLS_LANG settings can also be troublesome.
    To prevent this we give very clear installation instructions. However, nobody reads them. This leads to two questions:
    A) Is there a way to prevent this problem so I do not depend on the NLS_LANG setting by the DBA running the upgrade script?
    B) Otherwise: is there a way to test for the NLS_LANG setting inside the script and abort if it is not WE8MSWIN1252?
    Info:
    Database is 10.2.0.3/10.2.0.4 and sometimes 10.2.0.5, always database character set WE8MSWIN1252.
    Client software: I do not know what each DBA uses but it will be mostly 10g client software
    Client OS: Some DBA's will be running the script from Windows, others from some Unix variety. I cannot control that.

    I agree with Sergiusz. You're much better off if you can remove character set dependencies from your scripts by using commands like this.
    UPDATE SHOPS SET DESCRIPTION =  unistr( 'Caf\00E9' )
    WHERE SHOP_ID=1 ;If that's not possible however you can try this approach to determine the session's character set.
    SQL> column USERENV_LANGUAGE format a30
    SQL> column oracle_charset   format a20
    SQL> r
      1  select
      2    userenv_language
      3  , substr
      4    ( userenv_language
      5    , instr( userenv_language, '.' ) + 1
      6    ) as oracle_charset
      7  from
      8  ( select sys_context( 'USERENV', 'LANGUAGE' ) as userenv_language
      9    from dual
    10* )
    USERENV_LANGUAGE               ORACLE_CHARSET
    AMERICAN_AMERICA.AL32UTF8      AL32UTF8 --
    Joe

  • SQL*Plus Script Errors

    My scripts all contain relative file paths e.g.
    @@../directory1/file1.sql
    Is there a way of setting the current working directory in SQL Developer to make this work?
    In SQL*Plus for windows you simply opened the file but this does not seem to work.

    As I said, run them in SQL*Plus.
    SQL*Developer is a development tool and database browser, not a SQLPLus clone.
    It has its own methods of extracting data which may or may not suit your output requirements. You don't need col statements as much if you are viewing data in a grid, for example. [1]
    I don't know what you use the sqlplus scripts for, but they could be replaced over time with some combination of Apex, SQLDeveloper reports and straight sqldeveloper queries.
    As for SQL*PLus being greyed out on the menu, there are some known issues about that. I think one of them is that you need to be using tns connections. However, the sqlplus menu item is gone in sqldeveloper 1.5 so don't rely on it. Learn to run if from the command line.
    [1] Despite that, I would arguethat SQLDeveloper should support all (with tiny exceptions) SQLPlus commands. Not because I see it as a sqlplus replacement, but so it can be used to develop scripts which can then be run in SQL*Plus without amendment (without the hassle of switching back and forth during development)

  • How to install and practice SQL* plus on my personal computer

    I am doing BSC-IT and studying oracle in one of the semester. I have to practice on SQL* plus to create tables etc. I need to know what are the applications i need to install and steps i need to follow on my pc to successfully practice on SQL*plus. Your kind prompt on the current issue will be highly appreciated.
    regards,

    Few More Querries:
    -> Which Deployment Option Should i select:
    Rapid deployment
    Standard
    deployment
    Custom
    deployment
    Upgrade
    or
    Maintenance
    installation
    I guess Rapid Deployment will be suitable.
    Please suggest.
    Thanks in Advance.
    Reagrds,
    Satish

  • Migrating SQL Plus Scripts to APEX

    Hi, all:
    I am trying to migrate some sql scripts which generates spool files as reports from sqlplus.
    I am trying to use APEX 4.2.1 interactive report pages to provide similar but much powerful functions.
    Database version 10.2.0.5.
    Seems Apex IR only accept SELECT .... queries for the region source.
    But the original scripts used in sqlplus do other things such as create a temporary table,
    then query based on this table and generate spool files.
    I would like to know is there way to simulate this table creation in APEX before handover
    the process to region source query to continue?
    I saw APEX sql workshop can create / save / run scripts, I guess somehow I need to call
    saved scripts to create temp tables before handover to IR page to do query.
    Any suggestions?
    Thanks,
    John

    You can indeed not use a temporary table. If you create and fill one in one process, there is no guarantee that the data you inserted will still be there at the moment the IR is rendered (the select against the temp table, in another process/region) due to the connection pooling apex uses. A collection would indeed be the only way. (A normal table does work of course)

  • How to use bind vars in SQL*Plus Script?

    I am trying to use a bind var in my script ... does not seem to work ... something along these lines.
    variable v_id number;
    select max(user_id) into :v_id
    from user_id_tbl;
    exec trace_user(:v_id);
    This is in a UNIX Script - I don't get any errors but the binding is not working - not passing a valid v_id ... Any ideas?

    For the record a solution is:
    variable v_id number;
    begin
    select max(user_id) into :v_id from user_id_tbl;
    end;
    exec trace_user(:v_id);
    -- CJ

  • Downloading and installing Oracle (with sql plus) on Windows 7 Professional

    Hi,
    I got a new laptop which has Windows 7 Professional (64 bit). I intend to download Oracle 10g and would like to install bothe the database and the sql plus in this system.
    I would appreciate if somebody could provide me a link to the appropriate database (with sql plus installation capability). Also if available the installation guide.
    Thanks in advance.

    Hello,
    Windows 7 Professional (64 bit). I intend to download Oracle 10g and would like to install bothe the database and the sql plusOracle *10g* is not certified on Windows *7*, except with the latest patchset *10.2.0.5*, and its Premium Support ended on the *31st of July 2010*.
    You should download Oracle *11.2* which is certified on Windows *7 - 64 bit*.
    You'll find the Documentation and Download tabs on the link below:
    http://www.oracle.com/technetwork/database/enterprise-edition/overview/index.html
    About SQLPlus, it's delivered with Oracle Server and, in *11g*, you can still use it from a DOS box. If you intend to have a Graphical Tool, you should use Oracle SQL Developer instead:
    http://www.oracle.com/technetwork/developer-tools/sql-developer/overview/index.html
    Hope this help.
    Best regards,
    Jean-Valentin

  • SQL*Plus and Oracle

    Hi, i have recently started a new course where i am required to learn sql using the sql*plus program and several books. I have downloaded the instant client and the sql*plus program so that i can run them on my computer at home so i can learn at home. However i get a problem where i cannot logon to sql*plus.
    I believe this may be because i do not have an oracle server running on my pc, i am however not sure, would be gratefull for any help.

    Yes, you will need an Oracle Server to connect to. On your personal system, you can download Oracle XE (Express Edition) from OTN and use that. It contains both the server and client (SQL*Plus) components.

  • IF statement in SQL*Plus - how to do it

    Hi,
    In SQL*Plus script, I would like to keep conditional checking (IF statement) and proceed. For example, whatever is done in PL/SQL block below, want to do the same in SQL*Plus script, I know partly it can be done using VARIABLE keyword, conditional checking can be done using DECODE in SELECT statement, but I want to carry out a more complex requirement, hence I want to use IF statement somehow in SQL*Plus.
    Another question, how to do spooling in PL/SQL script, it can be done using UTL_FILE, any other option is there to achieve this.
    declare
    v_ind_count int;
    begin
    select count(1) into v_ind_count from user_indexes where index_name = 'index_object_name';
    IF v_ind_count > 0
    THEN
    dbms_output.put_line('index found');
    ELSE
    dbms_output.put_line('index does not exist');
    END IF;
    end;
    /

    Hello,
    SQL*PLUS has no scripting language. It can only execute SQL and PL/SQL scripts. There are some commands like SPOOL or SET but no commands for conditional statements. You should describe your requirements, maybe we can find a way.
    Or you can search the forum, maybe your question has already been answered
    [Google for SQL*PLUS + condition|https://www.google.de/search?q=site%3Aforums.oracle.com+"SQL*PLUS"+condition]
    # {message:id=4189517}
    # {message:id=4105290}
    how to do spooling in PL/SQL scriptFrom within PL/SQL you can use dbms_output, the spool has to be started by the calling SQL script when it is executed in SQL*PLUS. Or you can use utl_file, but then you can only write to a server directory, not into a client file. To give an advice we need more information about what you want to do.
    Regards
    Marcus

Maybe you are looking for

  • How to accessing item renderers in action script??

    Hi I am working on itemrenderes in Flex! I have link button component as item renderer inside one of the data grid column, please find my piece as below! Now how do we make that item render invisible once we click on it! We need to make that link but

  • Wmsmixer (my first PKGBUILD)

    Ok here is my PKGBUILD, please let me know if theres anything I need to change and if you like it perhaps it can go in the AUR. # Contributer: dedhart [[email protected]] pkgname=wmsmixer pkgver=0.5.1 pkgrel=1 pkgdesc="a hack to wmmixer which makes s

  • Source list in SA

    Dear Expert when we maintain delivery schedule for Scheduling agreement for every item of new scheduling agreement system ask for source list can we make the source list optional for delivery schedule ,if so then how can we make it optional Regards

  • CD Drive keeps ejecting

    I have a 13 Early 2011 MacBook pro and everytime I put a disc into the cd drive it just keeps ejecting, any solutions?C

  • Is it possibile that I have a virus on my IPad?

    Hallo, I ma new to the apple world and I am afraid there' a virus on my IPad. I know it should not be possibile but I have unexpected pop ups saying I am infected