[Oracle] ORA-00904 : 부적합한 식별자 invalid identifier

ORA-00904: 부적합한 식별자 invalid identifier 오류 가이드 Invalid Identifier Error Guide

이 문서는 Oracle 데이터베이스 오류인 ORA-00904: 부적합한 식별자의 일반적인 원인과 해결 방법을 설명합니다.
This document explains the common causes and solutions for the Oracle database error ORA-00904: invalid identifier.


ORA-00904 : 부적합한 식별자 invalid identifier

1. 원인: 입력된 열 이름이 누락되었거나 잘못 되었을 경우 발생.

  1. 존재하지 않는 열 이름을 지정함.
    • 쿼리에 사용된 컬럼명이 테이블에 실제로 존재하지 않거나 오타가 있는 경우입니다.
  2. 정의된 열 이름과 대소문자가 일치하지 않는 경우.
    • Oracle은 기본적으로 식별자를 대문자로 처리하지만, 큰따옴표(")로 감싸서 생성한 경우 대소문자를 정확히 구분합니다.
  3. 작은따옴표(')와 큰따옴표(") 사용 방법의 오류.
    • 작은따옴표(')는 문자열 값(value)을, 큰따옴표(")는 객체 이름(identifier)을 지정할 때 사용합니다. 이를 혼동하여 사용한 경우 오류가 발생합니다.
  4. 열 이름에 특수 문자 사용.
    • 규칙에 맞지 않는 특수문자를 사용하거나 숫자로 시작하는 열 이름을 따옴표 없이 사용한 경우입니다.
  5. 열 이름에 Oracle 예약어 사용.
    • SELECT, LEVEL, COMMENT 등 Oracle 시스템에서 사용하는 예약어를 열 이름으로 사용한 경우입니다.

2. 해결 방법

  1. 해당 열이 테이블에 존재하는지 확인.
    • DESC table_name; 명령어로 테이블의 구조를 확인하여 정확한 열 이름을 사용합니다.
  2. 큰따옴표로 묶인 열 이름은 대소문자를 구분하므로 확인.
    • 열을 생성할 때 큰따옴표(")를 사용했다면, 쿼리에서도 똑같은 대소문자로 ""로 감싸서 조회해야 합니다.
  3. 따옴표 사용법 확인.
    • 문자열 값은 작은따옴표(')로 묶고, 객체 이름(테이블, 열)은 필요 시에만 큰따옴표(")로 묶습니다.
  4. 열 이름 규칙 확인 후 수정.
    • 열 이름이 숫자나 허용되지 않은 기호로 시작하는지 확인하고, 규칙에 맞게 수정하거나 ""로 감싸줍니다.
  5. 열 이름에 예약어를 사용하고 있지 않은지 확인 후 수정.
    • 예약어를 열 이름으로 사용했다면 ""로 감싸서 쿼리를 실행하거나, 가능하면 예약어가 아닌 다른 이름으로 변경합니다.

ORA-00904: Invalid Identifier

1. Cause: The input column name is missing or invalid.

  1. Specifies a nonexistent column name.
    • This occurs if the column name used in the query does not exist in the table or contains a typo.
  2. The defined column name does not match the case.
    • By default, Oracle treats identifiers as uppercase. However, if a column was created using double quotes ("), it becomes case-sensitive.
  3. Error in how to use single quotes (') and double quotes (").
    • Single quotes (') are for string values, while double quotes (") are for object identifiers (e.g., table or column names). Confusing them will cause an error.
  4. Use of special characters in column names.
    • This happens when a column name begins with a number or an invalid special character without being enclosed in double quotes.
  5. Use of Oracle reserved words for column names.
    • Using words that are reserved for system use (e.g., SELECT, LEVEL, COMMENT) as a column name.

2. Solution

  1. Make sure the column exists in the table.
    • Use the DESC table_name; command to check the table structure and verify the correct column name.
  2. Check case for column names enclosed in double quotes.
    • If a column was created with double quotes ("), you must use the exact same case in your query, also enclosed in "".
  3. Verify the use of quotes.
    • Enclose string values with single quotes (') and object names (identifiers) with double quotes (") only when necessary.
  4. Check and fix the column name format.
    • Ensure the column name does not start with a number or an invalid symbol. If it does, correct the name or enclose it in "".
  5. Check for and fix the use of reserved words in column names.
    • If a column name is a reserved word, enclose it in double quotes (") or, preferably, rename the column to a non-reserved word.
반응형