Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
62 views
in Technique[技术] by (71.8m points)

Adding a dot in a string in sql

I need to add a dot in two strings of numbers. (example "88188741478"). I need to add it 8 characters before the end. The result should look like this "881.88741478". I need several columns to be returned but need to add the dot only in 2 of them.

Final output is should be something like this:

380600001036641|8.84243987|44.41515810|0

I am using sqlplus in a .bat file to run a .sql file.

My code is:

whenever sqlerror exit 90
set echo on
set verify off
set feedback off
set heading off
set linesize 257
set termout off
set pages 0
set pagesize 0
set space 0
spool Cfile.txt
Select
First
||'|'|| Second
||'|'|| Third
||'|'|| STUFF(Fourth, length(Fourth)-8, 0, '.') as "FOURTH"
||'|'|| STUFF(Fifth, length(Fifth)-8, 0, '.') as "FIFTH"
||'|'|| Sixth
FROM table
WHERE Sixth='0'
AND NotSelectedParameter IN ('001', '003');

I keep getting this error:

#ORA-00923: FROM keyword not found where expected

I tried changing aliases, checking for reserved words, using substring, substr, left + right instead of stuff but i keep getting different errors. In the times I don't get an error, the programs get blocked printing the line's number of last command (if "AND NotSelectedParameter IN ('001', '003');" is at line 12 it prints 12 and it blocks itself until i ctrl z in the cmd).

What can I do?

Edit: the unclosed identifier was a formatting error in this question. The identifier was closed in the original code.

question from:https://stackoverflow.com/questions/65898924/adding-a-dot-in-a-string-in-sql

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can't have (unterminated) aliases in the middle of a function.

Remove both "AS ..." .

A function that does exist is regexp_replace.

regexp_replace('88188741478','(.*)([[:digit:]]{8})$','1.2') 

gives

881.88741478

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...