Example code:
[SQL]View PlainCopy
- CREATE OR REPLACE FUNCTION "My_database"." F_get_user_count_by_depart "
- (
- Depart_id_val in long
- )
- return VARCHAR2
- Is
- User_state varchar (16);
- User_count number;
- Begin
- Select Count (*) into user_count from tb_user_info where depart_id=depart_id_val;
- If User_count > 0 Then
- user_state:=' users ' under the Department;
- Else
- user_state:=' No user in the department ';
- End If;
- return (user_state);
- End
Explain:
[SQL]View PlainCopy
- CREATE OR REPLACE FUNCTION "database name"." Function name "
- (
- Parameter one [in, out] type,
- Parameter two [in, out] type,
- ...
- )
- return value type
- Is
- variable one type;
- Variable two types;
- ... ;
- Begin
- /* The process of assigning a value to a variable */
- return (variable one or variable two or ...);
- End
- There are two types of arguments, in or out, and you can create functions without parameters;
- Multiple parameters are separated by ",", with ";" between multiple variables; Separated
Oracle Custom Functions function