Replace function not supporting for bigger text and text has single quote - snow

this is the statement execute from SNowflake SP.
var sql_Statement = "select regexp_replace ('" + mainSIDColsSrc + "'', 'source_doc:','') " ;
form the query like this :
select regexp_replace ('(trim(NVL(SOURCE_DOC:claimNumber::string,'~')) ||'^'|| trim(NVL(SOURCE_DOC:notificationType::string,'~')) ||'^'|| trim(NVL(SOURCE_DOC:estimateId::string,'~')) ||'^'|| trim(NVL(SOURCE_DOC:assignmentId::string,'~')))'', 'source_doc:','')
if run the above query :
SQL compilation error: syntax error line 1 at position 82 unexpected '~'. syntax error line 1 at position 153 unexpected '~'. syntax error line 1 at position 305 unexpected ':'. parse error line 1 at position 311 near ''.

Related

Insert 0 values into Postgres: Numeric Field Error

I have a problem when inserting "0" value into numeric field in PostgreSQL via PHP.
insert into canalis_db.cor_cust_corp_fncl_rprt
(corp_fncl_rprt_id,
customer_id,
rprt_period,
asset) values(
'ca423557-7788-36e3-7788-d36f8c130a83',
'ca4160e2-0189-12b7-e6a6-635819ac9aa2',
'2020', 
0) 
it well show error message.
Error: ERROR: syntax error at or near "0"
Position: 395
SQLState: 42601
ErrorCode: 0
Is there something error in my sql syntax?

`FOR UPDATE` breaks batch execution in HANA

HANA 102.05 fails to execute the following code:
CREATE TABLE ATABLE( f INT );
CREATE PROCEDURE TestProc()
AS
BEGIN
SELECT f FROM ATABLE
FOR UPDATE; -- Without FOR UPDATE it works
END;
SELECT 'Hello' FROM DUMMY;
complaining that:
SAP DBTech JDBC: [257]: sql syntax error: incorrect syntax near "SELECT": line 8 col 2 (at pos 124)
which points outside the proceudure, at SELECT 'Hello'. The procedure itself compiles without error. The entire script completes successfully if I remove the FOR UPDATE directive. What is wrong with the original?
Update
When I execute the same query from hdbsql.exe I get:
0 rows affected (overall time 26,076 msec; server time 6518 usec)
* 257: sql syntax error: line 5 col 9 (at pos 71) SQLSTATE: HY000
* 257: sql syntax error: incorrect syntax near "END": line 2 col 1 (at pos 32) SQLSTATE: HY000
'Hello'
"Hello"
1 row selected (overall time 4644 usec; server time 143 usec)

Select statement with array is throwing error

This statement is throwing error:
FOR _i2 IN 1 .. array_upper(p_extra_info, 1) LOOP
....
SELECT currval('ad_extra_info_id_seq') INTO _new_extra_info_ids[_i2];
....
END LOOP;
ERROR: syntax error at or near "["
LINE 179: ...rrval('ad_extra_info_id_seq') INTO _new_extra_info_ids[_i2];
^
********** Error **********
ERROR: syntax error at or near "["
SQL state: 42601
Character: 7907
Variable _new_extra_info_ids is declared like this: _new_extra_info_ids integer[];
Do you know what is wrong?
Use a direct assignment instead of a select:
FOR _i2 IN 1 .. array_upper(p_extra_info, 1) LOOP
....
_new_extra_info_ids[_i2] := currval('ad_extra_info_id_seq');
....
END LOOP;

SQL Error near the word 'go'

Why does SQL Server report that this statement isn't correct?
use DIGITECH
go
select *
from kunde as k
left join adresse as a on k.FK_AdID = a.AdID
where Name = 'Dirk'
go
SQL displays this error (in German):
Meldung 102, Ebene 15, Status 1, Zeile 14
Falsche Syntax in der Nähe von 'go'.
Meldung 102, Ebene 15, Status 1, Zeile 14
Falsche Syntax in der Nähe von 'go'.
Translated to english:
Msg 102 , Level 15 , State 1, Line 14
Incorrect syntax near 'go' .
Msg 102 , Level 15 , State 1, Line 14
Incorrect syntax near 'go' .
As other have pointed out, GO is the default batch delimiter for tools like Management Studio or sqlcmd. SQL Server does not understand GO, the tools use it to separate batches and send individual batches to SQL Server. You probably took an entire .sql file and executed in your app.
You can use a library like DbUtilSqlCmd which understands the sqlcmd delimiters (GO), and other sqlcmd specific syntax like :setvar, and execute your .sql file through it.
Can you specify the database in the query and avoid the go statements? For example:
select * from DIGITECH.dbo.kunde as k
left join DIGITECH.dbo.adresse as a
on k.FK_AdID = a.AdID
where Name = 'Dirk'

Xquery syntax error in SQL server 2012

I want to return the character 'o' in my sql database while working with xml data so I wrote the following query:
use master
select song_type.query ('table/[where o.name like % o %]')
from xmldata
but the program returned an error saying:
Msg 9341, Level 16, State 1, Line 2
XQuery [xmldata.song_type.query()]: Syntax error near '[', expected a step expression.
please how do I fix this.
Try this ...
select *
from xmldata where cast(convert(varchar(max),song_type) as xml).value("o.name[0]","varchar(500)") like '% o %'