I'm trying to make a replace with an sql request, but I also need to use a matching pattern in the replace request.
Let's suppose I have a database with one column movie and three fields : 'Batman Begins', 'The dark knight', 'the dark knight rises'.
And my request would look something like that :
SELECT replace(movie, 'kn%t','') as movie FROM db_movie;
or something like that :
SELECT replace(movie, movie like ('kn%t'),'') as movie FROM db_movie;
And I should get the following output :
('Batman Begins', 'the dark','the dark rises')
But I doesn't work, so do you have an idea how I could do that ?
And I need for my true request to use the '%' matching pattern, not just directly write the word "knight" that could be enough for that example.
Thank you very much for your answers :)
In SQL SERVER, there's a function CHARINDEX() that will help you.
Select movie from db_Movie where CHARINDEX('dark',movie) <> 0
Try the following query-:
select case when movie like '%knight%' then
replace(movie,'knight','') else movie end as movie
FROM db_movie
SQL Server
Try the following query-:
SELECT CASE WHEN MOVIE LIKE '%KNIGHT%' THEN
REPLACE(MOVIE,'KNIGHT','') ELSE MOVIE END AS MOVIE
FROM DB_MOVIE
SQL SERVER
I encounter some problems that i don't understand with APEX.... Well, let's be specific.
I ve got a select element retrieving a top 50 of most liked url (P11_URL). This is populate by a table view, TOp_Domains.
I create an element called "Context" that have to print all text containing the URL selected by the user from the element select. Those Texts come from another table, let's say "twitter_post".
I create a dynamic action (show only) with this sql/statement:
Select TXT, NB_RT, RANK
from myschema.twitter_post
where TXT like '%:P11_URL%'
group by TXT, NB_RT, RANK
.... and it doesn't work... I think APEX don't like like clause... But i don't know how to do. Let's keep in min an url could have been shared by multiple Tweets, that's why this element "context" is important for me.
I tried to bypass the problem by building a State (in french Statique) and a dynamic action that will refresh the state but it doesn't work neither... bouhououououou
TriX
Right click on the 'P11_URL' and create DA. Event :change, Item:P11_URL. As the true action of the DA, select 'Set Value'. Write your query in the sql stmt area. In the page items to submit, select 'P11_URL' . In the 'Affected Items': select 'Context'.
Query should be :
Select TXT, NB_RT, RANK
from myschema.twitter_post
where TXT like '%' || :P11_URL || '%'
group by TXT, NB_RT, RANK
So
Thanks to #Madona... Their example made me realised my mistake. I wrote the answer here for futher help if somebody encouter the same porblem.
A list select element get as arguments a display value (the one you want to be shown in your screen.... if you want so....^^ ) and a return value (in order, I think to linked dynamic actions). So to solved my problem i had to shape my sql statement as:
select hashtags d, hastags r
from my table
order by 1
[let s say that now in Apex it s an object called P1_HASHTAGS]
First step problem solving.
In fact, the ranking as second value, as i put into my sql statement was making some mitsakens into my 'Where like' clause search... well... Newbie am i!
Second step was to correctly formate the sql statement receiving the datas from my select lov (P1_HASHTAGS) into my interactive report. As shown here:
Select Id, hashtags
from my table
where txt like '%'||:P1_HASHTAGS||'%'
And it works!
Thank you Madona your example helped me figure my mistakes!
I have a query which is expert mode query. Also I have viewCriteria and whereClause.
When I use whereClause like under and execute; viewObject can't take any row from database. But when I put the same query in toad, i can see the result. Can you help me...
viewObject getQuery result
SELECT *
FROM (SELECT CO.CUST_ORD_ID,
PA.ACTORID_ AS WRK_GRP_ID,
CO.CUST_ID,
cam_pkg.getCustomerFullName (CO.CUST_ID) AS CUST_NAME,
WG.NAME AS WRK_GRP_NAME,
TI.CREATE_ AS ACTOIN_DATE,
WT.WFLW_TASK_ID,
WT.NAME AS WFLW_TASK_NAME,
TI.NAME_ AS TASK_SHRT_CODE,
CO.ORD_ST_ID,
ORS.NAME AS ORD_ST_NAME,
TI.PROCINST_ AS PROC_INSC_ID,
TI.ID_ AS TASK_ID
FROM cust_ord co,
JBPM_TASKINSTANCE TI,
jbpm_pooledactor PA,
jbpm_taskactorpool TAP,
wrk_grp WG,
ord_st ORS,
WFLW_TASK wt
WHERE CO.CUST_ORD_ID =
jbpm_pkg.get_subLong_jbpm_var_insc (TI.PROCINST_,
'CustOrderId')
AND TI.ISOPEN_ = 1
AND TI.END_ IS NULL) QRSLT
WHERE (TASK_ID IN
(1128732,
1129513))
which version of jdeveloper? and how exactly are you applying the view criteria? Are you sure you query is getting formed as you are expecting? Try to enable logging by putting
-Djbo.debugoutput=console in the run/debug properties of your view control project (make sure to bounce the server)
I'm a novice in mySql.
I'm trying to replace a value in the xml column of my table.
my select method works.
SELECT * FROM `comics` WHERE ExtractValue(xml,'comic/pageNumber') = 6
my replace method doesn't. I've been searching for the correct syntax for a bit now...
SET xml.modify(
replace value of ('comic/pageNumber') with 5
)
some background:
this situation comes up when i delete a comic page.
it leaves a gap in the page numbers, after which i would either:
iterate through all the comics and remove any gaps in the page numbers.
or
iterate through all comics with pageNumber larger than the deleted page, and reduce their pageNumber by 1.
How about
UPDATE comics
SET xml = UpdateXML(xml,'comic/pageNumber', '<pageNumber>5</pageNumber>')
WHERE ExtractValue(xml,'comic/pageNumber') = 6
Tested on MySQL version 5.1
UPDATE `comics`
SET xml = UpdateXML(xml,
'comic/pageNumber',
concat('<pageNumber>',(ExtractValue(xml,'comic/pageNumber')+1),'</pageNumber>'))
WHERE ExtractValue(xml,'comic/pageNumber') >= 1
You'd be better off actually storing the fields in the table, rather than a single field with xml in it. Then the following would work. Otherwise there's not much point using a relational database at all.
BEGIN;
DELETE FROM `comics`
WHERE `comicID` = :id AND `pageNumber` = :page;
UPDATE `comics` SET `pageNumber` = `pageNumber` - 1
WHERE `comicID` = :id AND `pageNumber` > :page;
COMMIT;
As most of you would know, when you save a view in MYSQL and then retrieve it later, it's all in native MYSQL, looks terrible - no line spaces, indents, plenty of UTF encoding tags littered around the place making your code look like sql soup.
Does anyone have a program or recommend a plugin to netbeans that i can use to format this sql. Here's my view, give formatting it a go and repost it as an example if you like :)
/* ALGORITHM=UNDEFINED */ SELECT `e`.`Australia` AS `audit_anps`,`e`.`audit_end_date` AS `audit_auditenddate`,`e`.`BumperIssueDates` AS `audit_bumperissuedates`,`e`.`BumperIssuesLinked` AS `audit_bumperissuelinked`,`e`.`BumperIssues` AS `audit_bumperissues`,`e`.`bundledSales` AS `audit_bundledsales`,`e`.`CoverPrice` AS `audit_coverprice`,`e`.`CoverPrice2` AS `audit_coverprice2`,`e`.`CoverPrice2Day` AS `audit_coverprice2day`,`e`.`CoverPrice3` AS `audit_coverprice3`,`e`.`CoverPrice3Day` AS `audit_coverprice3day`,`e`.`CoverPrice4` AS `audit_coverprice4`,`e`.`CoverPrice4Day` AS `audit_coverprice4day`,`e`.`CoverPriceDay` AS `audit_coverpriceday`,`e`.`timestamp` AS `audit_datecreated`,`e`.`weeksbetween` AS `audit_daysbetween`,_utf8'' AS `audit_dayspublished`,`e`.`AustraliaDigital` AS `audit_digital_anps`,`e`.`BumperIssueDatesD` AS `audit_digital_bumperissuedates`,`e`.`BumperIssuesD` AS `audit_digital_bumperissues`,`e`.`BumperIssuesLinkedD` AS `audit_digital_bumperissueslinked`,`e`.`bundledSalesDigital` AS `audit_digital_bundledsalesdigital`,`e`.`CoverPriceD` AS `audit_digital_coverprice`,`e`.`CoverPrice2D` AS `audit_digital_coverprice2`,`e`.`CoverPrice2DayD` AS `audit_digital_coverprice2day`,`e`.`CoverPrice3D` AS `audit_digital_coverprice3`,`e`.`CoverPrice3DayD` AS `audit_digital_coverprice3day`,`e`.`CoverPrice4D` AS `audit_digital_coverprice4`,`e`.`CoverPrice4DayD` AS `audit_digital_coverprice4day`,`e`.`CoverPriceDayD` AS `audit_digital_coverpriceday`,`e`.`ExcludedDatesD` AS `audit_digital_excludeddates`,`e`.`inclAccomAirlinesSalesDigital` AS `audit_digital_inclaccomairlinesales`,`e`.`inclEducationalSalesDigital` AS `audit_digital_incleducationalsales`,`e`.`inclEventSalesDigital` AS `audit_digital_incleventsales`,`e`.`inclMultiplePublicationSalesDigital` AS `audit_digital_inclmultiplepublicationsales`,`e`.`IssuesD` AS `audit_digital_issues`,`e`.`IssuesAuditedD` AS `audit_digital_issuesaudited`,`e`.`NonPublishingDatesD` AS `audit_digital_nonpublishingdates`,`e`.`RemarksD` AS `audit_digital_remarks`,`e`.`exclAustraliaOther` AS `audit_exclaustraliaother`,`e`.`exclInExcess` AS `audit_exclinexcess`,`e`.`ExcludedDates` AS `audit_excludeddates`,`e`.`Exclusions` AS `audit_exclusions`,`e`.`FrequencyID` AS `audit_frequencyid`,`e`.`inclAccomAirlineSales` AS `audit_inclaccomairlinesales`,`e`.`inclEducationalSales` AS `audit_incleducationalsales`,`e`.`inclEventSales` AS `audit_incleventsales`,`e`.`inclMultiplePublicationSales` AS `audit_inclmultiplepublicationsales`,`e`.`InExcess` AS `audit_inexcess`,`e`.`Issues` AS `audit_issues`,`e`.`IssuesAudited` AS `audit_issuesaudited`,`e`.`NimsAvCopiesDelivered` AS `audit_nimaveragecopiesdelivered`,`e`.`NimsAvCopiesMailed` AS `audit_nimaveragecopiesmailed`,`e`.`NimsAvCopiesPrinted` AS `audit_nimaveragecopiesprinted`,`e`.`NIMCopiesDelivered` AS `audit_nimcopiesdelivered`,`e`.`NIMCopiesMailed` AS `audit_nimcopiesmailed`,`e`.`NIMCopiesPrinted` AS `audit_nimcopiesprinted`,`e`.`NonPublishingDates` AS `audit_nonpublishingdates`,`e`.`NZInExcess` AS `audit_nzinexcess`,`e`.`NewZealand` AS `audit_nznps`,`e`.`OCInExcess` AS `audit_ocinexcess`,`e`.`OSMoney` AS `audit_osmoney`,`e`.`OtherCountries` AS `audit_othercountries`,_utf8'' AS `audit_parentpublication`,`e`.`AuditPeriod` AS `audit_period`,`e`.`periodAdjustment` AS `audit_periodadjustment`,`e`.`periodAdjustmentValue` AS `audit_periodadjustmentvalue`,_utf8'' AS `audit_periodenddate`,_utf8'' AS `audit_periodstartdate`,`e`.`PubID` AS `audit_pubid`,`e`.`comments` AS `audit_remarks`,`e`.`SpecialPublishingDay` AS `audit_specialpublishingday`,`e`.`stageid` AS `audit_stageid`,`e`.`totalIssuesAudited` AS `audit_totalissuesaudited`,`e`.`lAuditType` AS `audit_type`,`e`.`iYear` AS `audit_year`,`e`.`AuditorEmail` AS `deprecated_AuditorEmail`,`e`.`AuditorName` AS `deprecated_AuditorName`,`e`.`dateAuditorApproved` AS `deprecated_dateAuditorApproved`,`e`.`dateSignatoryApproved` AS `deprecated_dateSignatoryApproved`,`e`.`dateSubmitted` AS `deprecated_dateSubmitted`,`e`.`DayPublished` AS `deprecated_dayspublished`,`e`.`FirstSignatoryEmail` AS `deprecated_FirstSignatoryEmail`,`e`.`FirstSignatoryName` AS `deprecated_FirstSignatoryName`,`e`.`FormStatus` AS `deprecated_FormStatus`,`e`.`lodgementstatus` AS `deprecated_lodgementstatus`,`e`.`lodgementtype` AS `deprecated_lodgementtype`,`e`.`nPeriod` AS `deprecated_nPeriod`,`e`.`nYear` AS `deprecated_nYear`,`e`.`s2complete` AS `deprecated_s2complete`,`e`.`s3complete` AS `deprecated_s3complete`,`e`.`SecondSignatoryEmail` AS `deprecated_SecondSignatoryEmail`,`e`.`SecondSignatoryName` AS `deprecated_SecondSignatoryName`
FROM (`auau7859_aba`.`el_abc_stage` `e` LEFT JOIN `auau7859_aba`.`el_abc_status` `s` ON((`s`.`stageid` = `e`.`stageid`)))
WHERE ((`s`.`statusid` = (SELECT `h`.`statusid` AS `statusid`
FROM `auau7859_aba`.`el_abc_status` `h` WHERE (`h`.`stageid` = `s`.`stageid`) ORDER BY `h`.`statusid` DESC
LIMIT 1)) AND (`s`.`currentstatus` = _latin1'complete'))
Ugly, right?
Whenever I use code formatting in Netbeans, or in Heidi SQL all it does it put each section (FROM/WHERE/LIMIT/SELECT) on a new line. This is no good because my select statement is so long. I need something that will at the very least put each select field on a new line.
Can You help me?
Thank you.
Create a stored procedure to re create the view. That keeps your formatting and allows you to add comments to help document the view. I name mine as sp_create_viewname
I use squirrel SQL.
The application itself is a bit hard for me to use over heidi sql (which i swear by) but heidi's sql formatting functionality lack the superiority of squirrel
http://squirrel-sql.sourceforge.net/
It can format a view's horrible code perfectly and without a fuss.
Done with one click in a free online SQLFormatter
/* ALGORITHM=UNDEFINED */
SELECT
`e`.`Australia` AS `audit_anps`
,`e`.`audit_end_date` AS `audit_auditenddate`
,`e`.`BumperIssueDates` AS `audit_bumperissuedates`
,`e`.`BumperIssuesLinked` AS `audit_bumperissuelinked`
,`e`.`BumperIssues` AS `audit_bumperissues`
,`e`.`bundledSales` AS `audit_bundledsales`
,`e`.`CoverPrice` AS `audit_coverprice`
,`e`.`CoverPrice2` AS `audit_coverprice2`
,`e`.`CoverPrice2Day` AS `audit_coverprice2day`
,`e`.`CoverPrice3` AS `audit_coverprice3`
,`e`.`CoverPrice3Day` AS `audit_coverprice3day`
,`e`.`CoverPrice4` AS `audit_coverprice4`
,`e`.`CoverPrice4Day` AS `audit_coverprice4day`
,`e`.`CoverPriceDay` AS `audit_coverpriceday`
,`e`.`timestamp` AS `audit_datecreated`
,`e`.`weeksbetween` AS `audit_daysbetween`
, _utf8'' AS `audit_dayspublished`
,`e`.`AustraliaDigital` AS `audit_digital_anps`
,`e`.`BumperIssueDatesD` AS `audit_digital_bumperissuedates`
,`e`.`BumperIssuesD` AS `audit_digital_bumperissues`
,`e`.`BumperIssuesLinkedD` AS `audit_digital_bumperissueslinked`
,`e`.`bundledSalesDigital` AS `audit_digital_bundledsalesdigital`
,`e`.`CoverPriceD` AS `audit_digital_coverprice`
,`e`.`CoverPrice2D` AS `audit_digital_coverprice2`
,`e`.`CoverPrice2DayD` AS `audit_digital_coverprice2day`
,`e`.`CoverPrice3D` AS `audit_digital_coverprice3`
,`e`.`CoverPrice3DayD` AS `audit_digital_coverprice3day`
,`e`.`CoverPrice4D` AS `audit_digital_coverprice4`
,`e`.`CoverPrice4DayD` AS `audit_digital_coverprice4day`
,`e`.`CoverPriceDayD` AS `audit_digital_coverpriceday`
,`e`.`ExcludedDatesD` AS `audit_digital_excludeddates`
,`e`.`inclAccomAirlinesSalesDigital` AS `audit_digital_inclaccomairlinesales`
,`e`.`inclEducationalSalesDigital` AS `audit_digital_incleducationalsales`
,`e`.`inclEventSalesDigital` AS `audit_digital_incleventsales`
,`e`.`inclMultiplePublicationSalesDigital` AS `audit_digital_inclmultiplepublicationsales`
,`e`.`IssuesD` AS `audit_digital_issues`
,`e`.`IssuesAuditedD` AS `audit_digital_issuesaudited`
,`e`.`NonPublishingDatesD` AS `audit_digital_nonpublishingdates`
,`e`.`RemarksD` AS `audit_digital_remarks`
,`e`.`exclAustraliaOther` AS `audit_exclaustraliaother`
,`e`.`exclInExcess` AS `audit_exclinexcess`
,`e`.`ExcludedDates` AS `audit_excludeddates`
,`e`.`Exclusions` AS `audit_exclusions`
,`e`.`FrequencyID` AS `audit_frequencyid`
,`e`.`inclAccomAirlineSales` AS `audit_inclaccomairlinesales`
,`e`.`inclEducationalSales` AS `audit_incleducationalsales`
,`e`.`inclEventSales` AS `audit_incleventsales`
,`e`.`inclMultiplePublicationSales` AS `audit_inclmultiplepublicationsales`
,`e`.`InExcess` AS `audit_inexcess`
,`e`.`Issues` AS `audit_issues`
,`e`.`IssuesAudited` AS `audit_issuesaudited`
,`e`.`NimsAvCopiesDelivered` AS `audit_nimaveragecopiesdelivered`
,`e`.`NimsAvCopiesMailed` AS `audit_nimaveragecopiesmailed`
,`e`.`NimsAvCopiesPrinted` AS `audit_nimaveragecopiesprinted`
,`e`.`NIMCopiesDelivered` AS `audit_nimcopiesdelivered`
,`e`.`NIMCopiesMailed` AS `audit_nimcopiesmailed`
,`e`.`NIMCopiesPrinted` AS `audit_nimcopiesprinted`
,`e`.`NonPublishingDates` AS `audit_nonpublishingdates`
,`e`.`NZInExcess` AS `audit_nzinexcess`
,`e`.`NewZealand` AS `audit_nznps`
,`e`.`OCInExcess` AS `audit_ocinexcess`
,`e`.`OSMoney` AS `audit_osmoney`
,`e`.`OtherCountries` AS `audit_othercountries`
, _utf8'' AS `audit_parentpublication`
,`e`.`AuditPeriod` AS `audit_period`
,`e`.`periodAdjustment` AS `audit_periodadjustment`
,`e`.`periodAdjustmentValue` AS `audit_periodadjustmentvalue`
, _utf8'' AS `audit_periodenddate`
, _utf8'' AS `audit_periodstartdate`
,`e`.`PubID` AS `audit_pubid`
,`e`.`comments` AS `audit_remarks`
,`e`.`SpecialPublishingDay` AS `audit_specialpublishingday`
,`e`.`stageid` AS `audit_stageid`
,`e`.`totalIssuesAudited` AS `audit_totalissuesaudited`
,`e`.`lAuditType` AS `audit_type`
,`e`.`iYear` AS `audit_year`
,`e`.`AuditorEmail` AS `deprecated_AuditorEmail`
,`e`.`AuditorName` AS `deprecated_AuditorName`
,`e`.`dateAuditorApproved` AS `deprecated_dateAuditorApproved`
,`e`.`dateSignatoryApproved` AS `deprecated_dateSignatoryApproved`
,`e`.`dateSubmitted` AS `deprecated_dateSubmitted`
,`e`.`DayPublished` AS `deprecated_dayspublished`
,`e`.`FirstSignatoryEmail` AS `deprecated_FirstSignatoryEmail`
,`e`.`FirstSignatoryName` AS `deprecated_FirstSignatoryName`
,`e`.`FormStatus` AS `deprecated_FormStatus`
,`e`.`lodgementstatus` AS `deprecated_lodgementstatus`
,`e`.`lodgementtype` AS `deprecated_lodgementtype`
,`e`.`nPeriod` AS `deprecated_nPeriod`
,`e`.`nYear` AS `deprecated_nYear`
,`e`.`s2complete` AS `deprecated_s2complete`
,`e`.`s3complete` AS `deprecated_s3complete`
,`e`.`SecondSignatoryEmail` AS `deprecated_SecondSignatoryEmail`
,`e`.`SecondSignatoryName` AS `deprecated_SecondSignatoryName`
...