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 5 years ago.
Improve this question
I have a hashed string using SHA1. I would like to convert this string a password like string, meaning about 8 chars with upper, lower characters, and special chars.
You could use base-85 to encode the last 8 bytes of the hash to 10 ASCII characters.
You should be aware that if the character sequence that was originally hashed is predictable (for example, it's a word or phrase, or a commonly used password), it will be very easy to guess from the 10-character string. Even if the original string is randomly generated, finding another string that produces the same truncated hash is relatively easy.
In other words, this technique must not be used for anything that requires security.
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.
Improve this question
I am a self-learner and beginner learning SQL. I need to ensure the dataset is consistent. The statement used below:
SELECT
DISTINCT drive_wheels
FROM
cars.car_info
To check if this is the case, use a LENGTH query statement.
SELECT
DISTINCT drive_wheels
LENGTH(drive_wheels) AS string_length
FROM
cars.car_info;
**the LENGTH statement doesn't make sense to me
I'm assuming you are using MySQL or a MySQL-compatible database engine. In other database engines the implementation of the LENGTH could be different.
LENGTH is an SQL function that returns the number of bytes in a string.
In your SQL query, it returns the length of the content of the drive_wheels field as a string measured in bytes. If your field contains a numeric value then it's not the correct function to use - you can simply return the field as is.
Ref: https://www.mysqltutorial.org/mysql-string-length/
Note: number of bytes in a string and number of characters in a string can be different when for example UTF-8 encoding is used and the string contains characters outside of the normal Latin characters. Those characters might require 2, 3 or 4 bytes to represent.
The length function returns the number of characters in a string, so in layman's terms, how many letters are in the word.
Examples
Length('hello') = 5
Length('foo') = 3
Length('goodbye') = 7
Not sure what is in the drive wheels column though
The string LENGTH functions returns the length of the string in bytes. DISTINCT drive_wheels LENGTH(drive_wheels) AS string_length FROM cars.car_info The above query will return the length of drive_wheels from the car_info table.
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.
Improve this question
I had this question, in one assignment, and the answer is false. Can someone explain cuz I saw couple questions here trying to do this
In most SQL databases, this is not strictly possible. However, there are a few exceptions. In SQLite, any type of data can be stored in any column. However, SQLite columns support the concept of "affinity." There are 5 affinity types, including TEXT, NUMERIC, INTEGER, REAL, and BLOB. Inserting numeric data into a column with a TEXT affinity will result in that data first being converted to text.
On other databases, such as MySQL, columns do have rigid types, but there are flexibilities in other ways. For example, MySQL supports implicit casting such that the following comparison against a numeric column col is allowed and possible:
WHERE col > '123'
In this case, MySQL will implicitly convert the string literal 123 to an integer before doing the comparison.
A column value is an atomic value.
A single atomic value has exactly one data type: the declared for the column that contains the value.
So the answer is: no, a column in a relational database (that honors the SQL standard) can not have multiple data types.
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
In SQL Server I am using the concat function to join two columns. One column is numeric. Because of that after concat, the output shows that number in scientific notation. Is there any way to avoid that scientific notation?
I tried
concat (convert (numbercolumn as varachar), text_column)
but I get an error
concat is not a recognized built in function name
First, you don't need to explicitly convert, so:
concat(numbercolumn, textcolumn)
If this still converts to exponential, then convert to a decimal first. I'm not sure what you want things to look like but something like:
concat(convert(decimal(38, 10), numbercolumn), textcolumn)
You can also use format() or str() to convert the value to a string.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
assuming you data or application doesn't have to match an exact length, why would someone opt to use char (or nchar) over varchar (or nvarchar)?
CHAR(100) always stores 100 bytes (or Characters depending on your RDBMS). VARCHAR(100) will store up to 100 bytes plus the necessary number of bytes to store the length of the string.
For instance, if I store "Foo" in Char(100) it will take up 100 bytes in my field. If I store "Foo" in VARCHAR(100) it will take up 5 bytes. 3 bytes for each character, and 2 bytes for the length of "3".
If you data is variable in length, then use VARCHAR() to save space, if it is always the same length use CHAR() to save space (because you don't have to write the length with the characters).
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I'm trying to write a query to print the letter when i give number as input
1-a
2-b
3-c
4-d
5-f
and so on
using either SQL or PL/SQL query.
one way of doing it is:
begin
case when 1 then 'a'
when 2 then 'b'
when 3 then 'c'
.
.
.
when 26 then 'z'
.
.
end;
But is there any other way of writing it instead of such a long query.
Assuming this is Oracle (as per the plsql tag and the mention of the DECODE construct), you're looking for the TRANSLATE function.
It accepts a string to translate a pair of from and to strings, and then replaces every character from the string to translate that appears in the from with the corresponding character in the to string:
SELECT TRANSLATE (<your input here>, '1234', 'abcd') FROM dual;
tricky to see what you mean as you have not included any SQL or specified which flavour of database you are using.
also, what about the higher numbers. for example if Z is 26, then how do you tell if its B+F or Z.
assuming you are limiting from a to I or are going to comma delimit the numbers, then you could use a replace function along
the lines of REPLACE(str,num,CHR(64+num))
in this example assuming the str is "1"
then it would be replaced with the character with the ascii code 64+1=65 which is a
note that syntax, functions vary between databases, but most have a string replace and ascii code to char function. you might also
need to cast the value to a number on some db's