sql-function

SQL Server function intermittent performance issues

雨燕双飞 提交于 2019-12-21 06:42:30
问题 We have a function in our database that searches two large tables to see if a value exists. It is a pretty large query, but it is optimized to use indexes and generally runs pretty fast. Three times over the past 2 weeks, this function decided to go haywire and run extremely slow, which causes deadlocking and bad performance all around. This happens even at times of less than peak usage. Rebuilding the function using "Alter Function" in SQL Server seems to take care of the issue. Once we do

Can I run an HTTP GET directly in SQL under MySQL?

耗尽温柔 提交于 2019-12-20 04:37:15
问题 I'd love to do this: UPDATE table SET blobCol = HTTPGET(urlCol) WHERE whatever LIMIT n; Is there code available to do this? I known this should be possible as the MySQL Docs include an example of adding a function that does a DNS lookup. MySQL / windows / Preferably without having to compile stuff, but I can. (If you haven't heard of anything like this but you would expect that you would have if it did exist, A "proly not" would be nice.) EDIT: I known this would open a whole can-o-worms re

Why do SQL Server Scalar-valued functions get slower?

妖精的绣舞 提交于 2019-12-17 10:35:09
问题 Why do Scalar-valued functions seem to cause queries to run cumulatively slower the more times in succession that they are used? I have this table that was built with data purchased from a 3rd party. I've trimmed out some stuff to make this post shorter... but just so you get the idea of how things are setup. CREATE TABLE [dbo].[GIS_Location]( [ID] [int] IDENTITY(1,1) NOT NULL, --PK [Lat] [int] NOT NULL, [Lon] [int] NOT NULL, [Postal_Code] [varchar](7) NOT NULL, [State] [char](2) NOT NULL,

How to manipulate ntext type data in stored procedure of SQL Server 2008

落花浮王杯 提交于 2019-12-13 14:08:25
问题 I was wondering how to manipulate ntext datatype in stored procedure of SQL Server 2008. We have a column of type ntext in a table. We have to fetch data from that column, parse the data, change and then store it back. For all of the above task we have to use one or more than on stored procedure/function. So data passing between stored procedures are also involved. 回答1: If you're in the position to change the schema, consider changing the data type from ntext to nvarchar(max) . The later is

SQL - Can I have a Group By clause after a nestled Select?

跟風遠走 提交于 2019-12-13 10:22:23
问题 For example: Select max(date) From table A Where max(date) < any (select.. ...) Group By Book_Name,Client_Name So the max(date) field could be compared to the Nestled Select return, as if the grouping of the greater Select was already made. 回答1: What you want is typically done with the HAVING clause. Select Book_Name,Client_Name, max(date) From table A Group By Book_Name,Client_Name HAVING max(date) < any (select.. ...) I removed reference to the other answer. I don't think it was correct and

Spatial Data SQL Reprojection Function issues

放肆的年华 提交于 2019-12-13 05:47:07
问题 Hello I am just learning postGIS and thus postgresql (9.1) and am trying to save some time copying the same code over and over by creating an sql function to reproject some spatial data. Create Function reproject_shapefile(text,text,numeric) returns void as $$ -- Reprojects shapefiles given that they follow the pattern "gid * the_geom" CREATE TABLE $2 AS SELECT *, ST_Transform(the_geom,$3) AS the_geom2 FROM $1; Alter table $2 add Primary Key (gid); Alter table $2 drop column the_geom; Alter

Combine postgres function with query

浪尽此生 提交于 2019-12-13 04:45:00
问题 I currently struggle with the output of a sql-function which I require in my result-set: SELECT getAdditionalInfoAboutDate(date) from sampleCalendar The problem is, that I get the result in the following way: "Attribute1, Attribute2, Attribute3" "Attribute2, Attribute3, Attribute4" ... As you can see I get my desired result but it only has one column even though my function returns 3 columns. When I try to create a statement like: SELECT (Select * from getAdditionalInfoAboutDate(date)) from

Create and execute function in SQL Server

我们两清 提交于 2019-12-12 06:33:55
问题 I have four tables: dbo.Projects dbo.Locations (id, location name) dbo.Purpose (id, Purposename) dbo.Types (id, typname) I have a search criteria, this criteria is filled with data from database tables: locations , purpose and types . I want to create a function that returns table with search result from projects dependent on other tables. I have created one but it does not do what I need: ALTER FUNCTION SearchProjects ( @location nvarchar(50), @purpose nvarchar(50), @type nvarchar(50) )

How to call Oracle function which has SYS_REFCURSOR as OUT Parameter

烈酒焚心 提交于 2019-12-11 14:06:57
问题 create or replace FUNCTION test_fun ( p_ref_cur OUT SYS_REFCURSOR, p_a_code IN NUMBER DEFAULT 0, p_category IN package.category%TYPE DEFAULT NULL, p_name IN package.name%TYPE DEFAULT NULL, p_display_name IN package.display_name%TYPE DEFAULT NULL, p_rowid IN package."rowid"%TYPE DEFAULT NULL, p_flg IN package.flg%TYPE DEFAULT '1', p_mod_dat IN package.mod_dat%TYPE DEFAULT SYSTIMESTAMP, p_mod_usr IN package.mod_usr%TYPE DEFAULT NULL ) RETURN NUMBER AS How to call this function in oracle which

Problem with if-statement used at Table-returned-function in SQL

馋奶兔 提交于 2019-12-11 12:43:08
问题 I have simplified my function to the following: create function [dbo].[UserSuperTeams](@ProjectId int) returns table as return if @ProjectId=0 begin select TeamId from TblTeam t union select 0 as TeamId end else begin select t.TeamId from TblTeam t union select 1 as TeamId end; go I cannot make it work.. It seems I have some syntax errors, but I cannot figure out how to make it work.. Any idea? 回答1: If you are going to use t-sql code in the function, you need to define the table in the