为什么C风格的注释使insert语句运行两次? [英] Why do C-style comments make insert statement run twice?

查看:66
本文介绍了为什么C风格的注释使insert语句运行两次?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

总而言之,我开始遇到违反ORA-00001主键的情况,并将问题归结为我的某些INSERT INTO语句运行了两次.然后,我发现令人反感的命令此后具有C样式的注释:

To make a long story short, I started getting ORA-00001 primary key violations and I tracked down the issue to the fact that some of my INSERT INTO statements were running twice. I then discovered that the offending commands had a C-style comment afterwards:

WHENEVER SQLERROR EXIT FAILURE

SET ECHO OFF
SET HEADING OFF
SET PAGESIZE 0
SET FEEDBACK OFF
SET TIMING OFF
SET TIME OFF
SET TRIMSPOOL ON
SET TRIMOUT ON
SET LINESIZE 120

SET SQLBLANKLINES ON
SET SERVEROUTPUT ON

[...]

INSERT INTO INF_FIELD (FIELD_ID, CATEGORY_ID, COLUMN_EXPRESSION, DISPLAY_NAME, SORT_ORDER) VALUES (17, 1, 'FOO.NAME', 'Name of the foo', 17);

/*This is a comment*/

然后通过切换到以下语法即可轻松解决该问题:

It was then easily fixed by switching to this syntax:

--This is a comment

/*...*/注释使SQL * Plus运行两次语句的确切原因是什么?

What's the exact reason why /*...*/ comments were making SQL*Plus run the statement twice?

推荐答案

/* This is a comment */

只需确保在/*之后
有一个空格 因此,它被视为单行/多行注释.并不是要执行最后存储的PL/SQL或SQL

Just make sure you have a space after /* ,
So it is treated as a single/multi line comment. And not mean to execute the last stored PL/SQL or SQL

详细介绍.

SQL * Plus在/之后解释的内容将被忽略,并且将其缓存的块盲目地推入服务器.除了/*后跟new linespace.

What ever SQL*Plus interprets after / is ignored and it blindly pushes it's cached block into the server. Except for /* followed by a new line or space.

SQL> SELECT * FROM DUAL;

D
-
X

SQL> /*t*/

D
-
X

SQL> /*
SQL> */
SQL> /

D
-
X

SQL> /*s

D
-
X

摘自文档:

您必须在斜杠星号(/*)后面输入一个空格 评论.

You must enter a space after the slash-asterisk(/*) beginning a comment.

这篇关于为什么C风格的注释使insert语句运行两次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