cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
beastwood
Level II

Basic Questions using oracle SQL and JSL

I'm currently doing some testing to see how well JMP 13 and Oracle (12c) can work together.  My end-game is to import oracle data using SQL queries into JMP, run analysis on the data, and then return the data back to the Oracle database while dropping the original table.  I've been able to sucessfully bring data into JMP, but I'm having issues with saving the data table back to oracle. Here's what I have so far and what I think the drop the table command should be (currently commented out):

 

constring = ("DSN=***; UID=****; PWD=****);

dt1 = Open Database(constring,"select * from test1","test1");

dt1 << save database(constring,"test2");

//open database (constring,"Drop table test1");

 

When I run this the "test1" table pops up with the correct data in it, but the "save database" errors out with the following error:

Send Expects Scriptable Object in access or evaluation of 'Send' , dt1 << /*###*/save database( constring, "test2" ) /*###*/

In the following script, error marked by /*###*/
dt1 << /*###*/save database( constring, "test2" ) /*###*/
{}

 

I've been using this document (https://www.jmp.com/content/dam/jmp/documents/en/white-papers/wp-jmp-odbc-102427.pdf) as my primary reference and I think it looks the same as the example, but something is clearly off.

 

What am I doing wrong with the "save database" function and will the drop table command work?

11 REPLIES 11
beastwood
Level II

Re: Basic Questions using oracle SQL and JSL

Hmm, interesting.  I can actually create the tables by logging into oracle, but I'd love to get this working and the DBA hasn't been extremely helpful so far.  If I just try inserting the records how do I set it up to iterate through the JMP table records to insert them?  For example, let's say that I have a table in JMP with 100 records and 3 columns (ID, zip code, order amount).  How do I take what you just wrote and insert those records back into the table in oracle?

pmroz
Super User

Re: Basic Questions using oracle SQL and JSL

OK here's some code I cobbled together from a production system.  Names have been changed to protect the innocent and all that.

dt = New Table( "Example", Add Rows( 3 ), 
		New Column( "ID", Numeric, "Continuous", Format( "Best", 12 ),
		Set Values( [1, 2, 3] )	),
	New Column( "Zip Code", Numeric, "Continuous", Format( "Best", 12 ),
		Set Values( [12345, 19117, 10111] )	),
	New Column( "Order Amount", Numeric, "Continuous", Format( "Currency", "USD", 17, 2 ),
		Set Values( [56.25, 34.11, 14.72] )	)
);


// Come up with a unique temporary table name
unique_table_name = "TMP_" || right(char(today()), 5) || "_" || 
			substitute(left(char(tick seconds()), 9), ".", "_");

dbc = create database connection(<insert your parameters here>);
max_inserts = 200;
nr = nrows(dt);

// Use a series of INSERT ALL INTO statements, which have good performance
sql_statement = evalinsert(
"CREATE TABLE ^unique_table_name^ (
	id           NUMBER,
	zipcode      NUMBER,
	ORDER_AMOUNT NUMBER)");

//show(sql_statement);
	execute sql(dbc, sql_statement);
		
sql_statement = "INSERT ALL ";

for (i = 1, i <= nr, i++,
	one_id = dt:id[i];
	one_zip = dt:zip code[i];
	one_amt = dt:Order Amount[i];

	sql_statement = sql_statement || evalinsert(
" INTO ^unique_table_name^ (ID, ZIPCODE, ORDER_AMOUNT)
  VALUES(^one_id^, ^one_zip^, ^one_amt^) ");

	if (mod(i, max_inserts) == 0,
// Weird - INSERT ALL INTO requires a SELECT statement at the end - use a dummy one
		sql_statement = sql_statement || " SELECT 1 FROM DUAL";
//		show(sql_statement);
		execute sql(dbc, sql_statement);
		sql_statement = "INSERT ALL ";
	);
);

// See if there's anything left to do
if (sql_statement != "INSERT ALL ",
	sql_statement = sql_statement || " SELECT 1 FROM DUAL";
//	show(sql_statement);
	execute sql(dbc, sql_statement);
);

close database connection(dbc);