appending string in existing string in sqlite3 manager fro firefox? - firefox

hello i have i want to do something like this.
i have 4 rows with unique id 1,2,3,4 all four rows contains some string like
option1,option2,option3,option4
now i want to add "a ) " to the option1, "b ) " to the option2 and so on so is there a way i can do this with a query.currently i am adding these to a lots of rows manually

It's not clear exactly by what logic you want to select the letter to prepend to field somestring, but if for example it's a "Caesar's cypher" (1 gives 'a', 2 gives 'b' etc) based on the id field, as your question suggests, then this should work:
UPDATE sometable
SET somestring = (
substr('abcdefghijklmnopqrstuvwxyz', id, 1) ||
' ) ' || somestring)
WHERE id <= 26;
...for no more than 26 rows of course, since beyond that the logic must change and obviously we can't guess just how you want to extend it (use id modulo 26 + 1, use more characters than just lowercase letters, or ...?) since you give no clue on why you want to do this.

Related

SPSS Syntax Concatenate Case Values From Single Column

I am trying to build a string of values to be inserted into an SQL IN list. For example -
SELECT * FROM TABLE WHERE field IN ('AAA', 'BBB', 'CCC', 'DDD')
The list that I want needs to be constructed from values within a single column of my dataset but I'm struggling to find a way to concatenate those values.
My first thought was to use CASESTOVARS to put each of the values into columns prior to concat. This is simple but the number of cases is variable.
Is there a way to concat all fields without specifying?
Or is there a better way to go about this?
Unfortunately Python is not an option for me in this instance.
A simple sample dataset would be -
CasestoConcat
AAA
BBB
CCC
DDD
You can use the lag function for this.
First creating a bit of sample data to demonstrate on:
data list free/grp (F1) txt (a5).
begin data
1 "aaa" 1 "bb" 1 "cccc" 2 "d" 2 "ee" 2 "fff" 2 "ggggg" 3 "hh" 3 "iii"
end data.
Now the following code makes sure that rows that belong together are consecutive. You can also sort by any other relevant variable to keep the combined text in a specific order.
sort cases by grp.
string merged (A1000).
compute merged=txt.
if $casenum>1 and grp=lag(grp) merged=concat(rtrim(merged), " ", rtrim(lag(merged))).
exe.
At this point if you want to just keep the line that has all the concatenated texts, you can use this:
add files /file=* /by grp /last=lst.
select if lst=1.
exe.

string.IndexOf exact match

I have the following:
string text = "Select [id] AS [FROMId] FROM [TASK] ORDER BY id"
and I want to use text.IndexOf("FROM") in order to find where the FROM starts.
I want to find the position of FROM and not the position of FROMId.
LastIndexOf or FirstIndexOf are not correct answers cause the text could be anything like
string text = #"Select [id] AS [FROMId],
newId as [newFROMId] FROM [TASK] ORDER BY [FROMId]"
I need the indexof to do exact matching.
Any ideas?
Since FROM is an SQL reserved word that will generally have spaces on either side, you could look for that then, since that will give you the address of the space before the F, add one to get the location of the F itself:
int index = text.IndexOf(" FROM ") + 1
This may not necessarily take care of all edge cases(a) but, to do that properly, you may have to implement an SQL parser to ensure you can correctly locate the real from keyword and distinguish it from other possibilities.
(a) Such as things like:
select [a]FROM[tble] ...
select 'got data from unit #' | unit from tbl ...
and so on.

grid filter in foxpro

