Skip to content
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
Cannot retrieve contributors at this time

SQLcl - Scripting

SQLcl logo

What is it?

SQLcl scripting is based on Java's JSR-223 which allows scripting languages to be executed from the Java VM. There are a number of languages that can be plugged in with the NashHorn Javascript engine being included in Java. A list of languages can be found here

The addition of client side scripting will allow control flow in the sql scripts themselves. It also allow for things like file access, greater control on host commands, leverage various javascript libraries, and the ability to leverage java.


There are a few globals pushed into the scripting engine for use.

args -This is a simple array of the arguments passed along


		for(var arg in args) {
		   ctx.write(arg + ":" + args[arg]);

sqlcl - This is SQLCL itself

setStmt(<String of stuff to run>)
			This can be a single statement, an entire script of stuff, or any sqlcl command such as "@numbers.sql"
		Runs whatever is set via the setStmt function


		/* Run any amount of command in the sqlcl prompt */
		sqlcl.setStmt("select something from somewhere; @myscript \n begin null;end;");;

ctx ( this has tons of methods but this is the single most important )



		ctx.write('Hello World');


	var JDBCConnection=ctx.cloneCLIConnection();

util ( again tons of methods )

      executes whatever is passed in with a boolean return for success/failure
      executes and returns the first row , first column
      executes and returns an array(rows) of arrays(row).  
      execute and returns and array ( rows ) of objects ( row )
      returns the sql exeception from the executeXYZ functions

Examples: sql.js

Helper Functions

While JSR-223 is great for adding javascript capabilities, knowledge of java is required for more advanced usage. Some of the more commonly needed functions will be provided in helper.js. The .js file itself contains the descriptions of the functions. This will expand greatly as the examples and requests for examples grow.