stored-procedures

How to set a variable to the result of a stored procedure inside a Trigger MYSQL?

社会主义新天地 提交于 2020-08-26 04:58:25
问题 I have a little problem here, I'm making a trigger for my DB work, but I don't know how to use a stored procedure inside a trigger, I want to save the result of the procedure in a variable and then use the variable later on an IF comparator, this is my code: DELIMITER @ CREATE TRIGGER insert_players AFTER INSERT ON players FOR EACH ROW BEGIN DECLARE A varchar(50); set A = CALL consult_sex(player_name); //I WANT SOMETHING LIKE THIS IF A != FEMALE THEN INSERT INTO males (id_player, player

Spring SimpleJdbcCall default (optional) arguments

给你一囗甜甜゛ 提交于 2020-08-24 05:50:22
问题 I am trying to invoke a stored procedure which has default (optional) arguments without passing them and it is not working. Essentially the same problem as described here. My code: SqlParameterSource in = new MapSqlParameterSource() .addValue("ownname", "USER") .addValue("tabname", cachedTableName) .addValue("estimate_percent", 20) .addValue("method_opt", "FOR ALL COLUMNS SIZE 1") .addValue("degree", 0) .addValue("granularity", "AUTO") .addValue("cascade", Boolean.TRUE) .addValue("no

How to Build select Query split Temp Value to two column one Per Number And Another to Text when Flag Allow 1?

佐手、 提交于 2020-08-10 23:24:50
问题 I work on a query for SQL Server 2012. I have an issue: I can't build select Query split Column Temp value to two Column When row in the temp table #nonparametric has the flag Allow = 1, it must split column Temp value from #nonparametric to two column when the flag Allow = 1 . suppose column Temp value has value 50.40 kg it must split to two column First column with number so it will have 50.40 and it will be same Name as Parametric . Second column with Text so it will have kg and it will be

How to write clean SQL Server stored procedures

女生的网名这么多〃 提交于 2020-08-07 05:54:57
问题 When developing stored procedure, the code is typically far from clean. It is often impractical to break down the stored procedure code into single responsibility (CTE's, long select lists, breaking down adds even more functions/procedures and complexity). PL/SQL provide packages, but there is not an equivalent in SQL Server and I minimal experience with those to weigh in on how well they help with the Clean Code problem. One of my projects relies heavily on stored procedure, with a great

Pros and Cons of Triggers vs. Stored Procedures for Denormalization

◇◆丶佛笑我妖孽 提交于 2020-08-02 06:34:10
问题 When it comes to denormalizing data in a transactional database for performance, there are (at least) three different approaches: Push updates through stored procedures which update both the normalized transactional data and the denormalized reporting/analysis data; Implement triggers on the transactional tables that update the secondary tables; this is almost always the route taken when maintaining histories; Defer the processing to a nightly batch process, possibly doing an ETL into a data

Setting a customized option in a stored procedure

夙愿已清 提交于 2020-07-22 22:26:14
问题 I'm trying to set a custom option in a stored procedure, but it is storing the variable name and not contents of the variable. CREATE OR REPLACE FUNCTION set_user(_user_id bigint, is_local boolean default true) returns void AS $$ BEGIN SET my.user_id TO _user_id; END; $$ LANGUAGE PLPGSQL; select set_user(1); select current_setting('my.user_id'); current_setting ----------------- _user_id (1 row) I expect current_setting to return 1 , not the string value "_user_id" . 回答1: First solution

Setting a customized option in a stored procedure

最后都变了- 提交于 2020-07-22 22:21:54
问题 I'm trying to set a custom option in a stored procedure, but it is storing the variable name and not contents of the variable. CREATE OR REPLACE FUNCTION set_user(_user_id bigint, is_local boolean default true) returns void AS $$ BEGIN SET my.user_id TO _user_id; END; $$ LANGUAGE PLPGSQL; select set_user(1); select current_setting('my.user_id'); current_setting ----------------- _user_id (1 row) I expect current_setting to return 1 , not the string value "_user_id" . 回答1: First solution

Setting a customized option in a stored procedure

ⅰ亾dé卋堺 提交于 2020-07-22 22:19:16
问题 I'm trying to set a custom option in a stored procedure, but it is storing the variable name and not contents of the variable. CREATE OR REPLACE FUNCTION set_user(_user_id bigint, is_local boolean default true) returns void AS $$ BEGIN SET my.user_id TO _user_id; END; $$ LANGUAGE PLPGSQL; select set_user(1); select current_setting('my.user_id'); current_setting ----------------- _user_id (1 row) I expect current_setting to return 1 , not the string value "_user_id" . 回答1: First solution

How to return a value from a stored procedure (not function)?

跟風遠走 提交于 2020-07-22 05:41:31
问题 I have a Stored Procedure that inserts, updates or deletes tablerows. It was working fine while all parameters were used as input. However, I need to return the ID of last inserted row. For that I tried using an INOUT parameter and RETURNING after the INSERT statement to return the ID. However, I am not sure how to bind the returned ID to the INOUT parameter. Following is the code for stored procedure: CREATE OR REPLACE PROCEDURE public.spproductinsertupdatedelete( _ser integer, _subcategid