Adding columns in a open sql select query
Hi Everyone,
I would like to add the values of n columns of a table and place them in one column, how can i achieve this in open sql.
In oracle native sql the query will look like this:
Select col1 + col2 + col3 AS col
from tab1;
On a similar grounds, i would like to concatenate the contents of n columns into one column. The oracle native sql will look like this:
select col1 || col2 || col3
from tab1;
How can I do this in Open SQL.
Thanks in advance.
Prabhu.
Hi Prabhu,
I'm afraid what you're trying to do is not possible using the Open SQL. You will have to get the data from all the three columns into an internal table and then write your own logic to accomplish the same.
data : begin of itab occurs 0,
col1 type i,
col2 type i,
col3 type i,
col4 type i,
end of itab.
field-symbols: <fs_itab> like line of itab.
SELECT COL1
COL2
COL3
INTO TABLE ITAB.
LOOP AT ITAB assigning <fs_itab>.
<fs_itab>-col4 = <fs_itab>-col1 + <fs_itab>-col2 + <fs_itab>-col3.
ENDLOOP.
Regards,
Anand Mandalika.
Similar Messages
-
How to capture all the rows returned from a sql select query in CPO
Hi,
I am executing an sql select query which returns multiple rows. I need to capture the values of each row to specific variables. How do I proceed.
Thanks,
SwatiThe select activities ("Select from Oracle," Select from SQL Server," etc.) against database already return tables. Use one of the database adapters to do your select, and it will already be in a table form. Just put your query in the select and identify the columns in your result table. The online help or the database adapter guides in the product documentation can help.
-
Oracle SQL Select query takes long time than expected.
Hi,
I am facing a problem in SQL select query statement. There is a long time taken in select query from the Database.
The query is as follows.
select /*+rule */ f1.id,f1.fdn,p1.attr_name,p1.attr_value from fdnmappingtable f1,parametertable p1 where p1.id = f1.id and ((f1.object_type ='ne_sub_type.780' )) and ( (f1.id in(select id from fdnmappingtable where fdn like '0=#1#/14=#S0058-3#/17=#S0058-3#/18=#1#/780=#5#%')))order by f1.id asc
This query is taking more than 4 seconds to get the results in a system where the DB is running for more than 1 month.
The same query is taking very few milliseconds (50-100ms) in a system where the DB is freshly installed and the data in the tables are same in both the systems.
Kindly advice what is going wrong??
Regards,
PurushothamSQL> @/alcatel/omc1/data/query.sql
2 ;
9 rows selected.
Execution Plan
Plan hash value: 3745571015
| Id | Operation | Name |
| 0 | SELECT STATEMENT | |
| 1 | SORT ORDER BY | |
| 2 | NESTED LOOPS | |
| 3 | NESTED LOOPS | |
| 4 | TABLE ACCESS FULL | PARAMETERTABLE |
|* 5 | TABLE ACCESS BY INDEX ROWID| FDNMAPPINGTABLE |
|* 6 | INDEX UNIQUE SCAN | PRIMARY_KY_FDNMAPPINGTABLE |
|* 7 | TABLE ACCESS BY INDEX ROWID | FDNMAPPINGTABLE |
|* 8 | INDEX UNIQUE SCAN | PRIMARY_KY_FDNMAPPINGTABLE |
Predicate Information (identified by operation id):
5 - filter("F1"."OBJECT_TYPE"='ne_sub_type.780')
6 - access("P1"."ID"="F1"."ID")
7 - filter("FDN" LIKE '0=#1#/14=#S0058-3#/17=#S0058-3#/18=#1#/780=#5#
8 - access("F1"."ID"="ID")
Note
- rule based optimizer used (consider using cbo)
Statistics
0 recursive calls
0 db block gets
0 consistent gets
0 physical reads
0 redo size
0 bytes sent via SQL*Net to client
0 bytes received via SQL*Net from client
0 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
9 rows processed
SQL> -
hi friends,
i've a view called "risk_efforts" with fields user_id,user_name,wknd_dt,week_day,prod_efforts,unprod_efforts.
Name Type
ROW_ID NUMBER
USER_ID VARCHAR2(14)
USER_NAME VARCHAR2(50)
WKND_DT VARCHAR2(8)
WEEK_DAY VARCHAR2(250)
PROD_EFFORTS NUMBER
UNPROD_EFFORTS NUMBER
data is like this:
when there is some data in prod_efforts, unprod_efforts will be null
when there is some data in unprod_efforts, prod_efforts will be null
for example:
USER_ID USER_NAME WKND_DT WEEK_DAY PROD_EFFORTS UNPROD_EFFORTS
G666999 GTest 20100403 TUE null 3
G666999 GTest 20100403 TUE 14 null
now i want to combine these 2 rows into 1 row i.e o/p should be like this
USER_ID USER_NAME WKND_DT WEEK_DAY PROD_EFFORTS UNPROD_EFFORTS
G666999 GTest 20100403 TUE 14 3
i've tried all combinations but couldn't get the query. Please help me with the exact SQL select query.
thanks,
GirishWelcome to the forum.
First read this:
Urgency in online postings
Secondly, it's always helpful to provide the following:
1. Oracle version (SELECT * FROM V$VERSION)
2. Sample data in the form of CREATE / INSERT statements.
3. Expected output
4. Explanation of expected output (A.K.A. "business logic")
5. Use \ tags for #2 and #3. See FAQ (Link on top right side) for details.
You have provided #3 and #4. However with no usable form of sample data forum members will often not respond as quickly as they could if you provided #2.
I'm just wagering a guess here but what about this:SELECT ROW_ID
, USER_ID
, WKND_DT
, WEEK_DAY
, MAX(PROD_EFFORTS) AS PROD_EFFORTS
, MAX(UNPROD_EFFORTS) AS UNPROD_EFFORTS
FROM RISK_EFFORTS
GROUP BY ROW_ID
, USER_ID
, WKND_DT
, WEEK_DAY -
Reg: SQL select Query in BPEL process flow
<p>
Hi,
I am suppose to execute a SQL select query (in BPEL Process flow) as mention below in JDeveloper using Database adapter.
</p>
<p>
SELECT LENGTH, WIDTH, HEIGHT, WEIGHT,
</p>
<p>
LENGTH*WIDTH* HEIGHT AS ITEM_CUBE
</p>
<p>
FROM CUBE
</p>
<p>
WHERE ITEM= <xyz>
</p>
<p>
AND OBJECT= (SELECT CASE_NAME FROM CUBE_SUPPLIER WHERE ITEM=<xyz> AND SUPP_IND = ‘Y')
<strong>Now my question is:
1.</strong> What does this "*" refer to in the query and how can I retrieve the value of LENGTH*WIDTH* HEIGHT from the query where LENGTH,WIDTH and HEIGHT are the individual field in the table.
2.What does this " AS" refer to? If " ITEM_CUBE " is the alies for the table name "ITEM" to retrieve the value, then query shoud be evaluated as
</p>
<p>
SELECT LENGTH, WIDTH, HEIGHT, WEIGHT,
</p>
<p>
LENGTH*WIDTH* HEIGHT AS ITEM_CUBE
</p>
<p>
FROM CUBE
</p>
<p>
WHERE <strong>ITEM_CUBE.ITEM</strong>= <xyz>
</p>
<p>
AND <strong>ITEM_CUBE.OBJECT</strong>= (SELECT CASE_NAME FROM CUBE_SUPPLIER WHERE ITEM=<xyz> AND SUPP_IND = ‘Y')
Is my assumption correct?
Please suggest asap.
Thanks...
</p>
<p>
</p>Hi
Thank for your reply!
I have a nested select query which performs on two different table as shown below:
<p>
SELECT LENGTH, WIDTH, HEIGHT, WEIGHT,
</p>
<p>
LENGTH*WIDTH* HEIGHT AS ITEM_CUBE
</p>
<p>
FROM CUBE
</p>
<p>
WHERE ITEM= <abc>
</p>
<p>
AND OBJECT= (SELECT NAME FROM SUPPLIER WHERE ITEM=<Item> AND SUPP_IND = ‘Y')
I am using DB adapter of Oracle JDeveloper in BPEL process flow, where I can able to select only one master table in DB adapter say SUPPLIER and its attributes at a time.But as per my requirment I need to select both the table (CUBE and SUPPLIER) in a single adapter to execute my query.
It can be achievable by using two DB adapter , One to execute the nested query and another to execute the main qyery considering value of nested query as a parameter.But I want to achieve it by using a single one.
Am I correct with my concept?
Please suggest how to get it ?
</p>
Edited by: user10259700 on Oct 23, 2008 12:17 AM -
Parsing an OPEN SQL select statement
Hi all,
I want to parse an open SQL select statement to get the list of tables and the corresponding fields in the select statement.
Is there some ABAP-internal syntax from the SAP Database Interface that does this? or is the only option to do this is to manually break the statement?
Thanks.
GirishHi,
I doubt if there is something like that available to use. It think you will have to write a parser for yourself.
Regards -
How do I concatenate 2 fields in an Open SQL Select
Hi,
I have an internal table (simplified) that looks like this:
BEGIN OF t_konv,
kwert_vprs TYPE kwert,
knumv_kposn type char16,
END OF t_konv.
From an Open SQL Select statement I need to put kwert into kwert and I need to combine knumv and kposn into knumv_kposn.
Here is my select, but I do not know how to specify the last 2 fields as being concatenated into kmunv_kposn in my internal table.
SELECT hkwert hknumv h~kposn
INTO TABLE it_konv
FROM konv AS h
FOR ALL ENTRIES IN it_bil_sal
WHERE h~knumv = it_bil_sal-knumv
AND h~kposn = it_bil_sal-posnr.
Any help is much appreciated!
Thx,
AndyRight now, concatenating them is my solution to some other issue, so yea, I'd like to make it work this way, if possible.
That's a thought...I could do as you try. It just sucks that I can't do it in the select...it's so simple in ANSI SQL:
Select fielda || fieldb from...
Thanks alot for your help, Rob.
Andy -
SQL select query having more than 1000 values in 'IN' clause of predicate.
Hi,
We are executing a select query from a table and showing it through a front end screen. When the count of values given in the 'IN' clause of predicate are exceeding 1000 , it is throwing error.
eg. select * from Employees where emp.Id. in('111',123','121','3232',........1001 Ids)
We are using Oracle version 10.2.0.
Please suggest how to tackle such issue.
Regards,
Naveen Kumar.C.
Edited by: Naveen Kumar C on Aug 30, 2008 10:01 PMUse a nested table:
create or replace type numbertype
as object
(nr number(20,10) )
create or replace type number_table
as table of numbertype
create or replace procedure tableselect
( p_numbers in number_table
, p_ref_result out sys_refcursor)
is
begin
open p_ref_result for
select *
{noformat} from employees
, (select /*+ cardinality(tab 10) */ tab.nr
from table(p_numbers) tab) tbnrs
where id = tbnrs.nr;
end;
/{noformat}
Using nested tables will reduce the amount of parsing because the sql statement uses binded variables! The cardinality hint causes Oracle to use the index on employees.id. -
How to display data in a required format by SQL Select Query?
Hi,
i have a table named HR_PAYSLIP consisting of 4 columns empno, month, year, basic pay.
well i like to display the month wise basic salary
through a select query from the table
like this format;
EMPNO JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC
00094 122 153 145 224 245 545 114 544 444 111 555 222
00095 233 123 145 224 205 545 114 444 444 111 555 222
00096 163 123 145 224 215 545 114 551 444 111 555 222
00097 154 123 145 294 255 545 114 144 444 111 555 222
conditions:
where condition: where year = 2007
the employee no may be more and that must be displayed only one time like above for year,
and if the basic salary is zero for a month then it should be displayed as zero for a particular month as below
eg:
EMPNO, JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC
00094 122 153 0 224 245 545 114 544 444 111 555 222
Table Structure:
EMPNO NUMBER(10)
YEAR NUMBER(4)
MONTH NUMBER(2)
BASIC_PAY NUMBER(15)
Pls note: Month is stored in the table as 1 to 12.From the FAQ
{message:id=9360005} -
Need help for SQL SELECT query to fetch XML records from Oracle tables having CLOB field
Hello,
I have a scenario wherein i need to fetch records from several oracle tables having CLOB fields(which is holding XML) and then merge them logically to form a hierarchy XML. All these tables are related with PK-FK relationship. This XML hierarchy is having 'OP' as top-most root node and ‘DE’ as it’s bottom-most node with One-To-Many relationship. Hence, Each OP can have multiple GM, Each GM can have multiple DM and so on.
Table structures are mentioned below:
OP:
Name Null Type
OP_NBR NOT NULL NUMBER(4) (Primary Key)
OP_DESC VARCHAR2(50)
OP_PAYLOD_XML CLOB
GM:
Name Null Type
GM_NBR NOT NULL NUMBER(4) (Primary Key)
GM_DESC VARCHAR2(40)
OP_NBR NOT NULL NUMBER(4) (Foreign Key)
GM_PAYLOD_XML CLOB
DM:
Name Null Type
DM_NBR NOT NULL NUMBER(4) (Primary Key)
DM_DESC VARCHAR2(40)
GM_NBR NOT NULL NUMBER(4) (Foreign Key)
DM_PAYLOD_XML CLOB
DE:
Name Null Type
DE_NBR NOT NULL NUMBER(4) (Primary Key)
DE_DESC NOT NULL VARCHAR2(40)
DM_NBR NOT NULL NUMBER(4) (Foreign Key)
DE_PAYLOD_XML CLOB
+++++++++++++++++++++++++++++++++++++++++++++++++++++
SELECT
j.op_nbr||'||'||j.op_desc||'||'||j.op_paylod_xml AS op_paylod_xml,
i.gm_nbr||'||'||i.gm_desc||'||'||i.gm_paylod_xml AS gm_paylod_xml,
h.dm_nbr||'||'||h.dm_desc||'||'||h.dm_paylod_xml AS dm_paylod_xml,
g.de_nbr||'||'||g.de_desc||'||'||g.de_paylod_xml AS de_paylod_xml,
FROM
DE g, DM h, GM i, OP j
WHERE
h.dm_nbr = g.dm_nbr(+) and
i.gm_nbr = h.gm_nbr(+) and
j.op_nbr = i.op_nbr(+)
+++++++++++++++++++++++++++++++++++++++++++++++++++++
I am using above SQL select statement for fetching the XML records and this gives me all related xmls for each entity in a single record(OP, GM, DM. DE). Output of this SQL query is as below:
Current O/P:
<resultSet>
<Record1>
<OP_PAYLOD_XML1>
<GM_PAYLOD_XML1>
<DM_PAYLOD_XML1>
<DE_PAYLOD_XML1>
</Record1>
<Record2>
<OP_PAYLOD_XML2>
<GM_PAYLOD_XML2>
<DM_PAYLOD_XML2>
<DE_PAYLOD_XML2>
</Record2>
<RecordN>
<OP_PAYLOD_XMLN>
<GM_PAYLOD_XMLN>
<DM_PAYLOD_XMLN>
<DE_PAYLOD_XMLN>
</RecordN>
</resultSet>
Now i want to change my SQL query so that i get following output structure:
<resultSet>
<Record>
<OP_PAYLOD_XML1>
<GM_PAYLOD_XML1>
<GM_PAYLOD_XML2> .......
<GM_PAYLOD_XMLN>
<DM_PAYLOD_XML1>
<DM_PAYLOD_XML2> .......
<DM_PAYLOD_XMLN>
<DE_PAYLOD_XML1>
<DE_PAYLOD_XML2> .......
<DE_PAYLOD_XMLN>
</Record>
<Record>
<OP_PAYLOD_XML2>
<GM_PAYLOD_XML1'>
<GM_PAYLOD_XML2'> .......
<GM_PAYLOD_XMLN'>
<DM_PAYLOD_XML1'>
<DM_PAYLOD_XML2'> .......
<DM_PAYLOD_XMLN'>
<DE_PAYLOD_XML1'>
<DE_PAYLOD_XML2'> .......
<DE_PAYLOD_XMLN'>
</Record>
<resultSet>
Appreciate your help in this regard!Hi,
A few questions :
How's your first query supposed to give you an XML output like you show ?
Is there something you're not telling us?
What's the content of, for example, <OP_PAYLOD_XML1> ?
I don't think it's a good idea to embed the node level in the tag name, it would make much sense to expose that as an attribute.
What's the db version BTW? -
SQL SELECT Query Help ..Please its very Urgent!!
Hi All,
I am having Oracle Database whice is storing 1000's of records daily.
I need to select some information based on date and time.
I am having two coloumns for Date and time. The first column(testDate) of type Date stores date as MM/DD/YY format and the second column(testTime)of type Numeric stores the time in seconds.
The Example data is :
testDate ------=-- testTime
11/12/2002 --- 35000
11/12/2002 --- 43000
11/12/2002 --- 45000
11/12/2002 --- 75000
11/13/2002 --- 2000
11/13/2002 --- 3500
11/13/2002 --- 4300
11/13/2002 --- 9800
11/13/2002 --- 23000
11/14/2002 --- 5000
11/14/2002 --- 10000
11/14/2002 --- 15000
How can i write a SELECT Query to get the records of specific date and seconds to next day specific date and seconds.I mean i want all the records between 11/12/2002 --- 43000 seconds to 11/14/2002 --- 1000 seconds.
If any one helps me in this regard iam very thank full to them.Its very urgent for me.
ThanksHi m7nra,
I used the query as
SELECT * FROM table
WHERE testDate + (testTime/(24*60*60)) BETWEEN TO_DATE('MM/DD/YYYY','12.11.2002') AND TO_DATE('MM/DD/YYYY','14.11.2002')
its giving DATE FORMAT NOT RECOGNIZED error.
The Example data is :
testDate ------=-- testTime
11/12/2002 --- 35000
11/12/2002 --- 43000
11/12/2002 --- 45000
11/12/2002 --- 75000
11/13/2002 --- 2000
11/13/2002 --- 3500
11/13/2002 --- 4300
11/13/2002 --- 9800
11/13/2002 --- 23000
11/14/2002 --- 5000
11/14/2002 --- 10000
11/14/2002 --- 15000
infact i need all the records between 11/12/2002 --- 43000 seconds to 11/14/2002 --- 1000 seconds.
Please help me to find a full query beacuse iam very new to Oracle.
Thanks,
S R Mannava -
Splitting complex SQL select query in to independent sequence of small queries.
=====================
Problem Description
=====================
Consider I have the following table structures with approx no. of records in each.
Employee Table
emp_id:
name :
dept_id:
#Approx no. of rows in the table: 1 million
Department Table
dept_id:
dept_name:
#Approx no. of rows in the table: 1 Hundred
=====================
Target Result: is to get the employee name who's id is '100' and the department name he belongs to.
=====================
=====================
Ideal Query : Consider it as COMPLEX QUERY
=====================
select emp.name,dept.name
from employee emp, department dept
where
emp.dept_id = dept.dept_id
and
emp.emp_id = '100';
=====================
Optimized Independent Queries : Consider it as SIMPLE QUERIES
=====================
Now i want to split the above query in to two independent queries.
Query #1
select emp.name
from employee emp
where emp.id = '100';
:: Returns one row as emp.id is unique.
Query #2
select dept.dept_id, dept.name
from department dept
:: Returns 100 rows as there are only 100 rows.
=====================
Need Your Suggestions Here
=====================
If you compare the COMPLEX QUERY against SIMPLE QUERIES, i prefer to use SIMPLE QUERIES, get the results
and compare department id against two results programmatically and then get the final result. I know the database
query engines will do similar query optimization like dividing COMPLEX QUERY to SIMPLE QUERIES and run them
in some specific order to get results faster.
Now is it possible to get the exact sub queries which the database query engine (ANY database query engine) generates
out of complex select query? I mean i don't want to do the splitting manually but i still need those sub-queries.
Can any one help me out please?Why on earth would you want to keep the queries separate? As Tom Kyte would say, databases are born to join!
Providing emp_id has an index on it (and it should, assuming it's the table's primary key!) your "complex" (or, what I would call simple*), it'll most likely be faster than doing it separately. You've not got the context switches for one thing.
If you want to see what the optimizer does with your query, you should run a trace on the query. An explain plan would give you an idea of what it's going to do, too.
In general, doing something like this procedurally is going to almost certainly be worse than doing it in SQL (and by worse, I mean slower).
* I'd hate to see what you'd call some of the monster queries I work with, if you think that query is complex! -
How to execute SQL SELECT QUERY using VB in FDMEE
Hi Experts,
We are struggling with converting some of the FDM VB Scripts to FDMEE. While in FDM it was possible to simply create a RS Object, it doesnt seem to work in FDMEE. Can you please help me with some code samples that will help me execute SELECT Query and taking the output of the Query to Appropriate Variables.
Also it seems that the Accelerators in erstwhile FDM are no longer available in FDMEE. So we have to re-write our entire code all over again
ThanksThere are plenty of code examples in the FDMEE guide and al of the API methods are documented for both Visual Basic and Jython. Personally, I think, if you are having to re-factor your code because you have migrated from FDM to FDMEE I would look at doing it in Jython not the VB API. Jython is the scripting language that will be the mainstream choice going forward and athough the VB API is present to ease the move from FDM to FDMEE I wouldn't be sure how long it will be supported and you therefore may have to perform another code migration not too far down the line. Jython is a very powerful and easy to use if you spend a bit of time familiarizing yourself with the syntax and also opens up the opportunity to leverage the myriad of Java classes out there. Also all of your import scripts have to be in Jython with no VB alternative.
One other piece of advice is do not try and replicate allyour old code line for line. Look at what you were trying to achieve, assess whether it is still relevant or can it be faciliated by the new extended out of the box constructs and functionality FDMEE offers over classic FDM. -
Convert columns to rows by a select query
I have a table with 10 columns. Pk is combination of 3 columns, let us say A, B and C. I need a select query which returns 7 rows with four columns each let us say A,B,C and D where D contains the value of non PK column. i.e. for first row, D will contain value of fourth column of the table, for second row, D will contain fifth column of the table and so on.
Please help.Maybe NOT TESTED!
select col_a,col_b,col_c,column_4 col_d
from (select col_a,col_b,col_c,col_d,col_e,col_f,col_g,col_h,col_i,col_j
from the_table
unpivot include nulls (column_4 for source_column in (col_d as 'col_d',
col_e as 'col_e',
col_f as 'col_f',
col_g as 'col_g',
col_h as 'col_h',
col_i as 'col_i',
col_j as 'col_j'
)Regards
Etbin -
Hi friends ,
i have a table like
table ABC(
essay_id number(2),
line_id number(3),
line_t varchar2(100)
and here my table data goes..
essay_id line_id line_t
1 1 abc
1 2 def
1 3 ghi
2 1 klm
2 2 nop
here a single essay is stored as multiple lines in diff rows with same essay id and diff line id..
here i want to concatenate all the lines associated to same essay id..
for essay_id 1 ..output should be abcdefghi
for essay_id 2.. output should be klmnop
i did this with the help of cursor..
bt my question is ..
can we achieve this with a single select query...?
is it possible..
Please help me on this..
Thanks in advance
Regards,
JeyanthiWhat version of Oracle are you using?
Tim Hall has a page on the various string aggregation techniques that are available. The approaches that are available will depend heavily on the Oracle version.
Justin
Maybe you are looking for
-
Delivery Date with Zero Order Quantity in Sales Order
Dear All, I have created a sales order in va01 with different delivery date in schedule lines. I want to save delivery date with zero order quantity because he has not delivery on time.
-
Amex Delta Gold Skymiles card (need some advice/reassurance)
I applied for this card (has a $95 annual fee but waived the first year) on June 28, 2015 and immediately regretted doing so. I really didn't think it through and only did it because the week leading up to the 28th I was hanging out with my brother a
-
The FM "DD_DOMA_GET" not released for 'remote' calls.
Hi, When I try to import RFCs from my CRM system in XI, I am getting the following exception: com.sap.aii.ibrep.sbeans.upload.RemoteUploadException: The function module "DD_DOMA_GET" not released for 'remote' calls. Solution please!! Regards, Mahesh.
-
*Everything* disappeared from my sidebar except for my MacBook Pro icon, which is still showing under "Devices".
-
hello everyone I just bought a brandnew apple macbookpro 13" AND HAVE FOUND OUT THAT is a bit hard to figure everthing by yourself, have alredy the book mac for dummies, sincerely that will help otherwise I have to sell this laptop. I would to like k