When do I need to use a semicolon vs a slash in Oracle SQL?

前端 未结 6 815
刺人心
刺人心 2020-11-21 22:58

We have been having some debate this week at my company as to how we should write our SQL scripts.

Background: Our database is Oracle 10g (upgrading to 11 soon).

6条回答
  •  臣服心动
    2020-11-21 23:45

    Almost all Oracle deployments are done through SQL*Plus (that weird little command line tool that your DBA uses). And in SQL*Plus a lone slash basically means "re-execute last SQL or PL/SQL command that I just executed".

    See

    http://ss64.com/ora/syntax-sqlplus.html

    Rule of thumb would be to use slash with things that do BEGIN .. END or where you can use CREATE OR REPLACE.

    For inserts that need to be unique use

    INSERT INTO my_table ()
    SELECT 
    FROM dual
    WHERE NOT EXISTS (SELECT 
                      FROM my_table
                      WHERE )
    

提交回复
热议问题