sourcecode

'INSERT INTO' 근처의 구문 오류로 인해 실패하는 SQL 쿼리에서 오류가 어디에 있는지 이해하는 방법

copyscript 2023. 6. 8. 22:26
반응형

'INSERT INTO' 근처의 구문 오류로 인해 실패하는 SQL 쿼리에서 오류가 어디에 있는지 이해하는 방법

테이블에 "Orders"라는 이름의 레코드가 없을 경우 테이블에 일부 항목을 삽입하는 SQL 쿼리를 실행해야 합니다.지금까지 저는 이렇게 했습니다.

IF NOT EXISTS (
  SELECT 
    *
  FROM
    gridconfigs
  WHERE
    gridconfigs.name = 'Orders'
)
INSERT INTO
  `gridconfigs` (
    `ownerId`,
    `classId`,
    `name`,
    `searchType`,
    `type`,
    `config`,
    `description`,
    `creationDate`,
    `modificationDate`,
    `shareGlobally`
  )
VALUES(
....

그리고 이것이 제가 받고 있는 오류입니다.

Errore nella query (1064): Syntax error near 'INSERT INTO `gridconfigs` ( `ownerId`, `classId`, `name`, ...' at line 9

나는 그 오류가 실제로 무엇인지 이해하지 못합니다.

값에 삽입 대신 존재하는 SELECT를 작성할 수 있습니다.

CREATE TABLE   `gridconfigs` (
    `ownerId` int,
    `classId` int,
    `name` varchar(19),
    `searchType` int,
    `type` int,
    `config` int,
    `description` int,
    `creationDate` int,
    `modificationDate` int,
    `shareGlobally` int
  )
;
    


INSERT INTO gridconfigs
    
VALUES
(1,2,'Orders',4,5,6,7,8,9,10)
;

INSERT INTO
  `gridconfigs` (
    `ownerId`,
    `classId`,
    `name`,
    `searchType`,
    `type`,
    `config`,
    `description`,
    `creationDate`,
    `modificationDate`,
    `shareGlobally`
  )
    SELECT 
    1,2,3,4,5,6,7,8,9,10
    WHERE NOT EXISTS ( SELECT 1 FROM gridconfigs  WHERE  gridconfigs.name = 'Orders')
Records: 0  Duplicates: 0  Warnings: 0

만지작거리다

언급URL : https://stackoverflow.com/questions/73774218/how-to-understand-where-the-error-is-in-a-sql-query-that-fails-with-this-message

반응형