Question

How can I merge two numbers into varchar in sql function?

The function output is varchar(40) and the two numbers are parameters of function.

I found this: siteowner := concat(eov_y, eov_x); but it doesn't work well.

siteowner is the output. I am using Oracle 10g.

for examlpe eov_y = 234543 and eov_x = 675654 and the output will be siteowner = 234543 / 675654.

Was it helpful?

Solution

There may be more efficient ways to do this but this should work

LEFT(CAST(@eov_y AS varchar) + CAST(@eov_x AS varchar), 40)

For clarity here is an example of how this could be used

CREATE FUNCTION mergeNumbers 
(
    @eov_y INT,
    @eov_x INT
)
RETURNS varchar(40)
AS
BEGIN
    RETURN LEFT(CAST(@eov_y AS varchar) + CAST(@eov_x AS varchar), 40);
END

Which can be called with

SELECT dbo.mergeNumbers(11244,456);

This assumes SQL Server

As per comments, I don't have an Oracle db to try this but it should be about right

CREATE OR REPLACE FUNCTION mergeNumbers (eov_y NUMBER, eov_x NUMBER) RETURN VARCHAR IS
   siteowner VARCHAR(40);
BEGIN
   siteowner := SUBSTR(CAST(@eov_y AS VARCHAR) + CAST(@eov_x AS VARCHAR), 40);     
   RETURN siteowner;
END;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top