当前位置:网站首页>Solutions to the error reported by executing Oracle SQL statement [ora-00904: "createtime": invalid identifier] and [ora-00913: too many values]

Solutions to the error reported by executing Oracle SQL statement [ora-00904: "createtime": invalid identifier] and [ora-00913: too many values]

2022-06-10 23:22:00 Milk coffee 13

One 、 Problem description

① Use navicat After the modeling tool establishes the table structure , export sql Statement or directly synchronize the model to the specified user mode , We use normal query statements to query the contents and report errors 【ORA-00904: "CREATETIME": Invalid identifier 】;

② Execute inserted sql Wrong sentence 【ORA-00913: Too many values 】;

Two 、 Problem analysis

2.1、ORA-00904: "CREATETIME": Invalid identifier

Let's check navicat The table creation statement exported by the modeling tool , It is found that the fields are all enclosed in double quotation marks ;

 

If we use sql Statements such as 【SELECT CreateTime FROM "IQC_MaterialStandard_Record"】, The following error will be reported :

 

Oracle In single quotes 、 Double quotation mark description
Serial number explain
1

stay Oracle The middle double quotation marks are used to :

1、【 If you create an object , Object name 、 Field names are enclosed in double quotes , said Oracle Will be strictly case sensitive 】;

2、【 otherwise Oracle All default uppercase 】

2

Single quotation marks indicate : A single quoted field is a word similar to a string , Not case sensitive .

Single quotation marks are used to identify the difference between characters and numbers ;

When specifying string text , You must enclose the string text in single quotes .

1- Reference a string constant , That is to define the beginning and end of a string 

 select * from TEST where ID='100010';  -- Inquire about ID by 100010 Character information for 

 select * from TEST where ID=100010;  -- Inquire about JID by 100010 The integer number of 


2- Escape character , For characters that appear immediately after ( Single quotation marks ) Transference  

 select ' '' ' result from dual; -- The second single quotation mark is used as an escape character , The third single quotation mark is escaped . The result is  '

 select 'name''''' result from dual; -- The result is name''

 select 'name'||'''' result from dual;  -- The result is name','||'  Escaped to character splicing 
3

Double quotation marks are used for 【 keyword Object name Field name Alias

 Example of a double quotation mark scenario :

1、 Keyword used 
select "sysdate" from dual;  --  Equate to select sysdate from dual; 

2、 Strictly match the case of fields 
select * from test where "ReName" = ' Siyu '; -- Double quotation marks indicate oracle Case sensitive ,rename Will be an error 

3、 Use the alias 
select RENAME " Alias " from TEST; -- If there are special characters or keywords in the alias , Need double quotation marks to enclose 

2.2、ORA-00913: Too many values

  View our sql sentence 【
INSERT INTO "IQC_MaterialStandard_Record"("Id","InspectionLot","MaterialType") VALUES('100010','3002004101',' spare part ','2022-06-10 13:29:36')】, After careful inspection, it is found that there are more data to be inserted than fields , Match errors that are not reported .

3、 ... and 、 resolvent

3.1、 solve ORA-00904: "XXX Field ": Invalid identifier

Method 1 : Add double quotes to the fields in the query

// The original error reporting statement 
SELECT CreateTime FROM "IQC_MaterialStandard_Record"

// Statements that can be executed normally after modification ( You need to add double quotes to the field )
SELECT "CreateTime" FROM "IQC_MaterialStandard_Record"
        /// <summary>
        ///  Concatenate all elements of a string array , Where the specified separator is used between each element , Add the specified identifier on both sides of each element .
        /// </summary>
        /// <param name="separator"> Separator ( For example, comma 【","】)</param>
        /// <param name="fieldContainMark"> The identifier contained on both sides of the field ( For example, the field contains double quotation marks 【"\""】)</param>
        /// <param name="values"> Array to concatenate </param>
        /// <returns> Returns the contents of a concatenated string </returns>
        public static string Join(String separator,string fieldContainMark, params string[] values)
        {
            if (string.IsNullOrEmpty(separator) || values == null || values.Length <= 0) return null;

            string str = string.Empty;
            int len = values.Length;

            if (!string.IsNullOrEmpty(fieldContainMark))
            {
                for (int i = 0; i < len - 1; i++)
                {
                    str += $"{fieldContainMark}{values[i]}{fieldContainMark}{separator}";
                }
                str += $"{fieldContainMark}{values[len - 1]}{fieldContainMark}";
            }
            else
            {
                for (int i = 0; i < len - 1; i++)
                {
                    str += $"{values[i]}{separator}";
                }
                str += $"{values[len - 1]}";
            }

            return str;
        }
 // Get the attribute name of the specified model 
 var props = typeof(MaterialModel).GetProperties().Select(x => x.Name).ToArray();

// Assembly insert sql( Get the model attribute as the field name and the array with double quotation marks )
string cols = EntityHelper.Join(",","\"",props);

Method 2 : Recreate the table , Remove the double quotes from the field

  You can also use other editing tools to replace sql Double quotation marks in statements , And then execute sql Statement after the table is recreated, the previous statement can be executed normally .

3.2、 solve ORA-00913: Too many values

Check sql Statement found that the filled value is more than the specified field content , Just add the corresponding field or delete more than values , as follows :

// The original mistake sql sentence 
INSERT INTO "IQC_MaterialStandard_Record"("Id","InspectionLot","MaterialType") VALUES('100010','3002004101',' spare part ','2022-06-10 13:29:36')

// Now the correct sql sentence ( Whether you need to add fields or delete data needs to be viewed according to the table fields you have created )
INSERT INTO "IQC_MaterialStandard_Record"("Id","InspectionLot","MaterialType","CreateTime") VALUES('100010','3002004101',' spare part ','2022-06-10 13:29:36')
原网站

版权声明
本文为[Milk coffee 13]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/161/202206102215464467.html