public Integer exec(HplsqlParser.Exec_stmtContext ctx) { 
    if (execProc(ctx)) {
      return 0;
    }
    trace(ctx, "EXECUTE");
    Var vsql = evalPop(ctx.expr());
    String sql = vsql.toString();
    if (trace) {
      trace(ctx, "SQL statement: " + sql);
    }
    QueryResult query = queryExecutor.executeQuery(sql, ctx);
    if (query.error()) {
      exec.signal(query);
      return 1;
    }
    try {
      if (ctx.T_INTO() != null) {
        int cols = ctx.L_ID().size();
        if (query.next()) {
          for (int i = 0; i < cols; i++) {
            Var var = exec.findVariable(ctx.L_ID(i).getText());
            if (var != null) {
              if (var.type != Type.ROW) {
                var.setValue(query, i);
              }
              else {
                var.setRowValues(query);
              }
              if (trace) {
                trace(ctx, var, query.metadata(), i);
              }
            }
            else if (trace) {
              trace(ctx, "Variable not found: " + ctx.L_ID(i).getText());
            }
          }
          exec.setSqlCode(SqlCodes.SUCCESS);
        }
      }
      // Print the results
      else {
        int cols = query.columnCount();
        if (cols > 0) {
          while (query.next()) {
            for (int i = 0; i < cols; i++) {
              if (i > 1) {
                console.print("\t");
              }
              console.print(query.column(i, String.class));
            }
            console.printLine("");
          }
        }
      }
    } catch(QueryException e) {
      exec.signal(query);
      query.close();
      return 1;
    }
    query.close();
    return 0; 
  }
EXEC, EXECUTE and EXECUTE IMMEDIATE statement to execute dynamic SQL or stored procedure
hplsql/src/main/java/org/apache/hive/hplsql/Stmt.java