You can translate the question and the replies:

VQL Stored Procedure for returning a selection

Hi, I'm super new to VQL stored procedure. I'd like to convert the following selct statement to a VQL stored procedure. But I run into issues. I'm wondering what's the correct syntax for the store procedure, please? Here is the select statement: ``` SELECT field_value FROM "view_name" where "field_name"= 'FieldName1' and "field_value_usage" = 'Value1' ``` And this is stored procedure script I started: ``` (field_value OUT VARCHAR, dependantField IN VARCHAR,parentFieldValue IN VARCHAR ) AS ( CURSOR cursorData IS 'SELECT field_value FROM "view_name" where "field_name" = :dependantField and "field_value_usage" = :parentFieldValue'; rdata cursorData%ROWTYPE; ) BEGIN OPEN cursorData; LOOP FETCH cursorData INTO rdata; RETURN ROW (field_value ) VALUES (rdata.field_value); EXIT WHEN cursorData%NOTFOUND; END LOOP; CLOSE cursorData; END; ``` I'm getting a parsing error near : when try to execute. Thanks in advance for any input provided!
user
26-07-2024 17:24:23 -0400
code

3 Answers

Hi, Your stored procedure is almost correct. In the stored procedure you created, you are using the input variable names as parameters in the SELECT statement, which will result in a syntax error. Instead, you should specify different names for the variables in the SELECT statement and then assign these variables the values from the input parameters later when you open the cursor. To illustrate, let's use the following example SELECT statement: ``` SELECT customer_code FROM bv_orders WHERE status = 'Closed' OR status = 'Delivered'; ``` This is equivalent to the SELECT statement you included: ``` SELECT field_value FROM "view_name" WHERE "field_name" = 'FieldName1' AND "field_value_usage" = 'Value1'; ``` To convert this to a stored procedure, you will need parameter variables where dependantField and parentFieldValue will be replaced, for example: ``` (field_value OUT VARCHAR, dependantField IN VARCHAR, parentFieldValue IN VARCHAR) AS ( CURSOR cursorData IS 'SELECT customer_code FROM bv_orders WHERE status = '':param1'' OR status = '':param2'''; rdata cursorData%ROWTYPE; ) BEGIN OPEN cursorData PARAMETERS (param1, param2) VALUES (dependantField, parentFieldValue); LOOP FETCH cursorData INTO rdata; RETURN ROW(field_value) VALUES (rdata.customer_code); EXIT WHEN cursorData%NOTFOUND; END LOOP; CLOSE cursorData; END; ``` In this stored procedure, we add parameter variables :param1 and :param2 in the SELECT statement. These need to be different from the input variables that will be passed to the stored procedure for execution. In the BEGIN clause, we specify that these variables will hold some values using the PARAMETERS and VALUES functions. Specifically, :param1 and :param2 will be the parameters, and dependantField and parentFieldValue will be the values assigned to these parameters during execution. Hope this helps!
Denodo Team
29-07-2024 16:04:56 -0400
code
Thank you for the Help. With the above recommended code, there is no syntax error any more. But it's not returning any results for me. I'm wondering how I can trace to see exact code been executed in the back end when user execute the stored procedure, please? (as it only shows me SELECT * FROM storedprocedurename) WHERE dependantfield='Field2' AND parentfieldvalue='123' TRACE) And also where can I find detailed Documentation (user manual) around creating Stored Procedures, please? With the code above, can I put rdata.field_value on this line or it has to be a field that different from the OUT field: ``` RETURN ROW(field_value) VALUES (rdata.customer_code); ```
user
30-07-2024 11:57:33 -0400
Hi, You can trace the exact code executed in the backend by enabling LOGCONTROLLER for VDP requests using the following command to change the log level: ``` CALL LOGCONTROLLER('com.denodo.vdp.requests', DEBUG); ``` You may also refer to the Knowledge Base Articles on[ using the log controller and useful log categories](https://community.denodo.com/kb/en/view/document/Using%20logcontroller%20and%20useful%20log%20categories). Once enabled, navigate to the **vdp-requests.log** file located in the vdp log folder: {DENODO_HOME}\logs\vdp. In this file, you can find information about the queries executed by the stored procedure. For example: ``` SELECT * FROM denodo_training.basic_selection() WHERE dependantfield='********' AND parentfieldvalue='********' TRACE 327974475 [Access(2968)-340-02.00-denodo_training.basic_selection] INFO 2024-07-30T10:05:46.888 com.denodo.vdp.requests [] - CONNECT DATABASE `denodo_training` 327974492 [Access(2968)-340-02.00-denodo_training.basic_selection] INFO 2024-07-30T10:05:46.905 com.denodo.vdp.requests [] - SELECT customer_code FROM denodo_training.bv_ho_orders where status = '********' OR status = '********' 327975025 [Access(2968)-340-02.00-denodo_training.basic_selection] INFO 2024-07-30T10:05:47.438 com.denodo.vdp.requests [] - CLOSE 328004358 [DNI(9667)-XXX.XXX.XX.XX-339] INFO 2024-07-30T10:06:16.771 com.denodo.vdp.requests [] - CALL LOGCONTROLLER('********', '********') ``` For more details on developing VQL stored procedures, refer to the Knowledge Base Articles [Developing VQL Stored Procedures](https://community.denodo.com/docs/html/browse/8.0/en/vdp/developer/developing_extensions/developing_stored_procedures/developing_vql_stored_procedures). Regarding this line, you are returning the output stored in rdata from the cursor: `RETURN ROW(field_value) VALUES (rdata.customer_code);` which occurred in this line: `FETCH cursorData INTO rdata;` In my example, I stored **customer_codes** in **rdata**. Therefore, in the **RETURN ROW**, I referenced the data stored in **rdata**. For your case, if you stored **field_value** in the SELECT statement, **rdata** will hold the value of **field_value** after executing the **SELECT** statement. Thus, the output should align with the value stored in **rdata** and you can use **rdata.field_value**. If you still need further assistance and if you are a valid support user, you can raise a Support Case, for further assistance from the Support Team. Hope this helps!
Denodo Team
30-07-2024 13:24:06 -0400
code
You must sign in to add an answer. If you do not have an account, you can register here