stored-functions

SQL Server - where is “sys.functions”?

橙三吉。 提交于 2019-11-27 17:22:01
SQL Server 2005 has great sys.XXX views on the system catalog which I use frequently. What stumbles me is this: why is there a "sys.procedures" view to see info about your stored procedures, but there is no "sys.functions" view to see the same for your stored functions? Doesn't anybody use stored functions? I find them very handy for e.g. computed columns and such! Is there a specific reason sys.functions is missing, or is it just something that wasn't considered important enough to put into the sys catalog views?? Is it available in SQL Server 2008?? Cheers, Marc LukeH I find UDFs are very

Why is it not recommended to use server-side stored functions in MongoDB?

孤者浪人 提交于 2019-11-27 13:44:38
问题 According to the MongoDB documentation, it isn't recommended to use server-side stored functions. What is the reason behind this warning? 回答1: I am sure I have stated the list a couple of times despite the Google search result being filled only with people telling you how to do it: It is eval eval has natural abilities to be easily injected, it is like a non-PDO equilivant to SQL, if you don't buld a full scale escaping library around it it will mess you up. By using these functions you are

MySQL Stored Functions - Dynamic/Variable Table & Column Names

我们两清 提交于 2019-11-27 07:27:52
问题 I'm learning stored procedures/functions/triggers in MySQL this morning and I'm having some problems trying to use variable table and column names in queries. DELIMITER | USE R2R | DROP FUNCTION IF EXISTS getCategoryName | CREATE FUNCTION getCategoryName(LMID INT, levelNum INT) RETURNS VARCHAR(255) BEGIN DECLARE levelName VARCHAR(255) DEFAULT makeLevelName(levelNum); DECLARE levelID INT; DECLARE levelNameID VARCHAR(255) DEFAULT CONCAT(levelName, 'ID'); DECLARE ret VARCHAR(255); SELECT

How to use goto label in MySQL stored function

对着背影说爱祢 提交于 2019-11-27 06:59:22
问题 I would like to use goto in MySQL stored function. How can I use? Sample code is: if (action = 'D') then if (rowcount > 0) then DELETE FROM datatable WHERE id = 2; else SET p=CONCAT('Can not delete',@b); goto ret_label; end if; end if; Label: ret_label; return 0; 回答1: There are GOTO cases which can't be implemented in MySQL, like jumping backwards in code (and a good thing, too). But for something like your example where you want to jump out of everything to a final series of statements, you

Is there a PL/SQL pragma similar to DETERMINISTIC, but for the scope of one single SQL SELECT?

半世苍凉 提交于 2019-11-27 05:59:21
问题 In a SQL SELECT statement, I'd like to execute a function that is deterministic for the scope of that SELECT statement (or transaction would be ok, too): select t.x, t.y, my_function(t.x) from t Many values of t.x are the same so Oracle could omit calling the same function again and again, to speed things up. But if I label the function as DETERMINISTIC , the results may be cached between several executions of this query. The reason why I can't use DETERMINISTIC is because my_function uses a

Why does this MySQL stored function give different results than to doing the calculation in the query?

烈酒焚心 提交于 2019-11-27 04:44:29
问题 This is a question about calculating the distance between two points of latitude and longitude on the earth using a haversine formula, for use in projects where you need to have a 'find my nearest' function. The haversine formula is well discussed and solved in MySQL in this post. I then asked this question about turning it into a stored function so that its available for future projects without having to lookup, remember or re-type the formula in its long form. Its all good. Except my

Functions vs procedures in Oracle

旧城冷巷雨未停 提交于 2019-11-27 04:17:11
问题 can anybody explain what is the main difference between functions and procedures in Oracle? Why must I use procedures if I can do everything with functions? If I cannot call procedure in sql statement, ok, I'll write a function to do the same work. Procedures don't return values, ok, I'll return only sql%rowcount or 1(success), 0(exception) after any dml operation Both procedures and functions can pass variables to calling environment via OUT/IN OUT parameters I heard that the main difference

Recursive stored functions in MySQL

你说的曾经没有我的故事 提交于 2019-11-27 02:23:08
问题 I'm trying to make a function that recursively builds a path for a specific category CREATE FUNCTION getPath(inId INT) RETURNS TEXT DETERMINISTIC BEGIN DECLARE return_path TEXT; DECLARE return_parent_id INT; SELECT CONCAT('/', name) INTO return_path FROM article_categories WHERE id = inId; SELECT parent_id INTO return_parent_id FROM article_categories WHERE id = inId; IF return_parent_id > 0 THEN SELECT CONCAT(getPath(return_parent_id), return_path) INTO return_path; END IF; RETURN return

How to use Table output from stored MYSQL Procedure

南楼画角 提交于 2019-11-26 20:55:13
问题 I've been looking for the last hour or so and haven't found a conclusive answer to this seemingly simple problem: How do you call a stored MYSQL function/procedure and use its output in further SELECT queries? Although this obviously doesn't work, this is the kind of thing I'd like to have: SELECT P.`id` FROM (CALL test_proc()) AS P Where test_proc() is defined by: DROP PROCEDURE IF EXISTS test_proc; DELIMITER ;; CREATE PROCEDURE test_proc() BEGIN SELECT * FROM `table`; END;; DELIMITER ; Just