Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I need to complete cards numbers in sql. I have the prefix =11111 and the number of the card which is variable, therefore it could be '25' or '2130' but at the end I must have 14 numbers. So I need to fill spaces with zeros.
I've read about 'LPAD' but I don't understand very well this method.
You could use lpad, but if you're starting with a number you could use a 9-digit format model instead, and concatenate that onto your prefix:
select '11111' || to_char(25, 'FM000000000') from dual;
11111000000025
The FM format modifier stops Oracle adding a space for a potential +/- sign indicator.
SQL Fiddle demo
Use the ZEROFILL attribute.
But your database should only be responsible for saving data and not changing it before saving.
The best way would be to send the zerofilled data to the database server.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
This post was edited and submitted for review 1 year ago and failed to reopen the post:
Original close reason(s) were not resolved
Improve this question
It's a SQL instance and the examples are as follows:
Table values to transform:
String is Donald.Duck and the desired result is DDuck
String is Mickey.Mouse and the desired result is MMouse
you can use a regular expression in sql. it runs slower but it will use the dot.net framework
The regular expression is simple. Look forward and find a period then capture all non space characters proceeding the period.
how to call a regular expression in tsql
https://www.sqlshack.com/t-sql-regex-commands-in-sql-server/
#extract the data to a csv then process it and update back into the database
txt="Donald.Duck and the desired result is DDuck String other strings are Mickey.Mouse and Daffy.Duck"
pattern = re.compile(r'([a-zA-Z]+\.[a-zA-Z]+)')
result=re.findall(pattern,txt)
for item in result:
front,back=item.split('.')
txt=re.sub(item, front[0]+'.'+back,txt)
print(txt)
output
Donald.Duck and the desired result is DDuck String other strings are Mickey.Mouse and Daffy.Duck
Sql steps:
split the words into a table of words by space
fetch each word and do an instr to check for a period
split the front and back word by period
keep the first character of the front word and reassemble and replace the phrase
join the words into a sentence and update the database with the new sentence.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I Have below query:
where POSTDATE between to_date('&START_DATE','DD-MM-YYYY') and to_date('&END_DATE','DD-MM-YYYY')
and username='&username'
But my requirements are:
I need all usernames between Start date & End date(3rd Input is
blank) AND / OR
specified usernames(in 3rd Input) between provided
start date and End date in query
You want the date range check anyway, then you either want all users or a specified user; so you can check if you were given a username:
where POSTDATE between to_date('&START_DATE','DD-MM-YYYY') and to_date('&END_DATE','DD-MM-YYYY')
and ('&&username' is null or username='&&username')
If no user name is given then the second line evaluates to:
and ('' is null or username='')
In Oracle '' is equivalent to null (though they have always warned that could change one day...) so the first clause is true.
You haven't said if you're explicitly prompting for the inputs (with accept); if you are then you could use single & or double &&, but if not using double && will prevent you being asked twice.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
You can I display special Unicode characters in my result set on my SQL Server?
e.g. How can i display those characters ☺♦♦?
Well due to the fact that your question is very unspecific here are some solutions.
You need to specify a string as unicode string. This can be achieved by adding an N in front of the string. See example:
SELECT N'☺♦♦' as a, '☺♦♦' as b
Result:
a b
---- ----
☺♦♦ ???
If you want to store those symbols, you need a type as nvarchar or nchar.
Hopefully this helps you.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I have a database table that contains a column for pricing.
Its very old, so it was written before i understood datatypes. so we are using varchar for a money value.
Ive noticed some columns have $ in them, so what I'm wondering is... is there a way with SQL Server to perform an update of the table and remove any instances of non numeric characters or at the very least remove the $ from the string in the columns in one go ?
I hope this is possible.
Update tbl
SET price = replace(price, '$', '')
Here is the replace definition
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
Working on 10g.
I am writing a query to sort a list, and sorting is an important aspect of the list.
I have already isolated the fraction from the mixed number.
I have data that come in fraction form. (3/4, 5/8, 1/2)
I need to convert them to decimal to be able to 'order by' with them.
Any help would be appreciated.
This will blow up badly if the input is not a fraction such as 3/4, 5/8, etc., but here goes:
CAST(SUBSTR(theFraction, 1, INSTR(theFraction, '/')-1) AS NUMBER) /
CAST(SUBSTR(theFraction, INSTR(theFraction, '/')+1) AS NUMBER)
The logic is basically "get everything before the '/' and convert it to a number, then divide it by everything after the '/' converted as a number".