---
title: "Methods and the CALL statement"
description: "CoraDB methods are C functions attached to a table and called with CALL: class and instance methods, inheritance and CALL syntax."
url: "https://www.coradb.ai/manual/sql/method.html"
markdown_url: "https://www.coradb.ai/manual/markdown/sql/method.md"
product: "CoraDB"
version: "1.0"
keywords: "coradb method, call statement, class method, instance method, call on class, db_user methods, find_user"
---

# Methods and the CALL statement

A *method* is a function attached to a table. Methods are written in C, loaded dynamically when they are first called, and run with the **CALL** statement; the value they return is passed back to the caller. The system classes `db_user`, `db_authorization` and `db_authorizations` provide the methods used for [user and privilege management](https://www.coradb.ai/manual/sql/authorization.html#user-authorization-management-method); [DB_METHOD](https://www.coradb.ai/manual/sql/catalog_views.html#db_method) lists all methods.

For server-side logic written by users, [Java stored functions and procedures](https://www.coradb.ai/manual/sql/jsp.html) are usually the better choice.

## Method types

- A **class method** is called on the table itself (the class object). It typically creates or looks up rows, or reads and updates [class attributes](https://www.coradb.ai/manual/sql/oodb.html#class-attribute-and-method). `find_user` is a class method of `db_user`.
- An **instance method** is called on one row (an instance). It typically computes or updates values of that row. `set_password` is an instance method of `db_user`, called on a user object.

Subclasses inherit the class and instance methods of their superclasses. Name conflicts between methods are resolved like those between columns; see [Table inheritance](https://www.coradb.ai/manual/sql/oodb.html#class-conflict-resolution).

## CALL

```sql
CALL method_name ( [ argument [, argument ...] ] ) ON call_target [ { TO | INTO } variable ];
CALL method_name ( call_target [, argument ...] ) [ { TO | INTO } variable ];

call_target ::= CLASS table_name | object_expression
```

- *method_name* is a method of the target's table or a system method. Methods without arguments are called with empty parentheses.
- To call a class method, put **CLASS** before the table name: `ON CLASS db_user`.
- To call an instance method, give an expression that evaluates to a row object, typically a session variable that received the object from an earlier call. In the second form, the object is the first argument.
- **TO** or **INTO** stores the returned value in a session variable, which can be used as a target or argument of later calls and read in queries such as `SELECT variable FROM db_root`.
- A method call can be the target or an argument of another call.

```sql
-- class method: look up a user and keep the object in u
CALL find_user ('dba') ON CLASS db_user INTO u;
SELECT u.name FROM db_root;                  -- DBA

-- instance method, both forms
CALL add_user ('user_5', '') ON CLASS db_user TO v;
CALL set_password ('abc') ON v;
CALL set_password (v, 'abc');
```
