create or replace procedure test_09171(c_custkey varchar(25) , c_mktsegment varchar(25) , cname varchar(25)) returns string not null language javascript execute as owner as $$ var sqlquery="";> var VMAJOR=""; var VMINOR=""; try { IF (C_MKTSEGMENT IS NULL OR CNAME IS NULL OR C_MKTSEGMENT =' ' OR CNAME =' ') { var sql_command =`SELECT C_MKTSEGMENT,cname from customers WHERE ccustkey=C_CUSTKEY`; var rs=snowflake.createStatement( {sqlText: sql_command}); var result_set1 = rs.execute(); while(result_set1.next()){ VMAJOR =result_set1.getColumnValue(1); return C_MKTSEGMENT; VMINOR =result_set1.getColumnValue(1); return CNAME; } } return "succeeded" } catch(error) { return error.message } $$;
While trying to execute the proc as below
call test_09171('1369097','','Customer#001369097');
I am getting this error
JavaScript compilation error: Uncaught SyntaxError: missing ) after argument list in TEST_09171 at ‘ IF(C_MKTSEGMENT is null)’ position 7
Advertisement
Answer
You have a greater than symbol here that you need to remove:
var sqlquery="";>
This line is supposed to be JavaScript but it’s written as SQL:
IF (C_MKTSEGMENT IS NULL OR CNAME IS NULL OR C_MKTSEGMENT =' ' OR CNAME =' ')
It should be in JavaScript:
if (C_MKTSEGMENT == null || CNAME == null || C_MKTSEGMENT == ' ' || CNAME == ' ')