I have a grid on a form that displays some columns from a dbf table and a textbox.
I want to search the value displayed in the textbox over all columns from a dbf table. Some fields are numeric and other are character
If I want to find a number, should search all record that contain that number in all columns, no matter the column type.
If I want to search a substring should give me all record that contain that substring.
SET FILTER TO ALLTRIM(ThisForm.Text1.Value) $Content or ALLTRIM(val(ThisForm.Text1.Value)) $registrationNumber or ALLTRIM(ThisForm.Text1.Value) $holderNo
Your approach with the "$" wildcard "contains" approach appears to be ok. However, your attempt via allt( val( )) would fail as you cant trim a numeric value, it would have to be pre-converted to a string.
Now, that said, you could shorten your query by just doing a $ against a concatenation of ALL columns something like (assuming your registration number is a numeric field)...
set filter to ALLTRIM(ThisForm.Text1.Value) ;
$ ( Content +"," +str(registrationNumber) +," + holderNo )
if you have dates or date/time fields you could do DTOC( dateField ) or TTOC( dateTimeField). So, by building a single string of all values, you dont have to explicitly repeat the OR condition repeatedly.
You could do something like:
select curGrid
scan
lcRow = transform(field1) + transform(field2) ... + transform(lastfield)
if lcSearchValue $ lcRow
DoWhatever()
endif
endscan
This leverages the fact that transform() will give a string representation of any data type.

I want fetch substring from in oracle table between last '/' and before '.' from last in images table

I want to fetch substring from string in column between last '/' and last '.' .
Here is sample date for IMAGE_PATH column name:
sph/images/30_Fairhall_Court.jpeg
sph/images/9_Pennethorne_House.jpeg
rbkc/images/TAVISTOCK_CRESCENT.jpeg
haringey/images/399932thumb.jpg
urbanchoice/images/18190862.jpg
wandle/images/f13c10d2-2692-457d-a208-8bb9e10b27dc.png
housingmoves/images/No14_Asterid Heights_DS37620.jpg
wandle/images/f13c10d2-2692-457d-a208-8bb9e10b27dc.png
So the required output is like
30_Fairhall_Court
9_Pennethorne_House
TAVISTOCK_CRESCENT
399932thumb
18190862
f13c10d2-2692-457d-a208-8bb9e10b27dc
No14_Asterid Heights_DS37620
f13c10d2-2692-457d-a208-8bb9e10b27dc
Please suggest how to fetch. I need to update another blank column in table with this value. The table has around 10 lacks records.
One of possible solutions is to use functions substr() and instr() with negative third parameter:
select image_path,
substr(image_path,
instr(image_path, '/', -1) + 1,
instr(image_path, '.', -1)-instr(image_path, '/', -1) - 1) img
from test
SQL Fiddle
Results:
IMAGE_PATH IMG
-------------------------------------------------------- -------------------------------------
sph/images/30_Fairhall_Court.jpeg 30_Fairhall_Court
sph/images/9_Pennethorne_House.jpeg 9_Pennethorne_House
rbkc/images/TAVISTOCK_CRESCENT.jpeg TAVISTOCK_CRESCENT
haringey/images/399932thumb.jpg 399932thumb
urbanchoice/images/18190862.jpg 18190862
wandle/images/f13c10d2-2692-457d-a208-8bb9e10b27dc.png f13c10d2-2692-457d-a208-8bb9e10b27dc
housingmoves/images/No14_Asterid Heights_DS37620.jpg No14_Asterid Heights_DS37620
wandle/ima.ges/f13c10d2-2692-457d-a208-8bb9e10b27dc.png f13c10d2-2692-457d-a208-8bb9e10b27dc
This regex works with the sample data you provided:
select regexp_substr(image_path
, '(/)([a-z0-9_ \-]+)(\.)([a-z]+)$'
, 1
, 1
, 'i'
, 2)
from t23
/
We have to include all the optional parameters after pattern so we can use the subexpr parameter to select just the filename element. Find out more.
As far as the updating goes, a million row table isn't that big. Given that you have to update all the rows there's not much you can do to tune it. Just issue the UPDATE statement and let it rip.
"its not working"
Hmmm, here's a SQL Fiddle which proves it does work. You've probably introduced a typo.
"The regexp looks unnecessary complex. Why not simply"
Perhaps it is too complicated. However your simplified version doesn't produce the correct result if there's more than one dot in the IMAGE_PATH. If that's never going to happen then your solution works just fine.

convert word to ascii and return to word adding some value

I am working on PL/SQL . The oracle password by developer is set such way
=> input word => converted to ascii => added 2 to each letter => converted back to word
ex: input password is "admin".
admin is splitted into characters/letters (a, d, m, i, n)
converted to ascii and added 2 and again converted to word
a=97 97+2 = 99 = c
d=100 100+2=102 = f
m=109 109+2=111 = o
i=105 105+2=107 = k
n=110 110+2=112 = p
what i did is
$pass=str_split('admin');
foreach($pass as $password){
$new_password[]=chr(ord($password)+2);
}
$final= $new_password[0].$new_password[1].$new_password[2].$new_password[3].$new_password[4]; //the values 0-4 is set manually
echo $final;
result: cfokp
But i could not get proper ans to run the result string on command and match the oracle password with the retrieved one.
Another way in SQL is to split the characters, add 2 to the ascii value, and aggregate the string.
Of course, it won't be faster than the TRANSLATE approach. But, for a single or small set of values it shouldn't matter much.
For example,
SQL> WITH data AS
2 (SELECT 'admin' str FROM dual
3 )
4 SELECT str, LISTAGG(CHR(ASCII(REGEXP_SUBSTR(str, '\w', 1, LEVEL)) + 2), '') WITHIN GROUP(
5 ORDER BY LEVEL) str_new
6 FROM data
7 CONNECT BY LEVEL <= LENGTH(str)
8 /
STR STR_NEW
------ -------
admin cfokp
SQL>
The above SQL does following important tasks:
Split the string into characters using REGEXP_SUBSTR and ROW GENERATOR technique
Add value 2 to the ascii value of each character.
Convert back the modified ascii into characters.
Aggregate the string using LISTAGG
This is probably easier to do with translate:
select translate('admin',
'abcdefghijklmnopqrstuvwxyz',
'cdefghijklmnopqrstuvwxyzab'
)
from dual;
I'm not sure what you want to do with "y" and "z". This maps them back to "a" and "b". You can extend this to upper case letters and other characters if you need.

Resources