dynamic-sql

Can MySQL triggers be created with dynamic SQL from within a stored procedure?

▼魔方 西西 提交于 2020-01-03 10:57:06
问题 Is it possible to create a trigger in MySQL using dynamically generated SQL from within a stored procedure? I am executing other dynamically constructed queries in my procedure by preparing a statement, but when I try the same approach to create a trigger I get the following error: ERROR Code: 1295This command is not supported in the prepared statement protocol yet From Bug #31625, PREPARED STATEMENT syntax does not allow to create TRIGGERS I see other people have been complaining about the

Dynamically define returning row types based on a passed given table in plpgsql?

冷暖自知 提交于 2020-01-03 03:32:06
问题 I'm dynamically building a query in a plpgsql function that accepts a source table as an incoming variable. I want to return the results of the built SELECT statement, which performs aggregations on the given table, and returns results of that table. However, at the moment I'm getting the following error: ********** Error ********** ERROR: a column definition list is required for functions returning "record" SQL state: 42601 So it looks like I need to define column types of the record rows I

joined table rows into columns with column titles from original rows

爱⌒轻易说出口 提交于 2020-01-02 17:40:31
问题 I have three MYSQL tables, simplified, with following columns: ModuleEntries (MDE_ID) ModuleFields (MDF_ID, MDF_Label) ModuleEntryFieldValues (MFV_ID, MFV_MDE_ID, MFV_MDF_ID, MFV_Value) As you can see from the simplified column list, ModuleEntryFieldValues is the table which states that "for an entry, this field has this value". Now, I would like to retrieve this information in one "flat" recordset. I have managed to get things working, but not entirely to what i want. With the help of a

Using dynamic query + user defined datatype in Postgres

扶醉桌前 提交于 2020-01-02 10:26:11
问题 I need a function to normalize my input table features values. My features table has 9 columns out of which x1,x2...x6 are the input columns I need to scale. I'm able to do it by using a static query: create or replace function scale_function() returns void as $$ declare tav1 features%rowtype; rang1 features%rowtype; begin select avg(n),avg(x0),avg(x1),avg(x2),avg(x3),avg(x4),avg(x5),avg(x6),avg(y) into tav1 from features; select max(n)-min(n),max(x0)-min(x0),max(x1)-min(x1),max(x2)-min(x2)

Dynamic access to tables from another database inside an user function

流过昼夜 提交于 2020-01-02 07:26:31
问题 I have an user defined table function in SQL Server that aggregate data from several tables including a couple of tables of another database. That is done hardcoding the name of the database in the queries, but we want to make the database name configurable (because our databases usually share the server with the databases of other applications). I tried to construct a dynamic query string inside the function using the database name that is stored in a configuration table, but: When I tried

Binding variables in dynamic PL/SQL

点点圈 提交于 2020-01-01 19:27:07
问题 I have a dynamic PL/SQL that will construct the SELECT statement based on what the searching criteria input from the users,likes: l_sql := 'SELECT * INTO FROM TABLEA WHERE 1=1 '; IF in_param1 IS NOT NULL THEN l_sql := l_sql || 'AND column1 = in_param1 '; END IF; IF in_param2 IS NOT NULL THEN l_sql := l_sql || 'AND column2 = in_param2 '; END IF; ................................... IF in_paramXX IS NOT NULL THEN l_sql := l_sql || 'AND columnXX = in_paramXX '; END IF; To reduce the hard parse

Invoking a function call in a string in an Oracle Procedure

家住魔仙堡 提交于 2020-01-01 19:00:11
问题 I writing an application using Oracle 10g. I am currently facing this problem. I take in "filename" as parameter of type varchar2. A sample value that filename may contain is: 'TEST || to_char(sysdate, 'DDD')'. In the procedure, I want to get the value of this file name as in TEST147. When i write: select filename into ffilename from dual; I get the value ffilename = TEST || to_char(sysdate, 'DDD') whick makes sense. But how can I get around this issue and invoke the function in the string

Build dynamic SQL with “AND” expressions without confusing nested conditionals?

二次信任 提交于 2020-01-01 16:52:48
问题 I'm fairly new to php and coding in general. I have a series of conditions I need to test if they are set. They are $option1, $option2, $option3 if (isset($option1)){ if (isset($option2)){ if (isset($option3)){ $query = "SELECT * FROM Group WHERE FirstOption = '$option1' AND SecondOption = '$option2' AND ThirdOption = '$option3'"; } else { $query = "SELECT * FROM Group WHERE FirstOption = '$option1' AND SecondOption = '$option2"; } } else { $query = "SELECT * FROM Group WHERE FirstOption = '

Can I rollback Dynamic SQL in SQL Server / TSQL

北战南征 提交于 2020-01-01 11:58:15
问题 Can I run a dynamic sql in a transaction and roll back using EXEC: exec('SELECT * FROM TableA; SELECT * FROM TableB;'); Put this in a Transaction and use the @@error after the exec statement to do rollbacks. eg. Code BEGIN TRANSACTION exec('SELECT * FROM TableA; SELECT * FROM TableB;'); IF @@ERROR != 0 BEGIN ROLLBACK TRANSACTION RETURN END ELSE COMMIT TRANSACTION If there are n dynamic sql statements and the error occurs in n/2 will the first 1 to ((n/2) - 1) statements be rolled back

Insert from Dynamic Query in Postgres

大憨熊 提交于 2019-12-31 07:26:19
问题 With reference solution I've posted in my previous post resulted in one more situation. While trying to insert into my destination table(schema as below). -- Table: normalized_transaction -- DROP TABLE normalized_transaction; CREATE TABLE normalized_transaction ( transaction_id uuid, file_id uuid, account_number character varying(40), currency character varying(3), trade_date date, value_date date, narration character varying(200), amount numeric, mesitis_account_number character varying(50),