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

Call of function of a database from the java-program

There is a Postgresql database with the following function cap CREATE OR REPLACE FUNCTION net_train(terms text[], answer integer) RETURNS void AS $BODY$begin --this code is stub end;$BODY$ LANGUAGE plpgsql VOLATILE COST 100; ALTER FUNCTION…
user1851132
  • 341
  • 1
  • 6
  • 15
-1
votes
1 answer

How to call an Oracle Function with multi out parameters

Possible Duplicate: CALLING A STORED PROCEDURE IN TOAD I am given a function in Oracle as i have shown below.However i could not make it run. FUNCTION GetAdres (pCif NUMBER, pAddressno NUMBER DEFAULT 0, …
user1171708
  • 87
  • 2
  • 6
  • 13
-1
votes
2 answers

Join table with different datatype

I have following tables: Orders id int orderName varchar(5000) Communication body varchar(5000) attachment varchar(5000) Sample Orders data: id name 132 ordGD 589 ordPG 6321 ordMF Sample Communication data: body attachment body1 …
-1
votes
2 answers

To call some sql code to reset values of local variables

I am using Sql Server 2008. In my sql file, I have defined 5 local variables (all of them int) and set them all to 0. I then do some operations (not in a loop). After each operation, I need to reset the local variables' values to 0. Right now, I am…
user1274655
  • 151
  • 1
  • 4
  • 9
-2
votes
1 answer

Multiple errors in SQL Server Function

I'm trying to make a function that evaluates the expiration date in a policy and based on that when is called in a Query it returns the text values ('Monthly'..and so on). but i'm getting a few errors of type "Incorrect syntax near Begin, declare…
-2
votes
1 answer

convert varchar to INT SQL -Conversion Failed

I am trying to convert varchar to Int and i tried cast, convert, try_cast but getting an error conversion failed when converting varchar to datatype INT.Any other way to convert it? select cast('123RA' as INT) as p
learner123
  • 37
  • 1
  • 7
-2
votes
2 answers

How to use substring and charindex for parsing value from first column and create new column

I have a col column in the table and want to parse only the Line numbers from this column. Your formula works if the line number has only one letter. But in my case Line number changes up to 4 letters. My column looks like below one, – enter image…
-2
votes
2 answers

Filter a database table in Ruby, migrating code to Postgres

# Users | id | name | age | | ----- | -------- | ---- | | 1 | Rand | 25 | | 2 | Mat | 24 | | 3 | Perrin | 23 | Given the above table I've been building queries against it in Rails with the basic stuff which…
Eyeslandic
  • 14,553
  • 13
  • 41
  • 54
-2
votes
1 answer

datediff function in postgressql

i am new in PostgreSQL i try to create function this is code CREATE OR REPLACE FUNCTION diff(date Timestamp) RETURNS void As $$ declare CURRENT_DATE Timestamp; number numeric; begin CURRENT_DATE=(SELECT…
-2
votes
3 answers

SQL query/function to extract the first number from a string? not just the 1st numerical digit but the entire number until we hit a non-numeric value

I have two input strings that look like 'London 350 Paris 456 eu iu' and 'New York 154 Seattle 890 pc appl iu'. Now, I need the first number from the string. So the query/function needs to loop through the entire string and get all numbers from the…
Susie Dent
  • 73
  • 2
  • 6
-2
votes
1 answer

Scala: Using a spark sql function when selecting column from a dataframe

I have a two table/dataframe: A and B A has following columns: cust_id, purch_date B has one column: cust_id, col1 (col1 is not needed) Following sample shows content of each table: Table A cust_id purch_date 34564 2017-08-21 34564 …
skdhfgeq2134
  • 426
  • 1
  • 4
  • 16
-2
votes
2 answers

How to send tableName and columnName to sql function and return result

I want to create a T-SQL function, send table name and column name to it, and get the max value of this column. I wrote a function like this: CREATE FUNCTION getMaxValue (@TableName nvarchar(30),@FieldName nvarchar(30)) RETURNS nvarchar(max)…
-2
votes
1 answer

The equivalent of SQL's LIKE and _ wildcard in C#

I have a SQL function that needs to be converted to C#. The SQL function uses the LIKE keyword and the wildcard '_'. How can I write the equivalent C# function? Here is the SQL function: Create Function [dbo].[fnGetWarehouseByGrade222] ( @Grade…
Shon.Su
  • 111
  • 1
  • 6
-3
votes
1 answer

Postgresql function has syntax error at If. Why?

I am new to writing functions on postgres. So I was trying to write a function that checks if a row exists. If it exists then it returns the row with a flag 'Exists', else it inserts a row and returns it with a flag 'New'. But I am facing a simple…
-3
votes
1 answer

Add character after specific character in sql server

I have a string and need to add character ',' after each character'}' and the string doesn't have fixed length and need to add '[' in the start of text and ']' in the end of text for example :
1 2 3
60
61