want to extract two values from rows in a single sql result
Let me first of all explain the situationI have two tables
1 Animal_details(animal_id,and other details)
2 Animal_weight(animal_id,seq_no,weight,date_weighed)
in fact situation here is that for each weight I am inserting a new line with seq_no say
1 for the first weight
2 for the second weight...
with their weight and date
for example. animal_id = 1 seq_no = 1, weight = 200, date_weighed = 12-may-2000;
animal_id = 1, seq_no = 2, weight = 250, date_weighed = June 12, 2000;
means seq_no = 1 represents 1 weight of animals
seq_no = 2 represents 2 weight of animals
how an animal can have any number. weighted times.
now what I want, I want to show a result with
animal_id, weight_1, weight_2 with other animals details in a single line
How can I get first weight and the second or more weight in the same line for any animal?
Please answer soon, its urgency.
Thank you
You cannot issue a SQL with dynamic column list of 100%. What you can do is something like the questions:
with t as (
select animal_id,
max(case seq_no = 1 then weight end) first_weight,
max(case seq_no = 2 then weight end) second_weight,
max(case seq_no = 3 then weight end) third_weight
from animal _weight
where seq_no <= 3
group by animal_id
)
select t1.animal_id,
first_weight,
second_weight,
third_weight,
other_details
from t t1,
animal_details t2
where t2.animal_id = t1.animal_id
/
SY.
Tags: Database
Similar Questions
-
I want to analyze the values from a string
Hello.. I want to analyze certain values in a string... it's values in my channel...
anyType{NewDataSet=anyType{Table=anyType {SINo=5; ProductId=33;productname=aaa; price=543;};Table=anyType{SINo=1; ProductId=111;productname=bbb;price=543;};};}
I need to display my SINo, ProductId, productname and price... everything separately... is it possible? or is it possible to convert this string to an xml and then parse the values?
You can write a function to split this string with respect to the level of a delimiter, in this case '=' can be used, like the Split function available in the string for the Desktop Java class.
This function returns an array of strings in which the split string values is stored.
-
Install Oracle GoldenGate Linux to synchronize two schemas from database on a single server
Hi all
I have to synchronize two schemas from database (Oracle 12 c) in a single host RedHat Linux to demonstrate and understand the use of OGG V12.1.2.1.0. I try to do. But it's complicated and confused me because I am new to Oracle and Linux. I followed this tutorial ( install Oracle GoldenGate for Oracle 12.1.2 on CentOS/6.x to 6.x/RHEL Linux 6.x EL ). But it is difficult to understand how I can match with two diagrams of database on a single server.
And I found this tutorial (Oracle GoldenGate on Linux: two-way replication of Oracle 11 GR 2 to Oracle 11 g 2). He said: "" If you have that one host, it may be useful to change the /etc/hosts file to create aliases forhost01.example.com and host02.example.com.". What it really means?The other seems to be useful. But it's totally different from 1. Is that this will help my job since I use 12 c Oracle Server?
Can I get some tips to continue my task?
Here's another tutorial - http://www.oracle.com/webfolder/technetwork/tutorials/obe/fmw/goldengate/12c/OGG12c_Integrated_Replicat/index.html
It has everything set up on a single Linux host.
-
Difficult to extract multiple values from an XML document
I have the following XML Document
I need to retrieve the Id of the node FacilitySiteInteraction - in this case, the values are 78104 and 78105.<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> <s:Header> <ActivityId CorrelationId="4fc67c0d-4416-4c1f-92c5-0d6624fb41fd" xmlns="http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics">30ccb32d-d6f5-4442-a41a-1eb735112501</ActivityId> </s:Header> <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <FacilitySiteInteractionList xmlns="urn:WA.Ecy.ADS.FacilitySite.Services"> <FacilitySiteInteraction> <Id>78105</Id> <StartDate>2009-07-31T00:00:00</StartDate> <StatusCode>65</StatusCode> <InteractionTypeCode>WQGSWI</InteractionTypeCode> <FacilitySiteId>14951</FacilitySiteId> <CurrentSystemProgramName>WATQUAL</CurrentSystemProgramName> <CurrentSystemName>WPLCS</CurrentSystemName> <FederalProgramId/> <EndDate xsi:nil="true"/> <InteractionId>78105</InteractionId> <ProgramFacilitySiteName>Hedwall Inc.</ProgramFacilitySiteName> <ModifiedDate>2009-07-31T07:30:57.99</ModifiedDate> <ModifiedByName>taus461</ModifiedByName> <CreatedDate>2009-07-31T07:30:57.99</CreatedDate> <FS_FEATUREs/> </FacilitySiteInteraction> <FacilitySiteInteraction> <Id>78104</Id> <StartDate>2009-07-01T00:00:00</StartDate> <StatusCode>65</StatusCode> <InteractionTypeCode>WQMJIND</InteractionTypeCode> <FacilitySiteId>14951</FacilitySiteId> <CurrentSystemProgramName>WATQUAL</CurrentSystemProgramName> <CurrentSystemName>WPLCS</CurrentSystemName> <FederalProgramId/> <EndDate xsi:nil="true"/> <InteractionId>78104</InteractionId> <ProgramFacilitySiteName>Hedwall Inc.</ProgramFacilitySiteName> <ModifiedDate>2009-07-31T07:24:02.76</ModifiedDate> <ModifiedByName>taus461</ModifiedByName> <CreatedDate>2009-07-31T07:24:02.76</CreatedDate> <FS_FEATUREs/> </FacilitySiteInteraction> </FacilitySiteInteractionList> <TotalRowCount xmlns="urn:WA.Ecy.ADS.FacilitySite.Services">2</TotalRowCount> </s:Body> </s:Envelope>
I tried to use extractvalue just, but he hesitates with error ORA-19025.
If I use just extracted I see there the rubselect extractvalue(x,'//FacilitySiteInteractionList/FacilitySiteInteraction/Id','xmlns="urn:WA.Ecy.ADS.FacilitySite.Services"') from my_tab; ERROR at line 2: ORA-19025: EXTRACTVALUE returns value of only one node -- note: column my_tab.x is an xmltype data type
The format of the XML document does not have to consider another records/lines.select extract(x,'//FacilitySiteInteractionList/FacilitySiteInteraction/Id', 'xmlns="urn:WA.Ecy.ADS.FacilitySite.Services"') from my_tab; <Id xmlns="urn:WA.Ecy.ADS.FacilitySite.Services">78105</Id><Id xmlns="urn:WA.Ecy.ADS.FacilitySite.Services">78104</Id>
So, the next thing I tried was using the value of the iterator:
The downside of what I see is that I must first enter the TotalRowCount value and then more wrap XML Document TotalRowCount timesselect extractvalue(x,'//FacilitySiteInteractionList/FacilitySiteInteraction[2]/Id', 'xmlns="urn:WA.Ecy.ADS.FacilitySite.Services"') from my_tab; 78104
in order to get these values. So I was wondering if it is a more effective approach to enter these data?
Thank you, TonySQL> with t as ( select xmltype('
30ccb32d-d6f5-4442-a41a-1eb735112501 78105 2009-07-31T00:00:00 65 WQGSWI 14951 WATQUAL WPLCS 78105 Hedwall Inc. 2009-07-31T07:30:57.99 taus461 2009-07-31T07:30:57.99 78104 2009-07-01T00:00:00 65 WQMJIND 14951 WATQUAL WPLCS 78104 Hedwall Inc. 2009-07-31T07:24:02.76 taus461 2009-07-31T07:24:02.76 2 -
Another REGEXP question: how to extract multiple values from a string
Hi, how can I retrieve multiple values to a string with RegExp with Oracle SQL constructs?
Have looked at the various examples, I cannot understand this.
the following Sql code
Returns CN = A_role.select regexp_substr(sessie."rollen", 'CN=A_role') "A_role" from ( select ' CN=A_role,OU=a_org_unit,OU=another_org_unit,DC=bz,DC=ad,DC=min,DC=local CN=Another_role,OU=some_org_unit,DC=bz,DC=ad,DC=min,DC=local CN=Users,OU=Dep,DC=bz,DC=ad,DC=min,DC=local ' "rollen" from dual ) sessie;
I want him back all of the CN = concatenated values with a semicolon and stripped of the CN = bit.
So: A_role; Another_role; Users .
Any help would be much appreciated. Here I use database 11g 11.2.0.2.0.
Does anyone have an idea how to do this in SQL?
best regards MikeHello
If using Oracle 11 gwith tst as (select 'CN=A_role,OU=a_org_unit,OU=another_org_unit,DC=bz,DC=ad,DC=min,DC=local,' ||'CN=Another_role,OU=some_org_unit,DC=bz,DC=ad,DC=min,DC=local,' ||'CN=Users,OU=Dep,DC=bz,DC=ad,DC=min,DC=local' as rollen from dual ) select listagg(sub, ',') within group (order by rn) as res from (select regexp_substr(rollen, '(CN=)([[:alnum:]_]+)',1,rownum,'i',2) sub, rownum rn from tst connect by level <=length(rollen) ) where sub is not null
-
Insertion and extraction of data from a database by USING SQL Developer al32UTF8
Hi guys,.
Before I post my questions, I think it's better for me to give you guys my first understandings so that it is easier to understand where / if I have gone wrong...
I use Windows XP and Oracle 10 g
------------------------------------------------------------------------------------------------------------------------------------------------------------------
Non-unicode client - a client program that needs to use the code page of the operating system for the mapping of unicode data retrieved from the database as well as the support to display/insert characters from the code page to the database.
For example sqlplusw.exe
Therefore, when you use a non-unicode client
(1) we define the code page of the OS (Control Panel - regional and language of the parameter - advance - the language for non-unicode programs) to the code page that contain the characters that we will view/insert.
(2) we also defined the NLS_LANG characterset on the character set of code page, that we'll insert so that when we do an insert (for example in thai), oracle will and automatic conversion to Unicode can take place. This is also true when recover us the database unicode data so that the correct character set conversion can take place.
INSERTION OF
THAI->-> UNICODE conversion
RECOVERY OF
THAI <-conversion <-UNICODE
I hope that my basic understanding is correct up to this point.
---------------------------------------------------------------------------------------------------------------
Unicode client - a client program that supports display/inserting unicode characters without the need to set the code page of the operating system (Control Panel - regional and language setting - control - language for non-unicode programs advance)
For example isqlplus http or SQL Developer
However,.
(1) there are still set the NLS_LANG so that the correct conversion can take place between the client and the database.
For example, when the recovery if we set NLS_LANG value ZHS16GBK (Chinese) character and store data in Unicode in the database is for example (THAI), then the conversion would be a mistake.
It's a supported unicode client, then the NLS_LANG character set should be set to UNICODE as well.
---------------------------------------------------------------------------------------------------------------------------
Those are my questions
* Important - please help if you're busy and don't have the time to answer the remaining questions
(* Q1) if I had to use a unicode client, what should I put my character NLS_LANG set?
AMERICAN_AMERICA. UTF8?
(* T2) where can I put the NLS_LANG information of character in SQL Developer, I know there is a metalink for setting NLS_LANG using isqlplus but I cant seem to google each led for SQL developer.
Q3) is my basic understanding of up to this point? If no, please explain in a term more widespread that I'm really not familiar with character sets code page, unicode and fonts, glyphs...
A unicode client (Q4) didn't need to refer to the OS codepage (regional and language updates), y at - it a code page UNICODE for the customer to refer to, or is there an available window API?
Q5), there are still set the NLS_LANG so that the correct conversion can take place between the customer and the > > database.
For example, when recovery if we set NLS_LANG value ZHS16GBK (Chinese) character and the data store in > > unicode in the database is for example (THAI), then the conversion would be erroneous.
--------------------------------------------------------------------------------------------------------------------------
Thank you for spending the time to read my questions and I hope to hear soon tips from you guys.
Million thanks again for sharing.
Best regards
Noob, but eager to learnThe requirement to always set NLS_LANG is not true for JDBC, which ignores the NLS_LANG altogether. Java programs extract the textual data in string variables, which uses Unicode UTF-16 by design. JDBC defines the conversion of character sets so that data is converted between UTF - 16 and the database or the national character set.
The obligation to set NLS_LANG is not generally true for the OIC, either. The first call to a problem of the BEAK may be OCIEnvNlsCreate(). This call has two parameters that allow the caller to set the character set to use for the text of VARCHAR2/TANK/LONG/CLOB/statement and the character set to be used for NCHAR/NVARCHAR2/NCLOB. Only if these character sets is specified as 0, character set NLS_LANG is used. Also, the OIC programs can specify different character for each binding sets or set the variable (i.e. the buffer input/output). Note: The OIC programs always use NLS_LANG to initialize the language settings and the territory for the client program and the database session. Only the character set can be specified is OCIEnvNlsCreate().
OCIEnvNlsCreate() can specify the client character set to UTF-16 (platform boutien) format. This is not possible with NLS_LANG.
Various interfaces based on the BEAK, such as ODBC Oracle and .NET for the ODP, explicitly initialize OCI with character set Unicode and therefore ignore the NLS_LANG character set as well.
Thnx,
Sergiusz -
How to extract a string from a varchar column value
Hello
I have a varchar2 column that got the xml data. I want to extract the value of a tag < test > < / test >
I can't use EXTRACT because the column is not XMLTYPE.
Please suggest.Insert first only the first two columns:
INSERT INTO TESTXML (id,name) VALUES(1, '
'); INSERT INTO TESTXML (id,name) VALUES(2, 'ABCDEFTEST '); INSERT INTO TESTXML (id,name) VALUES(2, 'XYZUVWTEST ');XYZUVWTES Make this update:
update testxml set temp=rtrim(ltrim(regexp_substr(name,'
(.*?) '),''),' ');Edited by: hartmutm the 01.10.2010 05:13
-
How to merge two values of resource bundle?
Hi all
JDev worm: 11.1.1.7
I want to merge two values of resource bundle... How to do?
like this #{expr? str1: str1 + str2}
I tried like below and used some features of jstl... but no use did not work... got a parse exception, exception of compilation, etc...
< af:outputText value = "#{row.accountName eq 'AccountName9'?" {resource ['LBL_WELC']: resources ["LBL_WELC"] + resource ['LBL_HOME']} "/ >"
I would like to know how to do this?
Kind regards
Gopi
The outputtext above is an example, I can use diff bundle keys like below,
The principle is the same
Dario
-
Retrieve two values of column in a table
Hi I want to retrieve two values of column in a table and store the values as a single column value in another table... How to do with it?Use in this way:
Insert in tab2 (col1) select col1 | col2 from tab1; -
Multiplies two values of two different columns and display in cold fusion!
Hi all
I have a table book_sale
Topic | quantity | rate
===================
Science | 5. $25.00
Mathematics | 7. $70.00
Reading | 20. $2.30
==========================================================
I tried to code
< cfquery name = "get_saleamount" datasource = "Book" >
Select the object, the quantities, rates
of book_sale
< / cfquery >
< table >
< b >
< /Th > < th > topic
< /Th > < th > quantity
< /Th > < th > rates
Proceeds from the sale of < /th > < th >
< /tr >
< cfloop query = "get_saleamount."
< b >
< td > #Subject # < table >
< td > #Quantity # < table >
< td > #Rate # < table >
< td > #Quantity # * #Rate # < table >
< /tr >
< / cfloop >
< /table >
The multiplication operation did not work code above. I want to calculate sale_amount = quantity * note and display the results in a table. Please give me some advice how to multiply two values from database and display them in a table above. Thanks in advance.
If you want to exit, then simply change your
#Quantity # * #Rate #.
TO
#Quantity * rate #.but you can do it at the level of the database, if you have db (most do so):
Select the object, the quantities, rates, (amount * rate) AS ttl_cost
of book_sale
...
#Subject #.
#Quantity #.
#Rate #.
#ttl_cost #.
Azadi Saryev
SABAI - Dee.com
http://www.SABAI-Dee.com/ -
How to return two values of a function?
Hi all
I have a function which returns a varchar2 value. This value is used in the SQL of a ref cursor
Now I want this function returns two values. I tried to use varray, but could not accomplish the task.
Can you tell me how can I find the two values from a function? and how this function can be called in a SQL query?
Thank you very muchThe query should look like:
SELECT v.col.name AS name , v.col.flag AS flag FROM ( SELECT kk_test_kk(t.somecolumn,t.someothercolumn,42) AS col FROM sometable t ) v;
Note that you need to prefix with the name of view inline ('v' in the example) and the expression of the function ('col' in the example).
-
Synchronize two schemas from database on a linux server using Oracle GoldenGate
I followed this guide ( http://www.oracle.com/webfolder/technetwork/tutorials/obe/fmw/goldengate/12c/OGG12c_Installation/index.html?cid=9167 & ssid = 0 ) and for two different databases running on the same instance of database schemas.
What I have now is a Linux server with two Oracle database schemas. I have access through my Linux virtual machine. I want to do the synchronization possible between them.I use Oracle GoldenGate to make this possible. What should I do now? Goldengate is must be installed in the server too? I'm totally new to this situation. Can someone give me at least the major steps before going to the more comprehensive study?
Well understood. This helped.
Install Oracle GoldenGate Linux to synchronize two schemas from database on a single server
-
extract the value between the _ or until the end
Hello
I was trying to extract a value from format using regexp_substr below. But I don't know how to use the REGEXP_SUBSTR for this. Can someone please help on this.
STRING
ORACLE_TECHNOLOGY
ORACLE_TECHNOLOGY_NETWORK
ORACLE_TECHNOLOGY_NETWORK_INDIA
output:
TECHNOLOGY
So, what can be the input string, the output should be the string between the 1st and 2nd underscore (_). If missing the 2nd terms underscore (_), then it should give to the end.
My version of oracle's 11g.
Oracle Database 11 g Enterprise Edition Release 11.2.0.3.0 - 64 bit Production
PL/SQL Release 11.2.0.3.0 - Production
"CORE 11.2.0.3.0 Production."
AMT for 64-bit Windows: Version 11.2.0.3.0 - Production
NLSRTL Version 11.2.0.3.0 - Production
regexp_substr (String, ' _ ([^ _] *)(_|$)', 1, 1, null, 1)
or
substr (String, instr (string, '_') + 1, decode (instr (string, '_', 1, 2), 0, Length - instr (string, '_', 1, 2), instr (string, '_', 1, 2) - instr (string, '_', 1, 1) - 1))
-
Extraction of values within the brackets():
HelloPlease, help me to overcome this problem.
I want to extract the value inside the caliper.
example:
place (Chennai.Mumbai, Delhi)
I want inside the support value which is chennai.mumbai, delhi.
I used replace Regualr expression but I can't.
Thank you
Elayaperumal
SQL > t
2 as
(3)
4. Select 'place (chennai.mumbai, delhi)' str
5 double
6)
7 select substr (str, instr (str, ' ('), instr (str, ' ') ' ' ')-instr (str, ' (()) + 1) method_1)
8, regexp_substr (str, ' \([^)] +-)', 1, 1) method_2
9, regexp_replace (str, ' ([^ ()] +) (\([^)] +)', "\2") method_3
10 t;METHOD_1 METHOD_2 METHOD_3
---------------------- ---------------------- ----------------------
(chennai.mumbai, delhi) (chennai.mumbai, delhi) (chennai.mumbai, delhi)SQL >
-
Extract the value after the period
Hello
I am trying to extract the value from each period.
I have the table data is stored in this mode 172.168.15.10, which is an IP address,.
My requirement is I need to first value in a query with must return 172
If I need the value after the second period, it should return 168
Please suggest me how to write a SQL for the above requirement and oracle 11i Enterprise edition as the database.
Thank you
Sudhirwith regexp
select regexp_substr('172.168.15.10', '\d+', 1, :pos) s from dual
without regexp
select substr(s , instr(s, '.', 1, :pos) +1 , instr(s, '.', 1, :pos + 1) - instr(s, '.', 1, :pos) -1 ) s from (select '.'||'172.168.15.10'||'.' s from dual)
Edited by: chris227 the 01.10.2012 01:23
Maybe you are looking for
-
Good afternoon Assist. I hope you are well. I pressed a button then that in my Thunderbird, and he added a function of drop on the thread of the message. When receives an email and someone replies to the same message, it shows a menu function drop-do
-
Tecra M3 dark display, checked the usual problems
Hello My M3 went dark, it flickered on and off for about a week and then completely dark. I still work if I get the right angle and an external monitor is fine. If haven't tried a new cable from the screen, no difference and a new inverter, also no d
-
Continious beep at boot by Satellite L350-235
Hello world I have a problem on one of our Toshiba. It gives me now a Continious beep when starting the machine after having given in the bootpw.If I remove the battery and plug it back it starts normally. But after the next reboot, the problem recur
-
How security are the links posted in the answers to the questions?
Earlier, I asked why the SP3 update to my SP2, explains a backup should be performed. I was also asked why it was not conducted earlier. I'm still on SP2. I don't want to lose the programs and software on my computer. A backup really protect softw
-
the Welcome window in startup turns until I have press control / alt + delete
Welcome to the startup window hangs until I have press control / alt + delete