Control Statements

In this section, you will find the how conditional and loop statements from oracle, are converted to JavaScript.

IF, ELSIF and ELSE Statement

Oracle

CREATE OR REPLACE PROCEDURE PROC1
IS
    sal_raise NUMBER;
BEGIN
  IF jobid = 'PU_CLERK' THEN sal_raise := .09;
  ELSIF jobid = 'SH_CLERK' THEN sal_raise := .08;
  ELSIF jobid = 'ST_CLERK' THEN sal_raise := .07;
  ELSE sal_raise := 0;
  END IF;
END;

Snowflake

SnowConvert helpers Code removed from the example. You can find them here.

CREATE OR REPLACE PROCEDURE PUBLIC.PROC1 ()
RETURNS STRING
LANGUAGE JAVASCRIPT
EXECUTE AS CALLER
AS
$$
   // REGION SnowConvert Helpers Code
   let SAL_RAISE;
   if (JOBID == `PU_CLERK`) {
      SAL_RAISE = 0.09000000357627869;
   } else if (JOBID == `SH_CLERK`) {
      SAL_RAISE = 0.07999999821186066;
   } else if (JOBID == `ST_CLERK`) {
      SAL_RAISE = 0.07000000029802322;
   } else {
      SAL_RAISE = 0;
   }
$$;

Loop

Oracle

CREATE OR REPLACE PROCEDURE PROC1 
IS
BEGIN
  <<outer_loop>>
  LOOP
    i := i + 1;
    j := 0;
    <<inner_loop>>
    LOOP
      j := j + 1;
      s := s + i * j; -- Sum several products
    END LOOP inner_loop;
  END LOOP outer_loop;
END;

Snowflake

SnowConvert helpers Code removed from the example. You can find them here.

CREATE OR REPLACE PROCEDURE PUBLIC.PROC1 ()
RETURNS STRING
LANGUAGE JAVASCRIPT
EXECUTE AS CALLER
AS
$$
   // REGION SnowConvert Helpers Code
   while ( true ) {
      I = I + 1;
      J = 0;
      while ( true ) {
         J = J + 1;
         S = S + I * J;
      }
   }
$$;

While Statement

Oracle

CREATE OR REPLACE PROCEDURE PROC1 
IS
I NUMBER := 1;
J NUMBER := 10;
BEGIN
  WHILE I <> J LOOP
    I := I+1;
  END LOOP;
END;

Snowflake

SnowConvert helpers Code removed from the example. You can find them here.

CREATE OR REPLACE PROCEDURE PUBLIC.PROC1 ()
RETURNS STRING
LANGUAGE JAVASCRIPT
EXECUTE AS CALLER
AS
$$
   // REGION SnowConvert Helpers Code
   let I = 1;
   let J = 10;
   while ( I != J ) {
      I = I + 1;
   }
$$;

Last updated