i have code like this
SELECT ST_GeomFromText('POINT(replace( koordinat, ',', ' '))');
when i ran this query. showing error like this ? how to solve this probem..
ERROR: syntax error at or near "'))'"
LINE 1: ...ECT ST_GeomFromText('POINT(replace( koordinat, ',', ' '))');
First, you must build a string using the concatenate operator ||:
'POINT('|| replace( koordinat, ',', ' ') ||')'
Furthermore is recommended to set the SRID of the output geometry by passing a SRID as second parameter to the function ST_GeomFromText(). Assuming you have lon/lat coordinates, you will use 4326 as SRID:
SELECT ST_GeomFromText('POINT('||replace( koordinat, ',', ' ') || ')', 4326)
FROM your_table;
Related
I have a function a STRING_AGG function which is throwing error
Error message: STRING_AGG aggregation result exceeded the limit of
8000 bytes. Use LOB types to avoid result truncation.
As this Documentation, says I need to convert to varchar(max)
Current:
STRING_AGG(CONCAT([CT].[DeviceType] , ': ' , [COM].[Address]) , ', ')) AS [Contact]
Try:
STRING_AGG(CONVERT(VARCHAR(MAX),(CONCAT([CT].[DeviceType] , ': ' , [COM].[Address])) , ', ')) AS [Contact]
But it is throwing error:
The STRING_AGG function requires 2 argument(s).
What am I doing wrong? Regards
You have put the separator within the concat, it should be the second parameter:
STRING_AGG(CONVERT(VARCHAR(MAX),(CONCAT([CT].[DeviceType] , ': ' , [COM].[Address])) ), ', ') AS [Contact]
Do we have a workaround for the T-SQL CONCAT_WS function? This one throws an error that
is not a recongized built in function name
I presume this is not compatible with my version.
I am currently trying to get a proper format for my full name where MiddleName is or isn't NULL.
First, SQL Server now supports CONCAT_WS(). So, using the built-in function is the simplest "work-around".
As an alternative:
select stuff( (coalesce(', ' + col1, '') +
coalesce(', ' + col2, '') +
coalesce(', ' + col3, '')
), 1, 2, '') as concat_ws
The separator and "2" need to be consistent, of course.
REPLACE(T.FirstName, ' ', '') + '.' +
REPLACE(REPLACE(T.LastName, ' ', ''), '''', '') + '.' + SUBSTRING(CONVERT(varchar(50), T1.Id), 1, 8) +
'#outlook.com' AS 'EmailAddress'
EmailAddress is the one of the column which has above logic. Informatica workflow failing due to conversion with below error. Can any one help me how to handle this.
Source is SQL Server, and target is Oracle
I get this error:
[Informatica][ODBC 20101 driver][Microsoft SQL Server]Invalid operator for data type. Operator equals minus, type equals varchar.
This is not Informatica error. This is an error thrown by MS SQL Server and passes on to Informatica.
This means, the error is thrown by the query. Debug the query on your source system. It seems it some part results in a minus that is then interpreted as substraction by the Query Optimizer.
{FN CONCAT( {FN CONCAT({FN CONCAT({FN CONCAT( {FN CONCAT(REPLACE(T.FirstName,' ',''), '.')}, REPLACE(REPLACE(
T.LastName,' ',''),'''',''))},'.' )}, SUBSTRING(convert(varchar(50),T1.PersonId),1,8))},'#Outlook.com')} AS 'EmailAddress'
Made the changes as above. SQL Server doesnt have any issue with '+' or 'CONCAT'. inforamtica was throwing error for '+' for concatenation in query. Now im able to load the data to Oracle table from SQL Server. Thanks all for the responses and help.
I am a bit new to this site but I have looked an many possible answers to my question but none of them has answered my need. I have a feeling it's a good challenge. Here it goes.
In one of our tables we list what is used to run a report this can mean that we can have a short EXEC [svr1].[dbo].[stored_procedure] or "...From svr1.dbo.stored_procedure...".
My goal is to get the stored procedure name out of this string (column). I have tried to get the string between '[' and ']' but that breaks when there are no brackets. I have been at this for a few days and just can't seem to find a solution.
Any assistance you can provide is greatly appreciated.
Thank you in advance for entertaining this question.
almostanexpert
Considering the ending character of your sample sentences is space, or your sentences end without trailing ( whether space or any other character other than given samples ), and assuming you have no other dots before samples, the following would be a clean way which uses substring(), len(), charindex() and replace() together :
with t(str) as
(
select '[svr1].[dbo].[stored_procedure]' union all
select 'before svr1.dbo.stored_procedure someting more' union all
select 'abc before svr1.dbo.stored_procedure'
), t2(str) as
(
select replace(replace(str,'[',''),']','') from t
), t3(str) as
(
select substring(str,charindex('.',str)+1,len(str)) from t2
)
select
substring(
str,
charindex('.',str)+1,
case
when charindex(' ',str) > 0 then
charindex(' ',str)
else
len(str)
end - charindex('.',str)
) as "Result String"
from t3;
Result String
----------------
stored_procedure
stored_procedure
stored_procedure
Demo
With the variability of inputs you seem to have we will need to plan for a few scenarios. The below code assumes that there will be exactly two '.' characters before the stored_procedure, and that [stored_procedure] will either end the string or be followed by a space if the string continues.
SELECT TRIM('[' FROM TRIM(']' FROM --Trim brackets from final result if they exist
SUBSTR(column || ' ', --substr(string, start_pos, length), Space added in case proc name is end of str
INSTR(column || ' ', '.', 1, 2)+1, --start_pos: find second '.' and start 1 char after
INSTR(column || ' ', ' ', INSTR(column || ' ', '.', 1, 2), 1)-(INSTR(column || ' ', '.', 1, 2)+1))
-- Len: start after 2nd '.' and go until first space (subtract 2nd '.' index to get "Length")
))FROM TABLE;
Working from the middle out we'll start with using the SUBSTR function and concatenating a space to the end of the original string. This allows us to use a space to find the end of the stored_procedure even if it is the last piece of the string.
Next to find our starting position, we use INSTR to search for the second instance of the '.' and start 1 position after.
For the length argument, we find the index of the first space after that second '.' and then subtract that '.' index.
From here we have either [stored_procedure] or stored_procedure. Running the TRIM functions for each bracket will remove them if they exist, and if not will just return the name of the procedure.
Sample inputs based on above description:
'EXEC [svr1].[dbo].[stored_procedure]'
'EXEC [svr1].[dbo].[stored_procedure] FROM TEST'
'svr1.dbo.stored_procedure'
Note: This code is written for Oracle SQL but can be translated to mySQL using similar functions.
I want to use TRANSLATE to replace invalid XML characters in a string that's used in XMLAGG instead of nested REPLACE due to the large number of characters that need to be replaced:
select c.key,
cast( substr( xmlserialize( xmlagg( xmltext( concat( ' | ',
replace(replace(replace(replace(c.comment_text,chr(160),' '), chr(191),' '), chr(176),' '), chr(190),' ')
--translate(c.comment_text, ' ', chr(160)||chr(176)||chr(190)||chr(191))
) ) order by c.comment_date desc ) as clob ), 3, 4000 ) as varchar2) as sum_comment
from comments c
where c.comment_date > current_timestamp - 90
group by c.key
If I run this outside of the XMLAGG I can see that both the TRANSLATE and REPLACE are removing the invalid characters, but inside the XMLAGG I get the error I'm trying to avoid when using TRANSLATE:
An illegal XML character "#xA0" was found in an SQL/XML expression or function argument that begins with string " | A".