how to put quote around a sentence - oracle

I have a column in my table called Additional_comments. This column is a free text field where people pretty much write sentences, so it looks like this:
Additional_comments
The client is in need of basic services, housing, and employment help; client is in need of financial help. Client is in the senior age-group.
I want the sentence to appear like this - "The client is in need of basic services, housing, and employment help; client is in need of financial help. Client is in the senior age-group."
This is what I have tried before:
Select '"'+additional_comments+'"' from table;
I would appreciate if anyone can help me with this query to figure out how I can add double quotes around the sentence. Thank you

Just concatenate the quotes to your column
select '"' || additional_comments || '"' from your_table;

Related

Dynamic Custom filtered tables for a Schedule

I have several questions about sorting and organizing a schedule in google sheets.
I have found some work arounds to get most of what I want done but was hoping to get some input and maybe some ideas on ways to make it work better.
Problem - I have a CSV file I can generate for the work schedule of all the employees. It is not very coinvent to work with and look at. I am trying to take the data from the spreadsheet and sort it by day, department and Name.
Some of the people have split shifts which causes a second row with a blank cell where the name should be. (work around create another list that if the cell is blank it duplicate the data from the one above.)
Time and department for the shift are in the same cell and need to be separated (work around search every cell for all departments and display the name that matches and for the time take all the text left of the 12th character)
Lastly it would be nice to reverse the name so it is First then Last not "Last, First". As well as being able to have custom/nick names for example instead of Nunez, Elizabeth It would display Eli Nunez. This goes for the department was well. (Work around is similar to the department and just searching for every name and displaying the match with "=IF(ISNUMBER(SEARCH..." )
Ideally this would be done with a dynamic filter/pivot table/dynamic array that way there's not a lot of code in each cell and would automatically fill and sort.
I can also provide all my work around code if needed.
Sheet Example
"Full Week" sheet is what I am starting with and "Sorted by Day" sheet is the output/end goal I am looking for.
Hopefully this is enough information and sorry if this is the wrong place to ask/ post this.
Thank you
- Alan
Thank you for the help. I am still having a bit of trouble implementing it into my final schedule sheet.
Here is the my final sheet with all of my workaround code.
try:
=INDEX(IFERROR(REGEXREPLACE(TRANSPOSE(SPLIT(TRIM(FLATTEN(QUERY(QUERY(SUBSTITUTE(
TRIM(SPLIT(FLATTEN(QUERY(TRANSPOSE(REGEXREPLACE(REGEXREPLACE(TRIM(QUERY(SPLIT(FLATTEN(
QUERY(TRANSPOSE(QUERY(SPLIT(FLATTEN(IF('Full Week'!B2:20="",,'Full Week'!B1:1&"♣"&
TEXT('Full Week'!B1:1, "emmdd\♠ddd\♦")&"♣"&REGEXREPLACE(VLOOKUP(ROW('Full Week'!A2:A20),
IF('Full Week'!A2:A20<>"", {ROW('Full Week'!A2:A20), 'Full Week'!A2:A20}), 2, 1),
"(.*),(.*)", "♥$2 $1")&"♣♥"&SUBSTITUTE('Full Week'!B2:20, CHAR(10), "♣"))), "♣"),
"select Col2,Col5,Col3,Col4
where not Col4 matches '^♥ $'
and Col1 >= date '"&TEXT(TODAY()+1, "e-m-d")&"'
and Col1 <= date '"&TEXT(TODAY()+4, "e-m-d")&"'")),,9^9)), "♦"),
"select max(Col2)
group by Col2
pivot Col1")), "^♥", "♂ ♥"), "^$", " ♥ ♥ ♥")&" ♥"),,9^9)), "♥")), " ", "♀"),
"offset 1", 0),,9^9))), " ")), "♀|♂", " ")))
domo sheet

Need help translating returned data in Oracle query

Please keep in mind I am building a query in two phases here. The first phase is to get this to work with the existing query which is inefficient.
I am not good with PL/SQL at all, but I am learning slowly here.
I have this as a query:
SELECT LOGONID,FIRSTNAME,LASTNAME,ORGNAME
FROM WCSADMIN.USERREG UR,WCSADMIN.ADDRESS A
WHERE UR.USERS_ID = A.MEMBER_ID
AND A.ADDRESSTYPE IN('S','SB')
AND A.STATUS='P'
AND UR.STATUS='1'
AND (UPPER(LOGONID) LIKE UPPER('%cn=users%')
OR UPPER(LOGONID) LIKE UPPER('%o=Buyer A Organization%'))
AND UPPER(LOGONID) LIKE UPPER('uid=resourcereaper%')
AND rownum < 10; -- limits the rows back
Essentially the LOGONID field holds the LDAP string for logging on. The first characters in the field is uid=username,ou=......
I need to be able to carve that field down to just be "username". I think you can use the translate command, but I am unsure about how to trim off the uid= and everything (including) the first ",". Any insight would be greatly appreciated.
Josh
The translate command isn't the one you want - that does a character-for-character substitution.
You can use a combination of SUBSTR and INSTR to get the username, but the REGEXP_REPLACE is a little cleaner (my opinion of course). This will give you the uid value:
REGEXP_REPLACE(LogonID, '^uid=(.*?),.*$', '\1')
I'd explain the regular expression (and the \1) more, but I think the Oracle docs already do a much better job than I can.
Also, beware of the WHERE ROWNUM < 10. It's sometimes quirky (or at least appears so), and it won't work at all if you ORDER BY in your query. There's more info and a great explanation here. If you run into to trouble with ROWNUM you can fix it by putting ROWNUM into an outer query:
SELECT * FROM (
SELECT <your query>
) WHERE ROWNUM < 10
Something like this:
substr(LOGONID,
instr(LOGONID,'uid=')+4,
instr(LOGONID,',')-instr(LOGONID,'uid=')-4
)
This relies on the fact that there's always 'uid=' and a comma somewhere after it. If it's not the case, you'll need to handle exceptional cases as well. You could also use REGEXP_SUBSTR() if you want to be fancy.

Search for similar words using an index

I need to search over a DB table using some kind of fuzzy search like the one from oracle and using indexes since I do not want a table scan(there is a lot of data).
I want to ignore case, language special stuff(ñ, ß, ...) and special characters like _, (), -, etc...
Search for "maria (cool)" should get "maria- COOL" and "María_Cool" as matches.
Is that possible in Oracle in some way?
About the case, I think it can be solved created the index directly in lower case and searching always lower-cased. But I do not know how to solve the special chars stuff.
I thought about storing the data without special chars in a separated column and searching on that returning the real one, but I am not 100% sure where that is the perfect solution.
Any ideas?
Maybe UTL_MATCH can help.
But you can also create a function based index on, lets say, something like this:
regexp_replace(your_column, '[^0-9a-zA-Z]+', ' ')
And try to match like this:
...
WHERE regexp_replace(your_column, '[^0-9a-zA-Z]+', ' ') =
regexp_replace('maria (cool)' , '[^0-9a-zA-Z]+', ' ')
Here is a sqlfiddle demo It's not complete, but can be a start

How to use LIKE statement in sql plus with multiple wild carded values?

my question is that currently if i want to query for multiple wildcarded values. I need to do something like this.
select customername from customers where customername like '%smith' or customername like '%potter' or customer name like '%harris' or customername like '%williams';
So I wanna ask from the experts, is there any easier way to do this?
Regards,
Sanjan
Create a table of your 100 names
select customername from customers c inner join customersames cn on(c.customernamename like '%'+cn.searchForname)
Can be a table variable if that helps.
you can use regular expressions
EDIT: You can find plenty of resources online. take http://66.221.222.85/reference/regexp.html for example.
Regular expressions are really powerful but can be very SLOW if applied carelessly. For your case they may not squeeze your syntax much because you need to type those names anyway and that's the bulky part.

UTF-8 coding question (what is the last unicode character)

we are opening up our application to allow support for multiple languages. one of the problems we have encountered along the way is a feature we provide our customers. Imagine for a moment the user is presented with 3 fields.
All customers is a toggle
From Customer Name is a field they can type in
To Customer Name is a field they can type in.
what happens from the user experience standpoint is if you select all customers "from" and "to" are disabled
what happens in the code is if the customer selects "all customers" we look for all customer records that have customer names greater than or equal to "" (blank) and less than or equal to "}}}}}}}}}}}}" (which works fine in ANSI).
when we put a chinese character in the first letter of the name this does not work since the code for the Chinese glyph is greater than "}". Is there a character in UTF-8 that is "the last character" so I could replace it?
We are intending on supporting multiple languages so if the solution only works for Chinese it won't help us.
Thanks
Kevin
When "all customers" is selected run a query without any conditions on customer name.
Yes, this means a new, alternate path of execution. Yes, it's not "smart".
At the same time it will be a lot more readable and easier to troubleshoot later. KISS
Wouldn't it be simpler to create a base select statement with all other conditions and then add the from/to conditions based on whether the from/to fields were filled in or not? Something like this:
sql = "select a,b,c from users where c = 123";
if(!from.empty())
sql += " and name >= '" + from + "'";
if(!to.empty())
sql += " and name < '" + to + "'";
Why not use CUSTOMERNAME IS NOT NULL instead? That would allow any range of characters without worrying about what's the first and last character in any particular text encoding.
I would rework the logic of the application so that you don't have to search for the names of the customers in order to get references to them.
Simply add all customers to the list of customers if the "all customers" switch is toggled on.

Resources