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

Debugging

Updated on 2022-08-16 GMT+08:00

Syntax

RAISE has the following five syntax formats:

Figure 1 raise_format::=
Figure 2 raise_condition::=
Figure 3 raise_sqlstate::=
Figure 4 raise_option::=
Figure 5 raise::=

Parameter description:

  • The level option is used to specify the error level, that is, DEBUG, LOG, INFO, NOTICE, WARNING, or EXCEPTION (default). EXCEPTION throws an error that normally terminates the current transaction and the others only generate information at their levels. The log_min_messages and client_min_messages parameters control whether the error messages of specific levels are reported to the client and are written to the server log.
  • format: specifies the error message text to be reported, a format character string. The format character string can be appended with an expression for insertion to the message text. In a format character string, % is replaced by the parameter value attached to format and %% is used to print %. For example:
    --v_job_id replaces % in the character string.
    RAISE NOTICE 'Calling cs_create_job(%)',v_job_id;
  • option = expression: inserts additional information to an error report. The keyword option can be MESSAGE, DETAIL, HINT, or ERRCODE, and each expression can be any character string.
    • MESSAGE: specifies the error message text. This option cannot be used in a RAISE statement that contains a format character string in front of USING.
    • DETAIL: specifies detailed information of an error.
    • HINT: prints hint information.
    • ERRCODE: designates an error code (SQLSTATE) to a report. A condition name or a five-character SQLSTATE error code can be used.
  • condition_name: specifies the condition name corresponding to the error code.
  • sqlstate: specifies the error code.

If neither a condition name nor an SQLSTATE is designated in a RAISE EXCEPTION command, the RAISE EXCEPTION (P0001) is used by default. If no message text is designated, the condition name or SQLSTATE is used as the message text by default.

NOTICE:

If the SQLSTATE designates an error code, the error code is not limited to a defined error code. It can be any error code containing five digits or ASCII uppercase rather than 00000. Do not use an error code ended with three zeros because this kind of error codes are type codes and can be captured by the whole category.

NOTE:

The syntax described in Figure 5 does not append any parameter. This form is used only for the EXCEPTION statement in a BEGIN block so that the error can be re-processed.

Examples

Display error and hint information when a transaction terminates:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
CREATE OR REPLACE PROCEDURE proc_raise1(user_id in integer)
AS 
BEGIN 
RAISE EXCEPTION 'Noexistence ID --> %',user_id USING HINT = 'Please check your user ID'; 
END; 
/

call proc_raise1(300011);

-- Execution result:
ERROR:  Noexistence ID --> 300011
HINT:  Please check your user ID
Two methods are available for setting SQLSTATE:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
CREATE OR REPLACE PROCEDURE proc_raise2(user_id in integer)
AS 
BEGIN 
RAISE 'Duplicate user ID: %',user_id USING ERRCODE = 'unique_violation'; 
END; 
/

\set VERBOSITY verbose
call proc_raise2(300011);

-- Execution result:
ERROR:  Duplicate user ID: 300011
SQLSTATE: 23505
LOCATION:  exec_stmt_raise, pl_exec.cpp:3482

If the main parameter is a condition name or SQLSTATE, the following applies:

RAISE division_by_zero;

RAISE SQLSTATE '22012';

For example:

CREATE OR REPLACE PROCEDURE division(div in integer, dividend in integer) 
AS 
DECLARE 
res int; 
    BEGIN 
    IF dividend=0 THEN 
        RAISE division_by_zero; 
        RETURN; 
    ELSE 
        res := div/dividend; 
        RAISE INFO 'division result: %', res;
        RETURN; 
    END IF; 
    END; 
/
call division(3,0);

-- Execution result:
ERROR:  division_by_zero
Alternatively:
1
RAISE unique_violation USING MESSAGE = 'Duplicate user ID: ' || user_id;

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