Update query in liquibase - oracle

I need to run the below update query in liquibase, but I am not sure about the syntax. Can anyone please help:
update xyz.users
set email = (select CONCAT(username, '#gmail.com ') "email"
from xyz.users )
where email like '%#yahoo.com%' ;

try this
<update tableName="xyz.users">
<column name="email" valueComputed="(select CONCAT(username, '#gmail.com ')
from xyz.users)"/>
<where>email like '%#yahoo.com%'</where>
</update>

Related

add multiple columns with liquibase using yml

I want to add multiple columns to my database using liquibase and a yml-file.
I know that I can do this with one step using xml like this:
<changeSet author="liquibase-docs" id="addColumn-example">
<addColumn catalogName="cat"
schemaName="public"
tableName="person">
<column name="job" type="varchar(255)"/>
<column name="designation" type="varchar(255)"/>
</addColumn>
</changeSet>
Can I do the same in a yml-file?
- changeSet:
id: myId
author: malt
changes:
- addColumn:
tableName: myTable
columns:
- column:
name: name01
type: decimal(21,2)
- column:
name: name02
type: decimal(21,2)
This does not seem to work...
I just don't want to repeat the -addColumn-Tag again and again.
Thanks for your help!
Matthias
According to addColumn liquibase documentation you can do this in yaml as such (just their example):
databaseChangeLog:
- changeSet:
id: addColumn-example
author: liquibase-docs
changes:
- addColumn:
tableName: person
columns:
name: middlename
type: varchar(50)
You almost got it right, just need an extra indent after column:
- changeSet:
id: myId
author: malt
changes:
- addColumn:
tableName: myTable
columns:
- column:
 # note the indent below here!
name: name01
type: decimal(21,2)
- column:
name: name02
type: decimal(21,2)


Query returns only 4 out of 12 values of my table. Why is this happening?

I have created a script which I am using on 2 different system. One is Windows 10 with SQL Server Express 2019 and the other is on Windows 7 (32bit) with SQL Server Express 2014. The db I am using has the same structure. The code I am using in ASP Classic is exactly the same on both machines! But in the win7 machine does not work as it should!
I am having a query to my db and the problem is that SOME of the values I am getting are empty. The code I am using is the following:
<%
Set rs21 = Server.CreateObject("ADODB.Recordset")
strSQL21 = "SELECT * FROM otherfiles WHERE animalid LIKE '" & lngRecordNo & "'
AND historyid LIKE '" & historyid & "' order by datedone DESC"
rs21.Open strSQL21, adoCon
%>
BLAH BLAH BLAH
<%
Do While not rs21.EOF
historyid = rs21("historyid")
if not historyid = "" then
Set rshis = Server.CreateObject("ADODB.Recordset")
strSQLhis = "SELECT * FROM history WHERE id_no LIKE '" & historyid & "' order by id_no DESC"
rshis.Open strSQLhis, adoCon
'------------------- if I remove the following line (Set rscol) it works fine ---------------------------
Set rscol = Server.CreateObject("ADODB.Recordset")
strcol = "SELECT * FROM hospitals WHERE id_no = "& rsGuestbook21("hosid") &" order by id_no DESC"
rscol.Open strcol, adocon
color = rscol("color")
%>
BLAH BLAH BLAH
<%=rs21("datedone")%> ---> empty value
<%=rs21("id_no")%> ---> works fine!!!
I am 100% sure that my table has its values. In fact as I mention above only but setting the rscol = Server.CreateObject("ADODB.Recordset") then the values becomes ??empty??. Commenting this line works fine.
I just figured out my ??mistake??...
Not really sure if it is a mistake thou... but the problem solved when I placed a field that had a DATA TYPE of "nvarchar(MAX)" at the end of my of my table! Weird stuff??? Do you think that there is something more than that in which I should investigate?

How to extract a particular number from a long string of data using Oracle SQL?

I need the numbers extracted from the string of data contained in a column of a table.
Example string :
<strong>Customer Name</strong>: Hit - julaifnaf afbafbaf Caraballo Pichardo vs PICHARDO ALBERTO<br />
<strong>Address</strong>: NA - abdcinfainaf 42982542542 vs xx<br />
<strong>Country of citizenship</strong>: NA<br />
<strong>Country of residency</strong>: NA<br />
<strong>Date of birth</strong>: NA - xx vs Nov-72<br />
<strong>Place of birth</strong>: NA<br />
<strong>Identification Number</strong>: **1**<br />
<strong>emailDetails</strong>: <br/>
<b>Subject: </b>abcdejnfanfa <br/>
<b>Sent To: </b>abced#test.com<br/>
In the above example string the number I need extracted 1.
The length of the stings and position of the record vary,
but the numbers to be extracted always come after Identification Number</strong>: and before <br /><strong>.
What function can I use to extract this data?
SELECT TO_NUMBER(
REGEXP_SUBSTR(
column_name,
'<strong>Identification Number</strong>:.*?(\d+).*?<br />',
1,
1,
NULL,
1
)
) AS id_number
FROM table_name;
Try this:
select
regexp_replace(column_name,'.*<strong>Identification Number</strong>:[^>\d]*(\d+)[^>\d]*<br\s*/>.*', '\1', 1, 0, 'inm') as id
from html;
PS it's not very reliable solution though, because you can't parse any HTML using RegExp's.
Output:
ID
-----------
1

