Strange request: varchar2 as multiple rows..
Hi all.
I have a varchar2 field with a delimiter and want the output in multiple records based on the delimiter.
Ex: if the table name is XYZ and the data is as below
XYZ
field1~~~ field2~~~ field3
1~~~test1,test2,test3,test4~~~123123
2~~~test5,test6,test4~~~432423
the result need to be as follows...
field1~~~ field2~~~ field3
1~~~test1~~~123123
1~~~test2~~~123123
1~~~test3~~~123123
1~~~test4~~~123123
2~~~test5~~~432423
2~~~test6~~~432423
2~~~test4~~~432423
Appreciate any help.
Thanks NPR
Here's an implementation of a split function.
FUNCTION simple_split (
p_text IN VARCHAR2,
p_delimiter IN VARCHAR2 DEFAULT ',')
RETURN varchar2_array
IS
k_delim_len CONSTANT PLS_INTEGER := LENGTH (p_delimiter);
l_tokens varchar2_array := varchar2_array ();
l_text_to_split VARCHAR2 (32767);
l_delim_pos PLS_INTEGER;
BEGIN
l_tokens.DELETE;
l_text_to_split := p_text;
WHILE l_text_to_split IS NOT NULL
LOOP
l_delim_pos := INSTR (l_text_to_split, p_delimiter);
IF l_delim_pos > 0
THEN
l_tokens.EXTEND;
l_tokens (l_tokens.LAST) :=
SUBSTR (l_text_to_split, 1, l_delim_pos - 1);
l_text_to_split :=
SUBSTR (l_text_to_split, l_delim_pos + k_delim_len);
ELSE
l_tokens.EXTEND;
l_tokens (l_tokens.LAST) := l_text_to_split;
l_text_to_split := NULL;
END IF;
END LOOP;
RETURN l_tokens;
END simple_split;
Similar Messages
-
JClient - Strange Behaviour when using multiple-row-selection
Hi!
In my application a problem occures whenever I want to select multple rows in a JTable...
I am using a JTable bound to a ViewObject which displays quite a lot of rows. For further processing I need to select more than one row. So I changed the code the following way:
table.setModel(JUTableBinding.createAttributeListBinding(panelBinding, table, "SomeView", null, "SomeViewIter", new String[] {"FirstAttribute", "SecondAttribute"}));
table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
Basically there are 2 problems:
Whenever I want to select several rows or intervals by dragging the mouse or by using cursers, older selections disappear.
When I select rows and then use the scrollbar, all selections but one disappear.
Is there something wrong in my implementation or is this another bug? That's one of those little things, that make life of developers and end-users hard.
Any suggestions? Thanks a lot!Hi!
In my application a problem occures whenever I want to select multple rows in a JTable...
I am using a JTable bound to a ViewObject which displays quite a lot of rows. For further processing I need to select more than one row. So I changed the code the following way:
table.setModel(JUTableBinding.createAttributeListBinding(panelBinding, table, "SomeView", null, "SomeViewIter", new String[] {"FirstAttribute", "SecondAttribute"}));
table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);JUTableBinding only works with Single-selection model as it needs to track currency based on the current selection.
You'd have to implement a custom Table-model that wraps the built-in table model (quite like what's done in the 'table sorting example' at
http://otn.oracle.com/sample_code/products/jdev/jclient/jclient_table_sorting_sample.html
Then you may implement multiple selection and fake single selection model (last selected row perhaps) to the JUTableBinding's tableModel.
Basically there are 2 problems:
Whenever I want to select several rows or intervals by dragging the mouse or by using cursers, older selections disappear.
When I select rows and then use the scrollbar, all selections but one disappear.
Is there something wrong in my implementation or is this another bug? That's one of those little things, that make life of developers and end-users hard.
Any suggestions? Thanks a lot! -
Is there a way in Oracle to return multiple rows as a single string?
Hi gurus,
I just got help from your guys fixing my dynamic sql problem. What I am doing in that function is to return a single string from multiple rows and I use it in the select statement. It works fine once the problem was solved. But is there any way in Oracle to do this in the select statement only? I have a table that stores incidents (incident_id is the PK) and another table that stores the people that are involved in an incident.
Incident_table
(incident_id number PK);
Incident_people_table
(incident_id number PK/FK,
person_id number PK);
Now in a report, I need to return the multiple rows of the Incident_People_table as a single string separated by a comma, for example, 'Ben, John, Mark'. I asked the SQL Server DBA about this and he told me he can do that in SQL Server by using a variable in the sql statement and SQL Server will auomatically iterate the rows and concatenate the result (I have not seen his actual work). Is there a similar way in Oracle? I have seen some examples here for some similar requests using the sys_connect_by_path, but I wonder if it is feasible in a report sql that is already rather complex. Or should I just stick to my simpler funcion?
Thanks.
BenHi,
May be, this example will help you.
SQL> CREATE TABLE Incident_Table(
2 incident_id number
3 );
Table created.
SQL> CREATE TABLE Person_Table(
2 person_id number,
3 person_name VARCHAR2(200)
4 );
Table created.
SQL> CREATE TABLE Incident_People_Table(
2 incident_id number,
3 person_id number
4 );
Table created.
SQL> SELECT * FROM Incident_Table;
INCIDENT_ID
1
2
SQL> SELECT * FROM Person_Table;
PERSON_ID PERSON_NAME
1 John
2 Mark
3 Ben
4 Sam
SQL> SELECT * FROM Incident_People_Table;
INCIDENT_ID PERSON_ID
1 1
1 2
1 3
2 1
2 2
2 4
6 rows selected.
SQL> SELECT IT.*,
2 (
3 WITH People_Order AS (
4 SELECT IPT.incident_id, person_id, PT.person_name,
5 ROW_NUMBER() OVER (PARTITION BY IPT.incident_id ORDER BY PT.person_name) AS Order_Num,
6 COUNT(*) OVER (PARTITION BY IPT.incident_id) AS incident_people_cnt
7 FROM Incident_People_Table IPT
8 JOIN Person_Table PT USING(person_id)
9 )
10 SELECT SUBSTR(SYS_CONNECT_BY_PATH(PO.person_name, ', '), 3) AS incident_people_list
11 FROM (SELECT * FROM People_Order PO WHERE PO.incident_id = IT.incident_id) PO
12 WHERE PO.incident_people_cnt = LEVEL
13 START WITH PO.Order_Num = 1
14 CONNECT BY PRIOR PO.Order_Num = PO.Order_Num - 1
15 ) AS incident_people_list
16 FROM Incident_Table IT
17 ;
INCIDENT_ID INCIDENT_PEOPLE_LIST
1 Ben, John, Mark
2 John, Mark, SamRegards,
Dima -
2.1.0.62: Bug editing text columns in multiple rows using editor-window
Hello Forum,
I hope this is not a double post, but I did not come up with the right keywords to search for.
So here is the bug/strange annoying behavior:
When I edit multiple rows of a table using the extra edit-window, it shows the text of the previous row I edited and not the text of the actual row.
Well, sounds quit complicated so I'll give an example:
Suppose you have a table with two columns and two rows. One column is of type varchar2. Say it contains the values "one" and "two".
Now I click into the row containing "one", open the extra-edit-window and change the value to "one-1".
Then I click into the second row and also open the extra-edit-window. The window shows "one-1" instead of "two" as it should.
This is very annoying because I don't have autocommit activated and when I edit a couple of clob fields, the editor just shows the text of the previous field. I have to say commit for every row in order not to scramble the contents of multiple fields. I have to use the edit-window because the inplace editor is not very useful when editing large texts.
I observed this bug with varchar2 and clob fields but it may not be restricted to those.
I run Windows XP and conect to Oracle 10.2.0.4
Regards,
dhalekHello -K-,
setting "Post edits on row change" indeed does prevent this bug, but leads to another problem:
When I click the rollback-button, the table data is not reverted to its original state. In fact the changes are not commited, but rolling back, does not give the old data back. I can enter "rollback;" into the worksheet and then refresh the table data to show the old values but internally SQL Developer still thinks it has uncommitted changes in the table.
I, for now, uncheck "Post edits on row change" and use the inplace editor wherever possible. That has some strange cursor bugs (sometimes puts the cursor to the end making it impossible to enter text in the middle of the field) but that does not affect other rows.
Regards,
dhalek
Edited by: dhalek on 30.10.2009 15:08 -
Cursor fetch with multiple rows
I have been given code which, effectively, looks like this:
declare
cursor cTest is select * from (select 'one' from dual union all select 'two' from dual);
lvText varchar2(10);
begin
open cTest;
fetch cTest into lvText;
close cTest;
dbms_output.put_line(lvText);
end;
/That consistently returns just the result "one", even though there are two rows in the cursor.
If I re-write the code like this:
declare
lvText varchar2(10);
begin
select thecol into lvText from (select 'one' as thecol from dual union all select 'two' from dual);
dbms_output.put_line(lvText);
end;
/...then I get the error I expected (ORA-01422: exact fetch returns more than requested number of rows).
I guess I am a bit surprised the "fetch into" syntax (which I haven't used before) works at all. Why doesn't it spot that multiple rows are being loaded into a single variable and explode? I am guessing that which row 'wins' the competition to be assigned to the variable is completely indeterminate? Any doco on this behaviour you can point me at, please? The bit I read (http://docs.oracle.com/cd/B28359_01/appdev.111/b28370/fetch_statement.htm) simply says that "You must use either a cursor FOR loop or the FETCH statement to process a multiple-row query", but it doesn't say "the code will silent grab one of the rows at random if you use the FETCH statement on a multiple-row resultset".
(tested on 11.2.0.3, if it makes a difference)>
I realise FETCH fetches one row. The problem is that without a loop, doing so is 'wrong', logically. But it's still allowed, and I can't find anywhere in the doco that says "if you use FETCH, you MUST loop through the results, otherwise we will only return the first row, which will then probably be a bug in your code".
I'm asking for something from the doco (or from a website somewhere, maybe) that explains that "fetch without loops will work, but will be wrong". It's not something I expected, put it that way. It's something I would have thought others would have tripped over before now, anyway. In what I've read, like your code example here, you just see fetch-with-loops, with the unstated assumption made that you'd never do it any other way. I've not seen it explicitly said that it's possible to do it without a loop, but would be a dumb thing to do.
>
Oracle has no way to know what a developer is trying to do or how many rows a cursor will return.
It isn't necessarily true that "fetch without loops will work, but will be wrong". My cursor might only return one row.
What about a BULK COLLECT INTO without a LIMIT clause? Should Oracle tell you that if you query too many records you may run out of memory?
What about a BULK COLLECT INTO with a limit clause? Should Oracle tell you that "bulk collect with limit without a loop will work, but will be wrong"? It isn't necessarily wrong either. -
Multiple rows Converge to Single row and join
Hi Folks,
I am facing a tricky challenge to join a table with multiple rows and converge into a single row (based on ID, period) and join with another table to get a single row. Let me explain.
Table 1: DTL_TABLE (id, period, course, names, title, type)
1 2010 mat john null null
1 2010 mat jim null null
1 2010 cam null officer null
1 2010 cam null Prof null
1 2010 phy null null Inclass
1 2010 phy null null Online
Join with
Table 2: ID_TABLE(id, period, Loc, Dept, Code)
1 2010 nj 101 CC.
Output format (id, period, course, names, title, type, Loc, Dept, Code)
result : 1 2010 mat,cam,phy john,jim officer,prof inclass,online nj 101 CC
I have created all the DDLs and DMLs if that help. Kindly let me know if a Join SQL query is possible.
Thank you,
Aj
CREATE TABLE DTL_TABLE
ids VARCHAR2 (10),
period VARCHAR2 (10),
course VARCHAR2 (10),
names VARCHAR2 (10),
title VARCHAR2 (10),
TYPE VARCHAR2 (10)
INSERT INTO DTL_TABLE
VALUES ('1',
'2010',
'mat',
'jim',
NULL,
NULL);
INSERT INTO DTL_TABLE
VALUES ('1',
'2010',
'mat',
'john',
NULL,
NULL);
INSERT INTO DTL_TABLE
VALUES ('1',
'2010',
'mat',
'kale',
NULL,
NULL);
INSERT INTO DTL_TABLE
VALUES ('1',
'2010',
'cam',
NULL,
'officer',
NULL);
INSERT INTO DTL_TABLE
VALUES ('1',
'2010',
'cam',
NULL,
'prof',
NULL);
INSERT INTO DTL_TABLE
VALUES ('1',
'2010',
'phy',
NULL,
NULL,
'inclass');
INSERT INTO DTL_TABLE
VALUES ('1',
'2010',
'phy',
NULL,
NULL,
'online');
COMMIT;
CREATE TABLE id_table
ids VARCHAR2 (10),
period VARCHAR2 (10),
loc VARCHAR2 (10),
dept VARCHAR2 (10),
code VARCHAR2 (10)
INSERT INTO id_table
VALUES ('1',
'2010',
'nj',
'101',
'cc');
COMMIT;Aj09 wrote:
Hi Folks,
I am facing a tricky challenge to join a table with multiple rows and converge into a single row (based on ID, period) and join with another table to get a single row. Let me explain.
Table 1: DTL_TABLE (id, period, course, names, title, type)
1 2010 mat john null null
1 2010 mat jim null null
1 2010 cam null officer null
1 2010 cam null Prof null
1 2010 phy null null Inclass
1 2010 phy null null Online
Join with
Table 2: ID_TABLE(id, period, Loc, Dept, Code)
1 2010 nj 101 CC.
Output format (id, period, course, names, title, type, Loc, Dept, Code)
result : 1 2010 mat,cam,phy john,jim officer,prof inclass,online nj 101 CC
I have created all the DDLs and DMLs if that help. Kindly let me know if a Join SQL query is possible.
SELECT TBL.id,
DTLperiod,
course,
names,
title,
TYPE,
Loc,
Dept,
Code
FROM ID_TABLE TBL,
DTL_TABLE DTL
WHERE TBL.ID = DTL.ID
AND TBL.PERIOD = DTL.PERIOD; it not good to use RESERVED WORDS like "ID" or "TYPE" as column names -
How to create a function that returns multiple rows in table
Dear all,
I want to create a funtion that returns multiple rows from the table (ex: gl_balances). I done following:
-- Create type (successfull)
Create or replace type tp_gl_balance as Object
PERIOD_NAME VARCHAR2(15),
CURRENCY_CODE VARCHAR2(15),
PERIOD_TYPE VARCHAR2(15),
PERIOD_YEAR NUMBER(15),
BEGIN_BALANCE_DR NUMBER,
BEGIN_BALANCE_CR NUMBER
-- successfull
create type tp_tbl_gl_balance as table of tp_gl_balance;
but i create a function for return some rows from gl_balances, i can't compile it
create or replace function f_gl_balance(p_period varchar2) return tp_tbl_gl_balance pipelined
as
begin
return
(select gb.period_name, gb.currency_code, gb.period_type, gb.period_year, gb.begin_balance_dr, gb.begin_balance_cr
from gl_balances gb
where gb.period_name = p_period);
end;
I also try
create or replace function f_gl_balance(p_period varchar2) return tp_tbl_gl_balance pipelined
as
begin
select gb.period_name, gb.currency_code, gb.period_type, gb.period_year, gb.begin_balance_dr, gb.begin_balance_cr
from gl_balances gb
where gb.period_name = p_period;
return;
end;
Please help me solve this function.
thanks and best reguardhi,
Use TABLE FUNCTIONS,
[http://www.oracle-base.com/articles/9i/PipelinedTableFunctions9i.php]
Regards,
Danish -
Depicting multiple rows' data in one row
Hi All,
Pls. check the below query:
select manager_id mg_id, employee_id emp_id, last_name name from employees
where manager_id = '100'
and DEPARTMENT_ID = '80'if i run the following query, then o/p comes row wise; like below:
mg_id emp_id name
100 145 Russell
100 146 Partners
100 147 Errazuriz
100 148 Cambrault
100 149 Zlotkeybut if i want the o/p like below; i.e; under manager # 100, all employees' emp_id and name should come in only ONE row NOT in multiple rows:
mg_id emp_id name emp_id name emp_id name emp_id name emp_id name
100 145 Russell 146 Partners 147 Errazuriz 148 Cambrault 149 Zlotkeypls. help me to sort out the above sought o/p.
kindly tell me if there is any posting guidelines (except "Plain Text Help" on the right side) in this forum. i tried a lot to post above two o/p in easily readable format, but couldn't do that.
Edited by: Shariful on Sep 20, 2009 4:28 AM
Edited by: Shariful on Sep 20, 2009 4:29 AMHi,
Shariful wrote:
Hi All,
Pls. check the below query:
select manager_id mg_id, employee_id emp_id, last_name name from employees
where manager_id = '100'
and DEPARTMENT_ID = '80'
if i run the following query, then o/p comes row wise; like below:
mg_id emp_id name
100 145 Russell
100 146 Partners
100 147 Errazuriz
100 148 Cambrault
100 149 Zlotkey
but if i want the o/p like below; i.e; under manager # 100, all employees' emp_id and name should come in only ONE row NOT in multiple rows:
mg_id emp_id name emp_id name emp_id name emp_id name emp_id name
100 145 Russell 146 Partners 147 Errazuriz 148 Cambrault 149 ZlotkeyIf you want all the emp_ids and names concatenated into one big VARCHAR2 column, that's called String Aggregation
[AskTom.oracle.com|http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:2196162600402] shows several different ways to do it.
You can format that one big column so that it looks like separate columns.
If you want each emp_id and name in its own column, that's called Pivoting .
Look up "pivot" for various techniques. If you do not know exactly how many rows were in the original query (and therefore how many columns you'll need in the output), then it will require Dynamic SQL , which can be complicated.
Unfortunately, when you do search for "pivot", mlost of the hits will be things like "Search for pivot and you'll get lots of examples".
Re: Help for a query to add columns is one that actually has some information. It was a question very much like yours.
kindly tell me if there is any posting guidelines (except "Plain Text Help" on the right side) in this forum. i tried a lot to post above two o/p and query in easily readable format, but couldn't do that.Type these 6 characters:
(small letters only, inside curly brackets) before and after formatted text, to preserve spacing. -
Collecting data from multiple rows into one column
I'd like to run a query and put a collection of items into one output column instead of multiple rows. See the example below:
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - Prod
PL/SQL Release 10.2.0.5.0 - Production
"CORE 10.2.0.5.0 Production"
TNS for 32-bit Windows: Version 10.2.0.5.0 - Production
NLSRTL Version 10.2.0.5.0 - Production
CREATE TABLE "SKIP"."INGREDIENTS"
( "INGRED_ID" NUMBER,
"INGRED_NAME" VARCHAR2(20 BYTE),
"STORES" VARCHAR2(20 BYTE)
) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "USERS" ;
REM INSERTING into SKIP.INGREDIENTS
Insert into SKIP.INGREDIENTS (INGRED_ID,INGRED_NAME,STORES) values (1,'SEA SALT','Food lion');
Insert into SKIP.INGREDIENTS (INGRED_ID,INGRED_NAME,STORES) values (2,'TABLE SALT','Food lion');
Insert into SKIP.INGREDIENTS (INGRED_ID,INGRED_NAME,STORES) values (3,'FLOUR','Piggly Wiggly');
Insert into SKIP.INGREDIENTS (INGRED_ID,INGRED_NAME,STORES) values (4,'YEAST',null);
Insert into SKIP.INGREDIENTS (INGRED_ID,INGRED_NAME,STORES) values (5,'BEER','ABC Store');
CREATE TABLE "SKIP"."PRETZELS"
( "PRETZEL_ID" NUMBER,
"PRETZEL_NAME" VARCHAR2(20 BYTE),
"PRETZEL_DESC" VARCHAR2(100 BYTE)
) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "USERS" ;
REM INSERTING into SKIP.PRETZELS
Insert into SKIP.PRETZELS (PRETZEL_ID,PRETZEL_NAME,PRETZEL_DESC) values (1,'CLASSIC','Classic knot pretzel');
Insert into SKIP.PRETZELS (PRETZEL_ID,PRETZEL_NAME,PRETZEL_DESC) values (2,'THICK STICK','Straight pretzel, abt 1/2" in dia');
CREATE TABLE "SKIP"."INGRED_XREF"
( "PRETZEL_ID" NUMBER,
"INGRED_ID" NUMBER
) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "USERS" ;
REM INSERTING into SKIP.INGRED_XREF
Insert into SKIP.INGRED_XREF (PRETZEL_ID,INGRED_ID) values (1,1);
Insert into SKIP.INGRED_XREF (PRETZEL_ID,INGRED_ID) values (1,2);
Insert into SKIP.INGRED_XREF (PRETZEL_ID,INGRED_ID) values (1,4);
Insert into SKIP.INGRED_XREF (PRETZEL_ID,INGRED_ID) values (2,2);
Insert into SKIP.INGRED_XREF (PRETZEL_ID,INGRED_ID) values (2,3);
Insert into SKIP.INGRED_XREF (PRETZEL_ID,INGRED_ID) values (2,5);
-- Constraints for Table INGRED_XREF
ALTER TABLE "SKIP"."INGRED_XREF" MODIFY ("PRETZEL_ID" NOT NULL ENABLE);
ALTER TABLE "SKIP"."INGRED_XREF" MODIFY ("INGRED_ID" NOT NULL ENABLE);
{code}
Desired output (note how the ingredients are all listed in one column, separated by commas):
{code}
PRETZEL_ID PRETZEL_NAME PRETZEL_DESC INGREDIENTS
1 CLASSIC Classic knot pretzel SEA SALT, TABLE SALT, YEAST
2 THICK STICK Straight pretzel, abt 1/2" in dia TABLE_SALT, FLOUR, BEERSee the FAQ : {message:id=9360005}
Especially links concerning string aggregation. -
Retruring Multiple rows from a Stored Procedure
The Oracle JDBC documentation shows how to return a cursor pointer through the parameter list of a stored procedure allowing a Java program to use the cursor like a normal result set. I've tried it (using the thin driver) and it works fine - however, I'm having trouble getting this to work running the program under a Weblogic server (using their own JDBC implementation). So, I have two questions:
1) Has anyone had this problem before and solved it ??
2) Are there any other techniques for getting multiple rows back from the database without having to fire "raw" sql at it ?Hi
You could return not resultset but array, for example:
PACKAGE TEST:
type string_table is table of varchar2(80)
index by binary_integer;
function get_something (
something1 out string_table,
arraylength in number
) return number;
PACKAGE'S BODY:
function get_something (
something1 out string_table,
arraylength in number /** length of the array **/
) return number as
cursor C is
select something1, ...
from test_table;
pos number := 1;
begin
for position in C loop
exit when (pos > arraylength);
something1(pos) := position.something1;
pos := pos + 1;
end loop;
return (pos - 1);
end;
Of course in this example you need to know length of your array
(arraylength parameter), but you can avoid such problem, for
example, by using DBMS_SQL package (or dynamic SQL feature in
the Oracle8i).
Andrew
Mladen Gogala (guest) wrote:
: Phil Hildebrand (guest) wrote:
: : Is there a way that I can return multiple rows from a stored
: : procedure for function ?
: : Something like:
: : CREATE FUNCTION sp_get_children (my_nip IN port.nip_num%
TYPE)
: : RETURN my_nip
: : IS
: : CURSOR child_cur IS
: : SELECT nip_num
: : FROM logical_port
: : WHERE port_num = my_nip;
: : child_rec child_cur%rowtype;
: : BEGIN
: : FOR child_rec IN child_cur
: : LOOP
: : RETURN my_nip;
: : END LOOP;
: : END tmp_sp_get_children;
: : I know how to do it in Informix ( RETURN WITH RESUME ), but
: I'm
: : not running Informix ;)
: : Thanks,
: : Phil
: In contrast with Informix, SQL Server and Sybase, Oracle
: can not return a result set. the only workaround is to
: return the cursor variable as such.
null -
I wanted to display the multiple rows in one row but column should be diff
Hi
Could any body help me regarding this query how to write to get the multiple rows in one row.
eg.
i have one table tab1(eno number,ename varchar2,uid1 varchar2,uid2 varchar2,uid3 varchar4)
but when i am runing the query I am getting multiple record against one eno number because of uid1,uid2,uid3
suppose value of table is
eno ename uid1 uid2 uid3
1 a u1
1 a u2
1 a u3
when i am quering it is coming same as above but I want in one row
eno ename uid1 uid2 uid3
1 a u1 u2 u3
can any onle help me how to write the query for this requirement.
thanks
saifwhich is hard coded in my code? Here another approach, but fail for c as there is no information for the value of a column: does 1 in u1 means col 1, etc.
/* Formatted on 2012/05/29 16:29 (Formatter Plus v4.8.8) */
WITH t AS
(SELECT 1 col1, 'a' col2, 'u1' col3
FROM DUAL
UNION ALL
SELECT 1 col1, 'a' col2, 'u2' col3
FROM DUAL
UNION ALL
SELECT 1 col1, 'a' col2, 'u3' col3
FROM DUAL
UNION ALL
SELECT 1 col1, 'b' col2, 'u1' col3
FROM DUAL
UNION ALL
SELECT 1 col1, 'b' col2, 'u3' col3
FROM DUAL
UNION ALL
SELECT 1 col1, 'b' col2, 'u2' col3
FROM DUAL
UNION ALL
SELECT 1 col1, 'c' col2, 'u1' col3
FROM DUAL
UNION ALL
SELECT 1 col1, 'c' col2, 'u3' col3
FROM DUAL)
SELECT xx.col1, xx.col2, MAX (DECODE (xx.rn, 1, col3)) AS uid1, MAX (DECODE (xx.rn, 2, col3)) AS uid2,
MAX (DECODE (xx.rn, 3, col3)) AS uid3
FROM (SELECT t.col1, t.col2, t.col3, ROW_NUMBER () OVER (PARTITION BY col1, col2 ORDER BY col3) rn
FROM t) xx
GROUP BY col1, col2;output:
COL1 COL2 UID1 UID2 UID3
1 a u1 u2 u3
1 b u1 u2 u3
1 c u1 u3
Edited by: ʃʃp on May 29, 2012 2:30 AM -
How can i use multiple row subquery in update statement
Hai All
I using group function in my update statement.. and i need to update more rows so i need to use multiple row
subquery pls tell me how to use multiple row subquery in update statement
For example
while i am using this like this i got an error
update dail_att set outtime in (select max(r2.ptime) from temp_att where empcode=r2.enpno and
barcode=r2.cardn and attend_date=r2.pdate group by enpno,pdate,cardn);
Pls tell me how to use with example
Thanks & regards
Srikkanth.MHai Man
Thanks for ur response Let me clear what i need
First step Fetch the records as text file and stores into table T1
and the next step is i have seperated the text using substring and stores in different columns of a table
There are two shifts 0815 to 1645 and 1200 and 2000
Here I rep IN and O rep OUT
Empno date time inout
001 01-01-10 0815 I
002 01-01-10 0815 I
003 01-01-10 0818 I
001 01-01-10 1100 0
001 01-01-10 1130 I
002 01-01-10 1145 0
002 01-01-10 1215 I
004 01-01-10 1200 I
005 01-01-10 1215 I
004 01-01-10 1315 O
004 01-01-10 1345 I
001 01-01-10 1645 0
002 01-01-10 1715 0
003 01-01-10 1718 0
004 01-01-10 2010 0
005 01-01-10 2015 0
This is my T1 table i have taken data from text file and stored in this table from this table i need to move data to another table T2
T2 contains like this
Empno Intime Intrin Introut Outtime Date
001 0815 1100 1130 1645 01-01-10
002 0815 1145 1215 1715 01-01-10
003 0818 1718 01-01-10
004 1200 1315 1345 2010 01-01-10
005 1215 2015 01-01-10
This what i am trying to do man but i have little bit problems Pls give some solution with good example
And my coding is
declare
emp_code varchar2(25);
in_time varchar2(25);
out_time varchar2(25);
Cursor P1 is
Select REASON,ECODE,READMODE,EMPD,ENPNO,FILL,PDATE,PTIME,INOUT,CARDN,READERN
From temp_att
group by REASON,ECODE,READMODE,EMPD,ENPNO,FILL,PDATE,PTIME,INOUT,CARDN,READERN
ORDER BY enpno,pdate,ptime;
begin
for r2 in p1 loop
declare
bar_code varchar2(25);
begin
select barcode into bar_code from dail_att where empcode=r2.enpno and attend_date=r2.pdate;
For r3 in (select empcode,empname,barcode,intime,intrin,introut,addin,addout,outtime,attend_date from dail_att)loop
if r2.inout ='O' then
update dail_att set outtime =(select max(r2.ptime) from temp_att where empcode=r2.enpno and barcode=r2.cardn and attend_date=r2.pdate group by r2.cardn,r2.enpno,r2.pdate );
end if;
end loop;
exception
when no_data_found then
if r2.inout ='I' then
insert into dail_att(barcode,empcode,intime,attend_date)(select r2.cardn,r2.enpno,min(r2.ptime),r2.pdate from temp_att group by r2.cardn,r2.enpno,r2.pdate );
end if;
end;
end loop;
commit;
end;
Pls tell me what correction i need to do i the update statement i have used a subquery with group function but when i used it will return only one row but my need is to return many rows and i need to use multiple row subquery
and how can i use it in the update statement
Thanks In Advance
Srikkanth.M -
Multiple rows in post parameters
I am using the XSQL servlet programmatically. The xsql page being processed attempts to include the request parameters using the tag <xsql:include-request-params />.
I have found that when I pass in a dictionary of parameters with multiple values for a particular key (multiple row edit on the same page) I get the error detailed below. This, obviously, also occurs if you call XSQUtil.DictionaryOfParamsAsXMLDocument directly. However having multiple values works fine when using the XSQL Servlet on its own - a row tag is created for each record/row of multiple values.
Is this an oversight in the XSQLUtil and XSQLHttpUtil classes?
I think my only way forward is to write an action handler that retrieves the request parameters as XML and divides multiple values into rows. Is this correct?
How does the XSQL Servlet handle the case where there are a varied number of duplicate values?
[Ljava.lang.String;java.lang.ClassCastException: [Ljava.lang.String;
oracle.xml.parser.v2.XMLDocument oracle.xml.xsql.XSQLUtil.DictionaryOfParamsAsXMLDocument(java.util.Dictionary)
XSQLUtil.java:185
org.w3c.dom.Document oracle.xml.xsql.XSQLPageRequestImpl.getRequestParamsAsXMLDocument()
XSQLPageRequestImpl.java:217
void oracle.xml.xsql.actions.XSQLIncludeRequestHandler.handleAction(org.w3c.dom.Node)
XSQLIncludeRequestHandler.java:39
org.w3c.dom.Document oracle.xml.xsql.XSQLDocHandler.getDocument()
XSQLDocHandler.java:145
void oracle.xml.xsql.XSQLPageProcessor.process()
XSQLPageProcessor.java:146
void oracle.xml.xsql.XSQLRequest.process()
XSQLRequest.java:321
void oracle.xml.xsql.XSQLRequest.process(java.util.Dictionary, java.io.PrintWriter, java.io.PrintWriter)
XSQLRequest.java:216
You're running into Bug# 2440949. The XSQL Servlet uses different implementations to render the results of the request parameters based on the environment that it's running in. If you use the XSQLRequest class, it's got a bug where it's not handling the Array-valued parameters in a programmatic request correctly.
The bug's been fixed for the 10i version of the XSQL Servlet (current OTN XDK version is 9.2.0.2), but the only workaround in the interim is either to have your servlet forward the request to the XSQL Servlet using the request dispatcher object's forward() method, or to pass parameters with simple string values (and not array's of strings). -
Store Multiple rows in a dictionary to show as a grid
Hi,
I need to store multiple rows in a data dictionary.
Please give me the solution if the CCP has these feature to store multiple row data.
Please provide the guide if this is limitation in CCPI also have this problem. I have one form defined normally (e.g. server) and a second form defined as a grid (e.g. disks). My problem is when defining the plan, I can create a service item for the server but can't create one for the disk. How do I get the data from a grid form over to CPO? The design guide was quite vague on that point.
I thought also doing it as a bundle might work but that would in theory launch multiple different CPO processes which is not what I want. I would like all data from each from to be sent in a single request to the CPO process.
How do I do this?
Is it down to the type of adapter settings?
Actually, I've just answered my own question and now my adaptor is sending all the data but I would still like to know if I should be creating service items for those grid forms?
Ryan -
RFC XI JDBC to external database.... Get data in multiple rows
Hi,
We have been really struggling with this scenario. We have created a RFC that has 1 Import parameter (Order_ID) and table parameter (3 Columns: Order_ID, Partner_type, Partner_no).
When we call this RFC in SAP, it should make a connection to external database via JDBC and get multiple row data for every Order_ID. We are not using Oracle Stored Procedure, instead we are using simple Select statement. Did all the mapping and configured correctly. However, we are getting short-dump when we execute RFC. When we checked in XI, it says " Check xml instance is valid for source xsd and target-field mapping fulfills requirements of target xsd at "
Has anyone tried getting multiple row information from external database(Oracle) using Select statement in XI ? IF so, can you pl let us know if we need to something different in Mapping ?
NiranjanNiranjan,
Check this blog of mine to see how the datatype for Synchronous Select should be constructed,
https://weblogs.sdn.sap.com/pub/wlg/3928. [original link is broken] [original link is broken] [original link is broken] [original link is broken]
If this looks good, a few checks
1. Check the request inbound payload , i.e the RFC request in MONI. Is this as expected?
2. Check the output of the request mapping and check if this is as expected.
3. Check the response from JDBC, is this as per the datatype defined.
4. Check the mapping from JDBC response to RFC response.
To me this looks like an issue with the JDBC response structure.
Meanwhile to understand how to test mapping, check blog of michal,
/people/michal.krawczyk2/blog/2005/09/16/xi-how-to-test-your-mapping-in-real-life-scenarios
Regards
Bhavesh
Maybe you are looking for
-
Java or HTML to open PDF in a new window in Adobe Reader, not IE
Good morning, We have an interactive PDF document that has Flash built in. We sized to match the screen settings within our company. However, the way we have it posted, when a user clicks the link to open the PDF document, it opens inside of Interne
-
Will Airport Extreme Network with Panasonic Viera TC-P50ST30
Will Airport Extreme Network work properly with Panasonic Viera TC-P50ST30 HDTV?
-
Running mplayer at boot with systemctl. fails with alsa-lib error
I am running Arch ARM on a raspberry pi and would like to use it as a headless music player. I am trying to run mplayer in slave mode at start up and have in read from a fifo pipe which I could write to over SSH. I have written this mplayer.service f
-
I just purchased a ringtone and now it's not in my recent purchases
I just purchased a ringtone and now it's not in my recent purchases.
-
How to create New Stationery in Mail 3.5?
I've recently updated to 10.5.6, and in the new Mail there is a provision for using stationery. Does anyone know where the stationery files are stored? I'm interested in creating my own layouts and including them with the templates provided. Any idea