EXECUTE or sp_executesql commands in Kusto - azure-data-explorer

What is the alternative of SQL Execute Operator in Kusto for running dynamic Kusto commands?
let query = 'MyTableX | where ColumnA == \'some-string\'';
EXECUTE ['query']

At this point of time - such functionality is not available.
Please submit user-voice item at http://aka.ms/adx.uservoice

Related

Kusto command for generating create table & function script

Kusto explorer does allow scripting out functions and tables using the UI option "make command script". Is there any way we can use some sort of Kusto command to generate exactly the same output? Basically looking for command counterpart for clicking "make command script".
Continuing Yoni's answer, this should give you an executable command
.show table MyTable cslschema | project strcat(".create table ",TableName," (", Schema , ")")
project lets you select what to output (same as SELECT in sql)
strcat lets you concat string
.show table T cslschema (doc) should bring you close to that

sqlite3 got syntax error while executing vacuum in a trigger

I'm using sqlte3.8.8, trying to create a trigger to clean old data. Here is the SQL that I put in:
CREATE TRIGGER "main"."NewTrigger" AFTER INSERT ON "historydata"
BEGIN
delete from historydata where id in (select id from historydata order by id limit 100000);
vacuum;
END;
But I got Syntax error on "vacuum;".However, it works fine in sqlite command line.
Is it the case that "vacuum" cannot be used in a trigger?
The documentation shows that only UPDATE/INSERT/DELETE/SELECT statements are allowed in a trigger body.

run query in all schemas

Hi I am a newbie to Oracle. I have a query that I need to run against all the schemas in database lets say (scott,hr,exampleetc) that has the table transaction in the database.
Can some one help what is the best way to do it ?? I have about 30 schemas in database I can't do it by running this against all schemas as it is time consuming..
I was thinking a plsql will be the best way to do it but I am not enough knowledgeable to do this myself ..
query example:
select sum(amount)
from abc.transaction t1
where t1.payment_method ='transfer'
and TO_char(t1.result_time_stamp,'MONTH') = TO_char(sysdate,'MONTH')
order by t1.time_stamp asc;
Thanks is advance for help ..
I'm not sure what kind of queries you want to run, if they need to aggregate data from all tables at once or if you want to look through and run a command on each, but here's something that should get you started. It's a cursor that will find all tables named "transaction". If these are going to be ad-hoc queries, I would just copy the table name output from the below cursor, write a basic query and save it somewhere or make it into a procedure of some sort. Then just modify and re-use it in the future.
DECLARE
CURSOR c1
IS
SELECT owner, table_name
FROM all_tables
WHERE upper(table_name) = 'TRANSACTION';
BEGIN
FOR c1rec in c1
LOOP
dbms_output.put_line(c1rec.owner||'.'||c1rec.table_name);
END LOOP;
END;

execute multiple select statements using sqlite library

I am developing a Iphone App.
I need to know whether we can execute multiple insert statements in a batch at once using sqlite3 database.
As we do this in Core java in JDBC bt using execute_batch can we do the same using sqlite3 database?Can any one guide me how can i do this using sqlite3 by providing any code or link?
Thanks,
Shradha
You can do it by performing next queries:
BEGIN;
INSERT ....;
INSERT ....;
INSERT ....;
INSERT ....;
COMMIT;
Be careful with TCL, sqlite3 won't perform any DML and DDL till transaction will be COMMIT.
With using statements you won't be able to perform few commands at once if they separated by ';', statement prepare have pointer at which it will place commands which won't be performed int this statement.
We can pass multiple statements separated by a semicolon.
Example: "delete from table1;delete from table2;" This will delete the contents of table1 and table2. Similarly we can create insert statements.

Easiest method to test an Oracle Stored Procedure

I'm working on an ASP.NET project with an Oracle Database. We are using TOAD to add/manage the stored procedures -- and in general I like TOAD and Oracle. The one thing I've found frustrating is finding a simple way to test an Oracle Stored Proc, such as SQL Server's "exec [SP_NAME] Param1, Param2, ParamN" syntax.
All of our stored procedures output Ref Cursors. Here is an example of a Stored Proc:
CREATE OR REPLACE PROCEDURE APP_DB1.GET_JOB
(
p_JOB_ID IN JOB.JOB_ID%type,
outCursor OUT MYGEN.sqlcur
)
IS
BEGIN
OPEN outCursor FOR
SELECT *
FROM JOB
WHERE JOB_ID = p_JOB_ID;
END GET_JOB;
/
Any suggestions?
You just need a script that calls your stored procedure and has a bind variable for the ref cursor output to display it in TOAD's grid in the Editor window.
DECLARE
type result_set is ref cursor;
BEGIN
APP_DB1.GET_JOB(1, :result_set);
END;
When you then run this TOAD will prompt you to 'bind' :result_set, just select ref cursor from the list of types and then the result will display in the grid. The trick is to think of yourself as a 'client' calling your stored procedure and you need your own ref cursor to store the result.
If you just looking for a way to invoke the SP, then the Oracle way is:
begin
sp_name(....);
end;
I don't use Toad, but you should be able to put this into a SQL window and execute it.
In sqplus you can use the syntax
SQL>var rc refcursor
SQL>exec APP_DB1.GET_JOB(the job id you want to query, :rc)
SQL>print rc
That should do it. The first line defines a bind variable. You could also define a variable for the job id, or just type it in.
TOAD shows the result in a grid just fine with sample script from Russel. Run as script.
variable P_CUR refcursor;
exec PACK.GETEXECUTION ( '9f363e49-88c1-4295-b61e-60812d620d7e', '6', :P_CUR );
print P_CUR;
Thanks!
The idea is just to bind the outCursor variable to a cursor when toad prompts you for the variable type. Just pass the other variables the usual way. Like in the example below.
BEGIN
APP_DB1.GET_JOB(1, :v_outCursor);
END;
Run it and a dialogue box will prompt you to bind the :outCursor variable as shown in the following image.
Toad will then display the result in the result grid.

Resources