Xquery does not written a result

I have the following Xquery
select email1
from customers,
XMLTABLE(
'$customer/customerinfo/contacts/phone[#type="work"]'
PASSING object_value as "customer"
columns
email1 varchar2(60) path '/emails/email1'
) as x
EMAIL1
------------------------------------------------------------
1 row selected.
When executed on a table of customers of xmltype stored in oracle 12c i do not get any result but a blank .
The xml itself looks something like this
<customerinfo xmlns:ns0="http://posample.org" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Cid="1000">
<name>Kathy Smith</name>
<addr country="Canada">
<street>5 Rosewood</street>
<city>Toronto</city>
<prov-state>Ontario</prov-state>
<pcode-zip>M6W 1E6</pcode-zip>
</addr>
<contacts>
<phone type="work">416-555-1358</phone>
<emails>
<email1>kathy#stackoverflow.org</email1>
<email2>kathy#stackover.org</email2>
</emails>
<phone type="personal">416-555-1358</phone>
<emails>
<email1>kathy#stackoverflow.org</email1>
<email2>kathy#stackover.org</email2>
</emails>
</contacts>
</customerinfo>
1.I want the output to be kathy#stackoverflow.org.
<emails1/> is no children of <phone/>. This XML format is a little bit broken, as you cannot directly select any "work" email address.
An XPath expression which only matches the first <email1/> node after the "work phone" would be
/customerinfo/contacts/phone[#type="work"]/following-sibling::email1[1]

Oracle JPG metadata xpath from XMLTYPE column

I have a tavle storing photos. With a pl/sql script i extract the image metadata to the exifmetadata xmltype column.
I would like to select the elements one by one, but i always get null back and i don't know what is the issue with my xpath expression.
<exifMetadata xmlns="http://xmlns.oracle.com/ord/meta/exif" xsi:schemaLocation="http://xmlns.oracle.com/ord/meta/exif http://xmlns.oracle.com/ord/meta/exif" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<TiffIfd>
<Make tag="271">Apple</Make>
<Model tag="272">iPhone 4S</Model>
<Orientation tag="274">top left</Orientation>
<XResolution tag="282">72.0</XResolution>
<YResolution tag="283">72.0</YResolution>
<ResolutionUnit tag="296">inches</ResolutionUnit>
<Software tag="305">6.0.1</Software>
<DateTime tag="306">2012-11-16T13:31:15</DateTime>
<YCbCrPositioning tag="531">centered</YCbCrPositioning>
</TiffIfd>
<ExifIfd tag="34665">
<ExposureTime tag="33434">0.004405286</ExposureTime>
<FNumber tag="33437">2.4</FNumber>
<ExposureProgram tag="34850">Normal program</ExposureProgram>
<ExifVersion tag="36864">0221</ExifVersion>
<DateTimeOriginal tag="36867">2012-11-16T12:49:58</DateTimeOriginal>
<DateTimeDigitized tag="36868">2012-11-16T12:49:58</DateTimeDigitized>
<ComponentsConfiguration tag="37121">Y</ComponentsConfiguration>
<ShutterSpeedValue tag="37377">7.82697</ShutterSpeedValue>
<ApertureValue tag="37378">2.5260692</ApertureValue>
<BrightnessValue tag="37379">6.641153</BrightnessValue>
<MeteringMode tag="37383">Pattern</MeteringMode>
<Flash tag="37385">
<Fired>No</Fired>
</Flash>
<FocalLength tag="37386">4.28</FocalLength>
<FlashpixVersion tag="40960">0100</FlashpixVersion>
<ColorSpace tag="40961">sRGB</ColorSpace>
<PixelXDimension tag="40962">2902</PixelXDimension>
<PixelYDimension tag="40963">1938</PixelYDimension>
<SensingMethod tag="41495">One-chip color area</SensingMethod>
<ExposureMode tag="41986">Auto exposure</ExposureMode>
<WhiteBalance tag="41987">Auto</WhiteBalance>
<FocalLengthIn35mmFilm tag="41989">35</FocalLengthIn35mmFilm>
<SceneCaptureType tag="41990">Standard</SceneCaptureType>
</ExifIfd>
</exifMetadata>
And the SQL:
SELECT
p.metaexif.extract('//exifMetadata/TiffIfd/Make/text()').getStringVal() "Model"
FROM scott.photos p
WHERE id=22
;
The id 22 record exist that is sure.
you have a default namespace set so you have to cope with this.
eg use this:
select extractvalue(p.metaexif,'/exifMetadata/TiffIfd/Make',
'xmlns="http://xmlns.oracle.com/ord/meta/exif"')

Resources