Skip to Main Content

SQLcl: MCP Server & SQL Prompt

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How can I write a blob sqlcl variable to a file with javascript

I have filled a blob variable using

Var test blob

Begin select blob_column into :test from test_table where rownum = 1; end;

/

Now I like to write this Blob to a file.

I have seen the examples:

script

// issue the sql

var  ret = util.executeReturnList('select id,file_name,file_content from images',null);

// loop the results

for (i = 0; i < ret.length; i++) {

   // debug is nice

    ctx.write( ret[i].ID  + "\t" + ret[i].FILE_NAME+ "\n");

   // get the blob stream

     var blobStream =  ret[i].FILE_CONTENT.getBinaryStream(1);

   // get the path/file handle to write to

     var path = java.nio.file.FileSystems.getDefault().getPath(ret[i].FILE_NAME);

   // dump the file stream to the file

     java.nio.file.Files.copy(blobStream,path);

}

/

and

binds = ctx.getVarMap();

numVar = binds.get('NUM_VAR');

value = numVar.getValue();

ctx.write("num_var = " + value + "\n");

Both examples are working fine.

But how can I write the Blob value which I get by:

var blobVar = ctx.getVarMap().get("TEST").getValue();

to a file.

Comments
Post Details
Added on Sep 9 2017
0 comments
730 views