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

前端 未结 6 812
刺人心
刺人心 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:44

    I wanted to clarify some more use between the ; and the /

    In SQLPLUS:

    1. ; means "terminate the current statement, execute it and store it to the SQLPLUS buffer"
    2. after a D.M.L. (SELECT, UPDATE, INSERT,...) statement or some types of D.D.L (Creating Tables and Views) statements (that contain no ;), it means, store the statement to the buffer but do not run it.
    3. / after entering a statement into the buffer (with a blank ) means "run the D.M.L. or D.D.L. or PL/SQL in the buffer.
    4. RUN or R is a sqlsplus command to show/output the SQL in the buffer and run it. It will not terminate a SQL Statement.
    5. / during the entering of a D.M.L. or D.D.L. or PL/SQL means "terminate the current statement, execute it and store it to the SQLPLUS buffer"

    NOTE: Because ; are used for PL/SQL to end a statement ; cannot be used by SQLPLUS to mean "terminate the current statement, execute it and store it to the SQLPLUS buffer" because we want the whole PL/SQL block to be completely in the buffer, then execute it. PL/SQL blocks must end with:

    END;
    /
    

提交回复
热议问题