Is it possible to use EXECUTE IMMEDIATE from within a SQL udf? It's a very cool feature, but it seems it can only be called from within a SQL procedure, and BigQuery doesn't allow a stored procedure to be called within a SQL udf if I'm understanding properly.
Is this possible to do somehow in a SQL function, as I'm trying to dynamically build a query using the execute immediate command.
Related
We are trying to execute multiple statements in BigQuery using stored procedures. This is a generic stored procedure which can invoked for any table, hence need to execute dynamic statements on any table.
Is there EXEC() like thing in BigQuery to execute dynamically generated queries?
Yes. As of 5/20/2020, BigQuery released dynamic SQL feature for you to achieve the goal.
Dynamic SQL is now available as a beta release in all BigQuery regions. Dynamic SQL lets you generate and execute SQL statements dynamically at runtime. For more information, see EXECUTE IMMEDIATE.
For your scenario, you could have a generic procedure:
CREATE PROCEDURE myTableOperations(tableName STRING)
BEGIN
EXECUTE IMMEDIATE CONCAT("SELECT col1 FROM ", tableName, " WHERE ...");
...
END
I'm trying to write a T-SQL script to create a database and the corresponding tables. I'm having a problem where the USE statement complains that the database that I just "created" doesn't exist. If I run the script within SQL Server Management Studio so that I can make use of the GO statement, I don't get this issue.
Is there a T-SQL equivalent of GO that I can use to make sure the CREATE DATABASE gets executed before the USE?
I've tried BEGIN/COMMIT TRANSACTION and BEGIN/END but they didn't help.
Is there a T-SQL equivalent of GO that I can use to make sure the CREATE DATABASE gets executed before the USE?
Yes. Dynamic SQL. Each dynamic SQL invocation is a parsed, compiled, and executed as a separate batch.
EG:
exec ('
create database foo
')
exec ('
use foo
create table bar(id int)
')
Note that when used in dynamic SQL use database only change the database context for the dynamic batch. When control returns to the calling batch, the database context is restored.
In C# you should use separate calls to SqlComand for each batch.
High level steps.
Open connection to master.
Create new database (just create database statement).
Instead of USE call SqlConnection.ChangeDatabase(String) Method
Execute remaining batches
I am new to the stored procedure in oracle and my simple code wont compile in oracle toad.
Here is my code:
code
There is a readline under the ALTER, and it says "Found: "ALTER", expecting select or (: BEGIN BASE COSE...) " why is that?
Oracle doesn't allow you to use DDL natively in PL/SQL. To work around this, you can use EXECUTE IMMEDIATE to run the DDL as a dynamic query.
I'm trying to build a transformation in Kettle that gets FIELDS from a SQL Server Stored Procedure and inserts it in a MySql table.
The problem is that I can't find a way to get stored procedure "fields". I understand that Call DB Procedure task expects in/out params, and that's not my case, so I'm trying to use "Execute SQL Statements" with the following SQL:
exec credisfera.dbo.sp_insere_parcelas #dt_ref = '2016-05-03'
Is there a way to achieve this?
Simply put the exec statement in a Table input step. Upon execution (or "Output fields...", PDI will get the metadata from the JDBC driver.
In a stored procedure, I've to build my own SQL request(because tables names and some properties names are known only at execution time(parameters)).
So Basically I've something like this
EXECUTE IMMEDIATE WITH RESULT SET OFF 'My custom query which select one data'
Usually, I would use the INTO commands, but my parameter is recognized inside the Execute immediate, which seems logic.
(Before you ask: I cannot return this in a result set, the result set is used for another data(and the result of this EXECUTE IMMEDIATE will determine which query I will run(and must be returned)).
How would you approach this problem? I guess it's the same problem on SQL Server-... but I didn't tested on it
You could create a table in compiled Sql and then the dynamic Sql populates it, so that the compiled sql statement after the dynamic part can read the results and update them onto your output params.