---
title: "SQLCODE"
description: "The SQLCODE SQL function gets the error code of the last SQL error that occurred during execution."
language: ja
source_language: en
translation_state: pending
canonical: https://documentation.invantive.eu/ja/docs/invantive-universalsql/grammar/sql-functions/sqlcode
original: https://documentation.invantive.eu/en/docs/invantive-universalsql/grammar/sql-functions/sqlcode
updated: 2026-12-04T03:44:53Z
license: https://documentation.invantive.eu/ja/
---

## 構文

```mermaid
%%{init: {
  'theme': 'base',
  'flowchart': { 'padding': '7', 'nodeSpacing': '20', 'rankSpacing': '20' },
  'themeVariables': {
    'fontSize': '11px',
    'fontFamily': 'Arial'
  }
}}%%
flowchart LR
    Start((START)) --> SQLCODE[SQLCODE]:::quoted
    SQLCODE --> End((END))
```

## 目的
The `SQLCODE` SQL function gets the error code of the last SQL error that occurred during execution. The function can be used without parentheses.

関連項目：[[SQLERRM]]および[[SQLROWCOUNT]]。

Returns: the error code of the last error as `varchar2`. Returns `null` when no error occurred.

## 例
The following example retrieves the error code of the last error; the output is empty since no error occurred:
```sql
select sqlcode

-------------------

```
The following example first raises a division-by-zero error and then retrieves the error code of the last error:
```sql
select 1 / 0

itgenttn082: Division of 1 by zero is impossible.
```
```sql
select sqlcode

-------------------
itgenttn082
```
The following example catches a division-by-zero error; within the exception handler `SQLCODE` returns the error code `itgenttn082`:
```sql
declare
  l_dummy    pls_integer;
begin
  select 1/0
  into   l_dummy
  ;
exception
  when others
  then
    dbms_output.put_line(sqlcode);
end;
```

