# Function , cursor , or procudure in dremio

**URL:** <https://community.dremio.com/t/function-cursor-or-procudure-in-dremio/1756>\
**Category:** Uncategorized\
**Created:** [September 4, 2018, 10:16am UTC](https://community.dremio.com/t/function-cursor-or-procudure-in-dremio/1756 "2018-09-04T10:16:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![priyas6393](https://avatars.discourse-cdn.com/v4/letter/p/50afbb/32.png) [@priyas6393](https://community.dremio.com/u/priyas6393)\
**Post date:** [September 4, 2018, 10:16am UTC](https://community.dremio.com/t/function-cursor-or-procudure-in-dremio/1756/1 "2018-09-04T10:16:24Z")

</div>

can we create any function , cursor, or procedure in dremio . I have a requirement to create a procedure or function , cursor based on some conditions I want to add values to those columns .

---

<div class="post-metadata">

**Author:** ![anthony](https://sea2.discourse-cdn.com/flex020/user_avatar/community.dremio.com/anthony/32/670_2.png) [@anthony](https://community.dremio.com/u/anthony)\
**Post date:** [September 8, 2018, 5:54pm UTC](https://community.dremio.com/t/function-cursor-or-procudure-in-dremio/1756/2 "2018-09-08T17:54:56Z")

</div>

There are a couple options available today

1. Being open-source, Dremio allows the capabilities for users to create their own UDF (in Java). This will appear as a SQL function in the UI.
2. While stored procedure’s aren’t directly supported today, a similar workaround is by creating VDSs and chaining them together. In other words, you would create a VDS with a logic you are trying to reuse, save it, secure it, and give users the ability to query and build upon it.

---

<div class="post-metadata">

**Author:** ![andre](https://avatars.discourse-cdn.com/v4/letter/a/6de8d8/32.png) [@andre](https://community.dremio.com/u/andre)\
**Post date:** [July 15, 2020, 5:32pm UTC](https://community.dremio.com/t/function-cursor-or-procudure-in-dremio/1756/3 "2020-07-15T17:32:26Z")

</div>

Can you provide a simple example? For example, I have SPs that use variables then DML language – are you suggesting we need to write a UDF with that embedded then rather than ‘call’ the SP, invoke it as a function?

REPLACE PROCEDURE xxx

BEGIN  
BEGIN TRANSACTION;  
CALL vds (parameters?);  
END TRANSACTION;

```
more vsp dml statements?
    insert into xxx;
    update xxx;

```

END;

create vds?

REPLACE PROCEDURE vds (x,y,z)  
PROCESS\_USER:BEGIN  
DECLARE USER\_CNT INTEGER;  
DECLARE CURR\_TS TIMESTAMP;

```
SEL Current_Timestamp INTO CURR_TS;
	
SELECT Count(*) INTO USER_CNT
FROM ...;

IF USER_CNT = 0
	THEN LEAVE PROCESS_USER;
END IF;	 		

FOR CUR_PTR AS MYPTR CURSOR FOR  	 
	SELECT xxx

DO

UPDATE x
INSERT INTO x	
END FOR;

```

END PROCESS\_USER;
