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
1 answer

Random Double Function - POSTGRESQL

I'm trying to write a function that takes a minimum and a maximum input and returns a double. Inputs: high (integer) low (integer) Output: val (double) My SQL code is: CREATE OR REPLACE FUNCTION random_between(low INT ,high INT) RETURNS DOUBLE…
2
votes
0 answers

How to Grant Execute All Functions In SQL Server to group

I have a list of function I need to grant execute to specific group, I found that the query should be executed like this GRANT EXECUTE ON [dbo].[FunctionName] TO [GroupName] But since I have 40 functions in the database, so I need to execute it 40…
Med Amin
  • 23
  • 1
  • 4
2
votes
2 answers

What do I do if parameter of function is the same as a column name

I have an SQL function which has a parameter name as id. However, I have a column name which has the same name, id. How do I tell the function how to distinguish between the parameter and the column. My function works perfectly if I change the…
Paul
  • 127
  • 1
  • 1
  • 7
2
votes
1 answer

Stored Procedure error in POSTGRESQL PGADMIN4

I am getting the below error when I try to create either a stored procedure or a stored function in PGADMIN4. How can I fix it: ERROR: syntax error at or near "procedure" LINE 1: create or replace procedure transfer( The code to create the…
2
votes
1 answer

Postgresql, one function calls another function and get 2 out values to caller

Postgresql 12. Want to call function testA() from another function testB(), and assign two "out" values to the 2 local variables. Don't know how to do the assignment, please help. create or replace function testA( out outA int, out outB…
brewphone
  • 1,316
  • 4
  • 24
  • 32
2
votes
1 answer

Oracle function compiles successfully but throws error while executing PLS-00221: is not a procedure or is undefined

I have simple oracle function create or replace function abs.test_func(test_in in number) return number is test_out number ; BEGIN test_out:=test_in; RETURN test_out; END; if I compile it - it compiles successfully. but when I run from PLSQL…
David
  • 4,332
  • 13
  • 54
  • 93
2
votes
2 answers

SQL SERVER - Problems with COALESCE() function

I have this SQL function which is wrapped by a stored procedure: ALTER FUNCTION dbo.GetObjList ( @filterUID int = NULL, @filterSID varchar(32) = NULL ) RETURNS TABLE AS RETURN SELECT ROW_NUMBER() OVER (ORDER BY UID) AS [RowNumber], *…
Learner
  • 3,297
  • 4
  • 37
  • 62
2
votes
3 answers

Get SQL Computed Column Inserted Value

My Table Structure as follow, CREATE TABLE tbl_Info ( [SSEID] BIGINT NOT NULL IDENTITY(1,1), [ShortenKey] AS ConvertToBase([SSEID]), [Title] VARCHAR(500) NULL, ) ConvertToBase Function as…
Sency
  • 2,818
  • 8
  • 42
  • 59
2
votes
1 answer

Oracle/general sql - are all where conditions always checked?

There's a query which does something like this: select * from cars c where c.WheelCount > 0 or CountWheels(c) > 0 Is the function CountWheels called for every row, or just for those rows where t.Count <= 0 ? The thing is that that function contains…
avance70
  • 787
  • 1
  • 11
  • 22
2
votes
2 answers

Why is this SQL Function TicksToDateTime non-deterministic? and how to make it deterministic?

I have the following function "TicksToDateTime" CREATE FUNCTION [dbo].[TicksToDateTime] (@t bigint) RETURNS datetime WITH SCHEMABINDING AS -- converts the given datetime to .NET-compatible ticks -- see…
JKennedy
  • 18,150
  • 17
  • 114
  • 198
2
votes
3 answers

Error when creating a function in Postgres

I am trying to create a postgres function that just returns the friends that a user has in the database. It should just return the first and last names of all the user's friends. However, I keep getting this error: [42601] ERROR: query has no…
2
votes
1 answer

No data output from stored procedure (Postgresql)

I have a basic stored procedure for a select statement. The select statement by itself works and shows me the data output, but when I try calling it from a stored procedure, it says 'CALL Query returned successfully in 107 msec', but there's no data…
2
votes
2 answers

How to create a conditional insert function in Postgresql?

I try to write a function to insert some values in column3 in my table based on values inside this table, but I'm not so familiar with writing functions in Postgresql 9.6. --Create some table CREATE TABLE test(column1 INT, column2 INT, column3…
DrSnuggles
  • 217
  • 1
  • 14
2
votes
0 answers

Why do functions slow down queries in mysql-view?

I noticed the following: I'm creating a view for a table where some columns contain csv values. I want to split those csv files on the fly and make them individual columns in the view. As a start, I simply created a function that returns the input…
membersound
  • 81,582
  • 193
  • 585
  • 1,120
2
votes
3 answers

Creating a scalar function that takes input, and ranks unit prices in descending order

I am having a hard time developing a proper scalar function to work as intended. It needs to take an input of money type. I have a Products table, with a UnitPrice column that I am focused on. I need my function to sort products in descending order…
Chris
  • 41
  • 3