Retrieve data from HugeClob in oracle - sql

I have one Table, in this table stored data as xml on HugeClob. In this xml I have several data. I want retrieve this data with SQL query. I add 3 xml example.
// First
<xml-fragment>
<sdr:OCAC>
<op:operation>Sale</op:operation>
<op:ID>100</op:ID>
<op:payload>
<op:Tea>
</op:Tea>
</op:payload>
</sdr:OCAC>
</xml-fragment>
// Second
<xml-fragment>
<sdr:OCAC>
<op:operation>Sale</op:operation>
<op:ID>101</op:ID>
<op:payload>
<op:Cofe>
</op:Cofe>
</op:payload>
</sdr:OCAC>
</xml-fragment>
// Third
<xml-fragment>
<sdr:OCAC>
<op:operation>Sale</op:operation>
<op:ID>102</op:ID>
<op:payload>
<op:Juice>
</op:Juice>
</op:payload>
</sdr:OCAC>
</xml-fragment>
I want shown query result as attached image. I'm so sorry for my english.
Tea's price is 1.50
Cofe's price is 2.50
Juice's price is 3.00

Related

Microsoft SQL Server generates two select queries and puts data in separate columns

I am looking for a query that separate the data with the condition WHERE in the same output but in separates columns.
Example: I have the table Product_2:
I have two separates queries (to separate the products by Produt_Tag):
SELECT
Product_Mark AS "PIT-10_Product_Mark",
Product_Model AS "PIT-10_Product_Model"
FROM Product_2
WHERE Product_Tag = 'PIT-10';
SELECT
Product_Mark AS "PIT-11_Product_Mark",
Product_Model AS "PIT-11_Product_Model"
FROM Product_2
WHERE Product_Tag = 'PIT-11';
And I get this output:
But I need the output to be like this:
Can someone tell me how I need to modify my query to have the four columns in the same table/ output?
Thank you
I forgot to tell that in the data I Have the “Porduct_Mark” that only appears one time. (in reality the data in “Product_Mark” is the name of the place where the instrument is located and one place can have one or two instruments “Product_Model”. At the end I’m looking for the result show in the image here below. I tried to use LEFT JOIN but that don’t work.
here is the new table "Product_2"
Result that I'm looking for:
Luis Ardila
I am assuming Product_PK is the primary key for the table and the repeated value 1002 shown in the question is a mistake. Considering this assumption, you can get the result set using self join as below.
SELECT pa.Product_Mark AS "PIT-10_Product_Mark", pa.Product_Model AS "PIT-10_Product_Model",
pb.Product_Mark AS "PIT-11_Product_Mark", pb.Product_Model AS "PIT-11_Product_Model"
FROM Product_2 pa
INNER JOIN Product_2 pb
ON pa.Product_Mark = pb.Product_Mark
WHERE pa.product_pk != pb.product_pk
and pa.Product_Tag = 'PIT-10'
and pb.Product_Tag = 'PIT-11';
verified same in https://dbfiddle.uk/NiOO8zc1

VS SR Report joining data from multiple Data sets?

Wondering if anyone can help me, I am currently learning, SRSS Reports and have been tasked with a Pay & Display vehicle registration report, for staff and student carparks, to show if they are registered for P&D. I have the report laid out as a 3 table column; Name, Vehicle Number and Vehicle Registration. I have from the below code set out in my datasets the Vehicle Number and Vehicle Registrations pulling through, with a parameter to filter out if is staff or student pay and display. However I am having difficulty with pulling the Staff and Student names into one name column as they are through two different datasets. Can anyone be of help at all please? TIA
**-- Pay & Display Carpark Details Dataset**
SELECT * FROM Carpark_Vehicles
WHERE VehicleCustNo IN (SELECT CustID FROM [dbo].[Carpark_Customer]
WHERE CarParkID IN (SELECT CarParkID FROM [dbo].[Carpark_CarPark]
WHERE CTypeID IN ('PD', 'SPD')))
--and CTypeID IN (#Carpark_type))
**--Vehicle Details Dataset**
SELECT
Carpark_Vehicles.VehicleID
,Carpark_Vehicles.RegNo
,VehicleCustNo
FROM
Carpark_Vehicles
WHERE CarPark_Vehicles.RegNo = #RegNo
**--Staff details dataset**
SELECT
StaffDetails_StaffandLeaverDetails.StaffNumber
,StaffDetails_StaffandLeaverDetails.LastName
,StaffDetails_StaffandLeaverDetails.Name1
FROM
StaffDetails_StaffandLeaverDetails
**--Student details dataset**
SELECT
Student_CurrentStudentDetails.StudentNumber
,Student_CurrentStudentDetails.StudentID
,Student_CurrentStudentDetails.LastName
,Student_CurrentStudentDetails.FirstName
FROM
Student_CurrentStudentDetails
**--Carpark permit type (Pay & Display) parameter**
SELECT DISTINCT
CTypeID, CASE CTypeID WHEN 'abc' THEN 'Students' WHEN 'abc' THEN 'Staff' END AS Label
FROM
Carpark_Customer
WHERE CTypeID IN ('abc', 'Abc')
For your req I just took some sample data. This entire example will give you Idea how to achieve your final result.
Note: this is just showing you way how to achieve it, you have to modify as per your req.
Student and Staff Info from 2 different Tables
Registration Info from another separate Table
Your Final Result when Student as parameter is selected
Your Final Result when Staff as parameter is selected
Now how did I achieved this?
My Design for Final Result
Row visibilty expression for your final result Table in SSRS
Expressiion as below
=IIF(Parameters!ReportParameter1.Value=1,
IIF(Isnothing(Lookup(Fields!PersonId.Value,Fields!PersonId.Value,Fields!Name.Value, "DSStudentInfo")),true,false),
IIF(Isnothing(Lookup(Fields!PersonId.Value,Fields!PersonId.Value,Fields!Name.Value, "DSStaffInfo")),true,
false)
)
first Name column visibility
second column name visibility
First Name data value expression
=Lookup(Fields!PersonId.Value,Fields!PersonId.Value,Fields!Name.Value, "DSStudentInfo")
second name data value expression
=Lookup(Fields!PersonId.Value,Fields!PersonId.Value,Fields!Name.Value, "DSStaffInfo")

Google's Big Query using SQL: Associate the assignee name and harmonized assignee name when there are multiple assignees

My goal is to create a table from Google's Big Query patents-public-data.patents.publications_201710 table using standard SQL that has one row for the publication_number, assignee and assignee_harmonized.name where the publication_number is repeated for records that have multiple assignees. Here's an example of my desired output:
publication_number|assignee|assignee_harm
US-6044964-A|Sony Corporation|SONY CORP
US-6044964-A|Digital Audio Disc Corporation|DIGITAL AUDIO DISC CORP
US-8746747-B2|IPS Corporation—Weld-On Division|IPS CORPORATION—WELD ON DIVISION
US-8746747-B2|null|MCPHERSON TERRY R
I've tried the following query based off of the UNNEST suggestion found in this post
#standard SQL
SELECT
p.publication_number,
p.assignee,
a.name AS assignee_harm
FROM
`patents-public-data.patents.publications_201710` AS p,
UNNEST(assignee_harmonized) AS a
WHERE
p.publication_number IN ('US-6044964-A',
'US-8746747-B2')
However, the output appears as follows:
row|publication_number|assignee|assignee_harm
1|US-6044964-A|Sony Corporation|SONY CORP
||Digital Audio Disc Corporation|
2|US-6044964-A|Sony Corporation|DIGITAL AUDIO DISC CORP
||Digital Audio Disc Corporation|
3|US-8746747-B2|IPS Corporation—Weld-On Division|MCPHERSON TERRY R
4|US-8746747-B2|IPS Corporation—Weld-On Division|IPS CORPORATION—WELD ON DIVISION
You can see that the "Sony Corporation" assignee is inappropriately associated with the "DIGITAL AUDIO DISC CORP" harmonized name in row 2 with a similar issue appearing in row 3. Also, rows 1 and 2 contain two lines each but don't repeat the publication_number identifier. I don't see a straightforward way to do this because the number of "assignee" doesn't always equal the number of "assignee_harmonized.name" and they don't always appear in the same order (otherwise I could try creating two tables and merging them somehow). On the other hand, there has to be a way to associate the "assignee" variable with its harmonized value "assignee_harmonized.name", otherwise the purpose of having a harmonized value is lost. Could you please suggest a query (or set of queries) that will produce the desired output when there are either multiple "assignee" or multiple "assignee_harmonized.name" or both?
You're querying for a string and two arrays - the whole thing basically looks like this:
{
"publication_number": "US-8746747-B2",
"assignee": [
"IPS Corporation—Weld-On Division"
],
"assignee_harm": [
"MCPHERSON TERRY R",
"IPS CORPORATION—WELD ON DIVISION"
]
}
So that's the data and you somehow need to decide how to treat the combination of them ... either you cross join everything:
#standard SQL
SELECT
p.publication_number,
assignee,
assignee_harmonized.name AS assignee_harm
FROM
`patents-public-data.patents.publications_201710` AS p
,p.assignee assignee
,p.assignee_harmonized AS assignee_harmonized
WHERE
p.publication_number IN ('US-6044964-A','US-8746747-B2')
.. which gives you relational data .. or you leave it as two separate arrays:
#standard SQL
SELECT
p.publication_number,
assignee,
ARRAY( (SELECT name FROM p.assignee_harmonized)) AS assignee_harm
FROM
`patents-public-data.patents.publications_201710` AS p
WHERE
p.publication_number IN ('US-6044964-A','US-8746747-B2')
You can save this nested result as a table in bq as well.

the field is too small to accept the data you wanted to add. try inserting or pasting less data

SELECT net1.hhid, net1.prod_price, net2.seed, net3.lph_labour, net4.crop_labour, net5.fer_cost, net6.pes_cost, net7.seed_labour, net8.irr_cost,
(net2.seed+net3.lph_labour+net4.crop_labour+net5.fer_cost+net6.pes_cost+net7.seed_labour+net8.irr_cost) AS cost,
(net1.prod_price-cost) AS net_profit
FROM net1, net2, net3, net4, net5, net6, net7, net8
WHERE net1.hhid=net2.hhid And net1.hhid=net3.hhid And net1.hhid=net4.hhid And net1.hhid=net5.hhid And net1.hhid=net6.hhid And net1.hhid=net7.hhid And net1.hhid=net8.hhid And net1.country=net2.country And net1.country=net3.country And net1.country=net4.country And net1.country=net5.country And net1.country=net6.country And net1.country=net7.country And net1.country=net8.country;
The error message states that the
field is too small to accept the amount of data you attempted to add. try inserting or pasting less data
What is wrong with my code? I need to add the column vales of net1 to 8 queries, in which there hhid and country should be equal.

Represent one to many relationship on one report and get the many-table in a row instead of col

My user wants a report which rows and columns of many-table repeats in a single row until all rows of many-table are finished.
what is the best way to write query for that?
i hope could get what i want
______________________________________________________________________________________
|table(1) | table(2) |
|---------------|--------------------|--------------------|------|--------------------|
|table(1) (row1)|table(2 of 1)(row 1)|table(2 of 1)(row 2)| .... |table(N of 1)(row X)|
|---------------|--------------------|--------------------|------|--------------------|
|table(1) (row2)|table(2 of 2)(row 1)|table(2 of 2)(row 2)| .... |table(N of 2)(row y)|
|---------------|--------------------|--------------------|------|--------------------|
|table(1) (row3)|table(2 of 3)(row 1)|table(2 of 3)(row 2)| .... |table(N of 3)(row Z)|
|---------------|--------------------|--------------------|------|--------------------|
...
...
...
These are the tools you need:
Dynamic SQL
nested queries
rownum function
case when
If possible, I would load the data from the database to your front end and change the representation there.