Looking for some help here if anyone can offer some. I am working with an oracle database and I would like to trim a string up until a certain character '/'. These fields are paths of a URL and they are all different sizes so I need to make sure it's getting to the very last '/' in the URL and removing everything up until that point. Additionally, there is a session ID that is associated with some of these URLs that is located at the end of the string and has a semi-colon before it starts, so I would want to remove everything that contains a semi-colon up to the semi_colon and on. So essentially I want to remove content from the beginning of the URL and from the end of the URL if applicable. Examples of these URL's (string) are as follows:
Current URLS
/ingaccess/jsp/mslogon.jsp
/ingaccess/help/helpie_term_cash_surrender_value.html
/eportal/logout.do;jsessionid=xr8co1kyebrve47xsjwmzw--.p704
/eportal/logout.do;jsessionid=gdh_e_e1m1hna0z9ednklg--.p705
/ingaccess/help/helpie_term_northern_unit_value.html
/ingaccess/help/helpie_scheduled_rebalance.html
/eportal/home.action;jsessionid=9vhfbkhunkvtcm5g1dtgsa--.p704
/ingaccess/help/helpie_catch_up_50.html
/ingaccess/piechartmaker
/ingaccess/help/helpie_term_fund_balance.html
Desired URLS
mslogon.jsp
helpie_term_cash_surrender_value.html
logout.do
logout.do
helpie_term_northern_unit_value.html
helpie_scheduled_rebalance.html
home.action
helpie_catch_up_50.html
piechartmaker
helpie_term_fund_balance.html
Anyone know of an easy fix here? I've tried working with SUBSTR and REPLACE a bit but can't seem to get them to work.
Thanks a bunch in advance,
Ryan
Try this
SELECT CASE WHEN INSTR (surname,';')>0 THEN SUBSTR(surname,1
,INSTR(surname,';',1,1)-1) ELSE surname END FROM
(SELECT SUBSTR(column,INSTR(column,'/',-1)+1) AS surname
FROM tableName)
Tested on Apex
Related
I'm practicing exercises with SQL and I've got a problem I couldn't resolve yet.
I have a table with a column named: **'email' ** and I want to extract just the Domain of each mail. Then I was thinking to extract since '#' to get that information.
But idk how to do it, was trying with SUBSTRING, but that didn't work because that's about position, and each mail has different size.
I attach a screenshot about the table's composition (does not contain real information). Thank u so much :)
I tried with SUBSTRING method but that didn't work
Example email: example_email#outlook.com
Output expected: #outlook.com
We can use SPLIT_PART to fetch everything after the # and then append the #:
SELECT CONCAT('#',SPLIT_PART(email, '#', 2)) AS mailDomain
FROM people_practice;
Here the documentation about this and other useful string functions.
so This is a sample of my DB Values
UPDATE page p SET p.content = REPLACE(p.content, SUBSTRING(p.content, CHARINDEX('php?id=', p.content) +1), CONCAT('php?id=',p.course)) WHERE p.content LIKE '%php?id=%' AND p.content NOT LIKE CONCAT('%','php?id=',p.course,'%');
I'm Trying to only get the text after php?id= which is a number and change it to the correct number which is the course column
so for example the first value should be changed to
4|Enjoy your training!<a href="*/view.php?id=4">
Unfortunately charindex keeps giving me an Error
Any Help on how to Make this thing work without charindex as i Believe our server does not support this function
UPDATE: Charindex didnt exist in mysql so i had to use LOCATE fuction instead. Also i wasnt using the root password for the whole server, just the root password for the db
Thanks for the heads up!
Now just need the query to correctly update... as it removes just everything after <a href etc etc and doesnt replace
It is possible to write a .htaccess rule to ignore part of the query string but still keep it in the url (without redirection)?
i need a way to ignore query string(s) starts with the utm_ like they are absent (invisible to the backend scripts) but still present in the browser URL because the query string will be captured by the JavaScript analytics scripts (thats why solutions with the redirection unacceptable).
lets say i have an url without query string: https://example.com/bla/hello
or with query string: https://example.com/anything?hello=world
then i need to add a query string part utm_source=123 which could be positioned anywhere among the other query string elements
some pages of the site stops working or starts behaving different when im adding a query string to the url for example https://example.com/?utm_source=123 throws 404
if it is possible, could you help me with the rules ?
I have a table that has a bunch of url's within a certain column. We no longer want a certain url within the table and instead of manually updating each data record I was curious if there is a way to remove just a certain type of url through an update query?
For instance, a data record with the following url's exists:
Presentation (PowerPoint File)<br> Presentation (Webcast)
and I want to remove the smil url so the data only shows:
Presentation (PowerPoint File)<br>
I want to remove the entire "smil" url from this string (from ), and every other smil url from the other records (the other records are similar with a different smil file name). Some of the records could have more than two urls, BUT the "smil" url is always the last one.
Preserving some of the comment history so future readers understand the decision points before implementing the solution
Does it always follow the pattern of text<br>text
there are a few times where there are two urls and they exclude the <br> and then there are a few times where it is just the smil url within the data.
You haven't clearly define what a "smil" url is. Is it one with smil in it anywhere? With the file suffix being .smil? With /smil/ in the path? some combination of these?
The problem you're going to have is that to properly solve this, you'll need to be able to have some insight into the html fragments. That's usually a .NET thing, the string matching in TSQL is likely to be insufficient for your needs. You could try taking multiple passes as it. If it follows the text<br>text pattern, you could left(myCol, charindex(mycol, '<br>')) where Mycol like '%smil%' and keep taking passes at it until you've found all the patterns.
#billinkc: I see where you are going, I was thinking if it would be possible to remove everything from the start of <a href="xxx since those "smil" links all start with that character string.
And there'd never be the case of streaming<br>foo? If so, then yeah, search for the <a href="http: using charindex/patindex (can never remember which) and then slice it out with left/substring.
#billinkc: yup that will always be the case. the "streaming" url is ALWAYS last. Ok this was easier than I thought, just needed some outside eyes. Thank you.
Given that we know we don't have to worry about anything useful existing after the smil url and that the url will always be an external, we can safely use a left/substring approach like
DECLARE #Source table
(
SourceUrl varchar(200)
)
INSERT INTO #Source
(SourceUrl)
VALUES
('Presentation (PowerPoint File)<br> Presentation (Webcast)');
-- INSPECT THIS, IF APPROPRIATE THEN
SELECT
S.SourceUrl AS Before
, CHARINDEX('<a href="http://', S.SourceUrl) AS WhereFound
, LEFT(S.SourceUrl, CHARINDEX('<a href="http://', S.SourceUrl) -1) AS After
FROM
#Source AS S
WHERE
S.SourceUrl LIKE '%smil%';
-- Only run this if you like the results of the above
UPDATE
S
SET
SourceUrl = LEFT(S.SourceUrl, CHARINDEX('<a href="http://', S.SourceUrl) -1)
FROM
#Source AS S
WHERE
S.SourceUrl LIKE '%smil%';
What am I doing wrong with my full text search? If this code
Select UserID, UserName
From Users
Where Contains([UserName], '%Jack%')
I get the user jack back, but if I do this
Select UserID, UserName
From Users
Where Contains([UserName], '%Ja%')
I get nothing what am I doing wrong?
You're mixing LIKE syntax with CONTAINS. Keep in mind that full text searching is word based, while like searches for a character pattern within a string.
Try:
Select UserID, UserName
From Users
Where Contains([UserName], '"Ja*"')
Contains([UserName], '"Ja*"') - Syntax for PREFIX search. Would match "Jack" but NOT "Ajax"
You cannot do any POSTFIX search with full text search. If you were to try:
Contains([UserName], '"*Ja*"') -- wrapped in *
This would actually still do a PREFIX ONLY search, it will strip out all special characters that are not proper syntax, meaning the first * would be stripped then ran. If you need open ended search you need to use %% still to find inner parts or words.