stored-procedures

Dynamic Variable in Cursor in Oracle stored procedure

跟風遠走 提交于 2021-01-29 08:02:44
问题 Need help in passing dynamic variable (table name) in cursor in Oracle stored procedure. My stored procedure: CREATE OR REPLACE PROCEDURE ABCDEF (TBL_NAME IN VARCHAR) IS CURSOR CUR IS SELECT * FROM TABLEA BEGIN FOR rec IN CUR LOOP . . . END I NEED THIS TABLEA in cursor to be replaced by TBL_NAME variable. I tried to make the cursor statement as executable statement but it didn't help me. Suggestions, please 回答1: Made this working using part of the solution above. Thanks for the suggestions.

How to unit test a function in .NET Core 3.1 that uses ExecuteSqlRawAsync to call a stored procedure?

南笙酒味 提交于 2021-01-29 06:02:11
问题 I'm writing an API in ASP.NET Core 3.1, using EF Core to access a SQL Server database. I have a function in the API that needs to call a stored procedure with several input parameters and an output parameter. A simplified version of this function is below. I am using a DbContext with .UseInMemoryDatabase() for other tests, but the in memory database cannot be used with stored procedures. (This solution is database first, not code first. It would be possible to change the stored procedure if

MYSQL Stored Procedure - Concat Row Value

拈花ヽ惹草 提交于 2021-01-29 05:19:50
问题 Update Sorry for the delay in responding. I was traveling yesterday when I sent that in. I am on version 5.6. This is what I was thinking of and it does mark when there is change, but the issue is the sort causes the result set to fall out of order. I guess I will need to create a temporary table and just apply the conditional formatting once the order has been set. SET @previousstate = ''; SELECT frm.fi_details.PortfolioCode AS 'Portfolio Code', id, if(@previousstate != frm.fi_details

Mysql stored procedure gives unknown column error when executed [duplicate]

杀马特。学长 韩版系。学妹 提交于 2021-01-29 03:33:48
问题 This question already has an answer here : mysql Unknown column variable in the field list (1 answer) Closed 1 year ago . I have written a small stored procedure to store redmine issue and timelog entries in my private redmine. The procedure is stored, but when I call it, it gives SQL error (1054): Unknown column 'uid' in 'field list' error. The column that the error message mention is exists, the type matches. Rewrite code, redeploy db When the second insert removed from SP, it works great.

Mysql stored procedure gives unknown column error when executed [duplicate]

坚强是说给别人听的谎言 提交于 2021-01-29 03:20:46
问题 This question already has an answer here : mysql Unknown column variable in the field list (1 answer) Closed 1 year ago . I have written a small stored procedure to store redmine issue and timelog entries in my private redmine. The procedure is stored, but when I call it, it gives SQL error (1054): Unknown column 'uid' in 'field list' error. The column that the error message mention is exists, the type matches. Rewrite code, redeploy db When the second insert removed from SP, it works great.

Updating Identity Column of a table with consecutive numbers through SQL Stored Procedure

别等时光非礼了梦想. 提交于 2021-01-29 02:07:13
问题 After deleting the duplicate records from the table, I want to update Identity column of a table with consecutive numbering starting with 1. Here is my table details id(identity(1,1)), EmployeeID(int), Punch_Time(datetime), Deviceid(int) I need to perform this action through a stored procedure. When i tried following statement in stored procedure DECLARE @myVar int SET @myVar = 0 set identity_insert TempTrans_Raw# ON UPDATE TempTrans_Raw# SET @myvar = Id = @myVar + 1 set identity_insert

Updating Identity Column of a table with consecutive numbers through SQL Stored Procedure

依然范特西╮ 提交于 2021-01-29 02:05:36
问题 After deleting the duplicate records from the table, I want to update Identity column of a table with consecutive numbering starting with 1. Here is my table details id(identity(1,1)), EmployeeID(int), Punch_Time(datetime), Deviceid(int) I need to perform this action through a stored procedure. When i tried following statement in stored procedure DECLARE @myVar int SET @myVar = 0 set identity_insert TempTrans_Raw# ON UPDATE TempTrans_Raw# SET @myvar = Id = @myVar + 1 set identity_insert

MySQL 5.7, sort table by column name using a variable in Stored procedure

空扰寡人 提交于 2021-01-28 21:51:51
问题 I have a simple table with some data: DROP TABLE IF EXISTS `MY_TABLE`; CREATE TABLE IF NOT EXISTS `MY_TABLE` ( `id` CHAR(40) CHARACTER SET 'utf8' COLLATE 'utf8_bin' NOT NULL, PRIMARY KEY (`id`) ); INSERT INTO `MY_TABLE` (`id`) VALUES (1); INSERT INTO `MY_TABLE` (`id`) VALUES (2); INSERT INTO `MY_TABLE` (`id`) VALUES (3); Now I have a procedure to retrieve this data ordering from a column. This works as expected: DROP PROCEDURE IF EXISTS test_procedure; DELIMITER $$ CREATE PROCEDURE test

Condition based where clause SQL Server stored procedure

ε祈祈猫儿з 提交于 2021-01-28 19:41:52
问题 Can someone suggest how to add a condition in WHERE clause of my stored procedure? CREATE Procedure getAllEmployeesByDeptAndFlag @Dept int, @sal int, @Flag int AS if @flag = 1 select * from employee where Department = @dept and @sal < 10000 else select * from employee where Department = @dept Is there any way to simplify above procedure? 回答1: You could use the or logical operator to unify both branches of the if statement: select * from employee where Department = @dept AND (@flag != 1 OR

how to write to dynamically created table in Redshift procedure

人走茶凉 提交于 2021-01-28 19:12:43
问题 I need to write a procedure in Redshift that will write to a table, but the table name comes from the input string. Then I declare a variable that puts together the table name. CREATE OR REPLACE PROCEDURE my_schema.data_test(current "varchar") LANGUAGE plpgsql AS $$ declare new_table varchar(50) = 'new_tab' || '_' || current; BEGIN select 'somestring' as colname into new_table; commit; END; $$ This code runs but it doesn't create a new table, no errors. If I remove the declare statement then