Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive
On this page

Show all

SQLSTATE and SQLCODE

Updated on 2024-05-07 GMT+08:00

SQLSTATE is a five-character array. The five characters contain digits or upper-case letters that represent codes of various error and warning conditions. SQLSTATE has a hierarchical scheme: the first two characters indicate the general class of the condition, the last three characters indicate a subclass of the general condition. For example, the code 00000 indicates the success state.

SQLCODE is a simple integer. The value 0 indicates success, a positive value indicates success with additional information, a negative value indicates an error. The SQL standard only defines the positive value +100, which indicates that the last command returned or affected zero rows, and no specific negative values.

Table 1 Mapping between SQLSTATE and SQLCODE

SQLCODE Value

SQLSTATE Value

Description

0 (ECPG_NO_ERROR)

SQLSTATE 00000

Indicates no error.

100 (ECPG_NOT_FOUND)

SQLSTATE 02000

This is a harmless condition indicating that the last command retrieved or processed zero rows, or that you are at the end of the cursor.

When processing a cursor in a loop, you could use this code as a way to detect when to abort the loop. An example is as follows:
while (1) 
{ 
    EXEC SQL FETCH ... ; 
    if (sqlca.sqlcode == ECPG_NOT_FOUND)  
        break; 
}

Actually, WHENEVER NOT FOUND DO BREAK effectively does this internally, so there is usually no advantage in writing this out explicitly.

-12 (ECPG_OUT_OF_MEMORY)

SQLSTATE YE001

Indicates that your virtual memory is exhausted. The numeric value is defined as –ENOMEM.

-200 (ECPG_UNSUPPORTED)

SQLSTATE YE000

Indicates that the preprocessor has generated something that the library does not know about.

-201 (ECPG_TOO_MANY_ARGUMENTS)

SQLSTATE 07001 or 07002

Indicates that the command specified more host variables than the command expected.

-202 (ECPG_TOO_FEW_ARGUMENTS)

SQLSTATE 07001 or 07002

Indicates that the command specified fewer host variables than the command expected.

-203 (ECPG_TOO_MANY_MATCHES)

SQLSTATE 21000

Indicates that a query has returned multiple rows, but the statement is ready to store only one result row.

-204 (ECPG_INT_FORMAT)

SQLSTATE 42804

The host variable is of the int type and the data in the database is of a different type and contains a value that cannot be interpreted as an int. The library uses strtol() for this conversion.

-205 (ECPG_UINT_FORMAT)

SQLSTATE 42804

The host variable is of the unsigned int type and the data in the database is of a different type and contains a value that cannot be interpreted as an unsigned int. The library uses strtoul() for this conversion.

-206 (ECPG_FLOAT_FORMAT)

SQLSTATE 42804

The host variable is of the float type and the data in the database is of another type and contains a value that cannot be interpreted as a float value. The library uses strtod() for this conversion.

-207 (ECPG_NUMERIC_FORMAT)

SQLSTATE 42804

The host variable is of the numeric type and the data in the database is of another type and contains a value that cannot be interpreted as a numeric value.

-208 (ECPG_INTERVAL_FORMAT)

SQLSTATE 42804

The host variable is of the interval type and the data in the database is of another type and contains a value that cannot be interpreted as an interval value.

-209 (ECPG_DATE_FORMAT)

SQLSTATE 42804

The host variable is of the date type and the data in the database is of another type and contains a value that cannot be interpreted as a date value.

-210 (ECPG_TIMESTAMP_FORMAT)

SQLSTATE 42804

The host variable is of the timestamp type and the data in the database is of another type and contains a value that cannot be interpreted as a timestamp value.

-211 (ECPG_CONVERT_BOOL)

SQLSTATE 42804

The host variable is of the Boolean type, but the data in the database is neither 't' nor 'f'.

-212 (ECPG_EMPTY)

SQLSTATE YE000

The statement sent to the SQL server was empty. (This usually does not occur in an embedded SQL program, so it may point to an internal error.)

-213 (ECPG_MISSING_INDICATOR)

SQLSTATE 22002

A null value was returned and no null indicator variable was provided.

-214 (ECPG_NO_ARRAY)

SQLSTATE 42804

An ordinary variable was used in a place that requires an array.

-215 (ECPG_DATA_NOT_ARRAY)

SQLSTATE 42804

The database returned an ordinary variable in a place that requires array value.

-216 (ECPG_ARRAY_INSERT)

SQLSTATE 42804

The value cannot be inserted into the array.

-220 (ECPG_NO_CONN)

SQLSTATE 08003

The program tried to access a connection that does not exist.

-221 (ECPG_NOT_CONN)

SQLSTATE YE000

The program tried to access a connection that does exist but is not open. (This is an internal error.)

-230 (ECPG_INVALID_STMT)

SQLSTATE 26000

The statement you are trying to use has not been prepared.

-239 (ECPG_INFORMIX_DUPLICATE_KEY)

SQLSTATE 23505

Duplicate key error, violation of unique constraint.

-240 (ECPG_UNKNOWN_DESCRIPTOR)

SQLSTATE 33000

The specified descriptor was not found. The statement you are trying to use has not been prepared.

-241 (ECPG_INVALID_DESCRIPTOR_INDEX)

SQLSTATE 07009

The specified descriptor was out of range.

-242 (ECPG_UNKNOWN_DESCRIPTOR_ITEM)

SQLSTATE YE000

An invalid descriptor item was requested. (This is an internal error.)

-243 (ECPG_VAR_NOT_NUMERIC)

SQLSTATE 07006

During the execution of a dynamic statement, the database returned a numeric value and the host variable was not numeric.

-244 (ECPG_VAR_NOT_CHAR)

SQLSTATE 07006

During the execution of a dynamic statement, the database returned a non-numeric value and the host variable was numeric.

-284 (ECPG_INFORMIX_SUBSELECT_NOT_ONE)

SQLSTATE 21000

The result of the subquery was not a single row.

-400 (ECPG_PGSQL)

-

Some error caused by the SQL server. This message contains an error message from the SQL server.

-401 (ECPG_TRANS)

SQLSTATE 08007

The SQL server notified that the transaction cannot be started, committed, or rolled back.

-402 (ECPG_CONNECT)

SQLSTATE 08001

The connection attempt to the database did not succeed.

-403 (ECPG_DUPLICATE_KEY)

SQLSTATE 23505

Duplicate key error, violation of unique constraint.

-404 (ECPG_SUBSELECT_NOT_ONE)

SQLSTATE 21000

The result of the subquery was not a single row.

-602 (ECPG_WARNING_UNKNOWN_PORTAL)

SQLSTATE 34000

An invalid cursor name was specified.

-603 (ECPG_WARNING_IN_TRANSACTION)

SQLSTATE 25001

A transaction is in progress.

-604 (ECPG_WARNING_NO_TRANSACTION)

SQLSTATE 25P01

There is no active (in-progress) transaction.

-605 (ECPG_WARNING_PORTAL_EXISTS)

SQLSTATE 42P03

An existing cursor name was specified.

CAUTION:
  • The SQLSTATE codes 22002, 07001, 07002, 07006, 07009, 33000, 42601, 42804, 42P03, YE000 and YE001 are newly added to ecpg for embedded SQL statements. Other SQLSTATE codes are inherited from the kernel SQLSTATE codes.
  • If the value of SQLSCODE is –400, ecpg detects that the kernel server returns an error. The error code of the kernel SQLSTATE is used.

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback