Questions tagged [sql-function]

A function defined in a relational database system. Most RDBS's include numerous built-in functions and also allow for the creation of additional custom functions.

908 questions
2
votes
2 answers

Use Java functions with Apache Derby

I've encountered problems with using functions in Apache Derby, in that I can't get Derby to find my self-defined functions. The typical error message looks like this: The class 'de.uniba.kinf.projm.hylleblomst.database.sql.utils.GroupConcat' does…
styps
  • 279
  • 2
  • 14
2
votes
3 answers

Recursive in SQL Server 2008

I've a scenario(table) like this: This is table(Folder) structure. I've only records for user_id = 1 in this table. Now I need to insert the same folder structure for another user. Sorry, I've updated the question... yes, folder_id is identity…
2
votes
1 answer

function which returns values that have last 2 numbers greater than a certain value for INT datatype

Is there any SQL function that I can use to return all those records that have last 2 numbers greater than 31. Basically, there is one column: OpenDate in INT datatype stored as '19810281' and the last 2 values are 81(which should be a date) so it…
Geetanjali Sachdeva
  • 133
  • 1
  • 5
  • 14
2
votes
1 answer

Performance of a SQL Server Scalar Function

CREATE FUNCTION GETBUSINESSDATEDIFF ( @startdate as DATETIME, @enddate as DATETIME ) RETURNS INT AS BEGIN DECLARE @res int SET @res = (DATEDIFF(dd, @startdate, @enddate) + 0) -(DATEDIFF(wk, @startdate, @enddate) * 2) +(CASE WHEN…
CH81
  • 387
  • 4
  • 12
2
votes
4 answers

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

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 /…
BCS
  • 75,627
  • 68
  • 187
  • 294
2
votes
3 answers

Create SQL function referring to a table or column that does not exist (yet)

I want to load some SQL functions in a empty database through psql: psql -d my_database -f fuctions.sql --set ON_ERROR_STOP=1 I use --set ON_ERROR_STOP=1 because I want that psql fails if the script contains errors. The content of functions.sql…
Tom-db
  • 6,528
  • 3
  • 30
  • 44
2
votes
1 answer

How to insert SELECT LISTAGG values to varchar variable

I am writing an Oracle user defined function. How can I insert listtagg values Pears, Oranges, Bananas, Apples into a variable products and return in function. products VARCHAR2(4000); BEGIN SELECT LISTAGG(product_name, ', ') WITHIN GROUP (ORDER BY…
SKARVA Bodavula
  • 903
  • 11
  • 17
2
votes
1 answer

Drop function in Postgres

I have the following function: CREATE FUNCTION "updateStat"(_request_date timestamp without time zone, _calls integer, _latency integer) RETURNS void AS $$ BEGIN LOCK TABLE "statistics" IN SHARE ROW EXCLUSIVE MODE; WITH upsert AS (UPDATE…
lante
  • 7,192
  • 4
  • 37
  • 57
2
votes
5 answers

MySQL query that returns all the rows that have been added in the last 24 hours

I have a table that contains the next columns: ip(varchar 255), index(bigint 20), time(timestamp) each time something is inserted there, the time column gets current timestamp. I want to run a query that returns all the rows that have been added in…
Michael S.
  • 305
  • 4
  • 17
2
votes
2 answers

Constraint violation on parallel run

I created a function that will serves as primary key for my table CREATE FUNCTION dbo.NewCustomerPK() RETURNS VARCHAR (10) AS BEGIN DECLARE @LastCustID VARCHAR(10) DECLARE @newID INT DECLARE @charID CHAR(10) SELECT @LastCustID =…
2
votes
3 answers

SQL Function Constraint for Denormalized Data

How do I create a function constraint for denormalized data? -- graduation_class table graduation_class_id | graduation_year_id 123 1 456 2 -- user table user_id | graduation_class_id | …
Adam Levitt
  • 10,316
  • 26
  • 84
  • 145
2
votes
3 answers

SQL Table valued function

I have a Table Valued Function as following. But it is giving a error. That is saying "Msg 156, Level 15, State 1, Procedure GetOpeningByRepAcc, Line 36 Incorrect syntax near the keyword 'begin'." But I didn't able to fix this. Any idea…
Tom
  • 1,343
  • 1
  • 18
  • 37
2
votes
3 answers

SQL Character Replace function extend

I'am currently developing a program and i want to write a function which is accept a value in following format "AAAA BBBB" CCCC DDDD EEEE "FFFF GGGG HHHH" I want to replace the spaces in above with "_" and need a output as showed following format…
2
votes
1 answer

Replace spaces using function in sql

I'am currently developing a program and i want to write a function which is accept a value in following format "AAAA BBBB" CCCC DDDD EEEE "FFFF GGGG HHHH" I want to replace the spaces in above with "_" and need a output as showed following…
2
votes
1 answer

How to write a SQL Server scalar function to calculate the sum?

I'm having an issue with SQL Server 2008, I want to write a function that returns the sum of a specific column, the code goes like this: CREATE FUNCTION [dbo].[GetIssuesSum](@i int) RETURNS int AS BEGIN DECLARE @IssueSum int SELECT SUM…
user3804193
  • 113
  • 4
  • 11