Wm_concat or Listagg
Hi allI need a suggestion that one we should use wm_concat or listagg.
My db is 11g Standard Edition.
Please Guide!
Yes, that's wht which suggest to my blog...
Alexander gelin
http://nimishgarg.blogspot.com
Tags: Database
Similar Questions
-
Reg: WMSYS. WM_CONCAT or LISTAGG
All,
I'm trying to select column names that begin with "E" in my sql query projection area. For this I used USER_TAB_COLS with WMSYS. WM_CONCAT / LISTAGG too.
I got the names of columns, with separator ", but could not inject it to the sql query. Please help me.
SQL > SELECT WMSYS. WM_CONCAT (column_name)
2 FROM user_tab_cols
3 WHERE table_name = 'EMP '.
4 AND column_name LIKE '% E ';WMSYS. WM_CONCAT (COLUMN_NAME)
--------------------------------------------------------------------------------
EMPNO, ENAMESQL > SELECT
2. (SELECT WMSYS. WM_CONCAT (column_name)
3 FROM user_tab_cols
4 WHERE table_name = 'EMP '.
5 AND COLUMN_NAME LIKE '% E '.
(6) a
7 FROM EMP where rownum < = 4;A
--------------------------------------------------------------------------------
EMPNO, ENAME
ERROR:
ORA-22922: non-existent LOB value-LISTAGG
SQL > select (selection ListAgg (column_name, ',')
2 IN THE GROUP (ORDER BY COLUMN_NAME DESC) AS CONCATV
3 to user_tab_cols
4. WHERE TABLE_NAME = 'EMP '.
5 AND COLUMN_NAME LIKE '% E') a FROM EMP WHERE ROWNUM < = 3;A
----------------------------------------------------------------------------------------------------
ENAME, EMPNO
ENAME, EMPNO
ENAME, EMPNOThank you
Here is an example of what you want to do:
: c is of type cursor
declare
v varchar2 (4000);
Start
Select GROUP(ORDER BY COLUMN_NAME DESC) AS CONCATV ListAgg (column_name, ',')
v
of user_tab_cols
WHERE TABLE_NAME = 'MYTABLE ';
Open: c for 'select'. v. "from MYTABLE";
end;
----
Ramin Hashimzade
-
How can'i use wm_concat in ODI 10
Hello
I would like to know how to use the wm_concat function in an ODI interface (I use 10 ODI)
For example, I have the following source data
A B C
--- --- -------
20 5 SMITH
30 3 ALLEN
30 2 WARD
20 4 JONES
30 2 MARTIN
30 3 BLAKE
10 1 CLARK
20 3 SCOTT
10 3 KING
30 5 TURNER
20 2 ADAMS
30 5 JAMES
20 1 FORD
10 5 MILLER
and I want to insert the next data kes
A sum(B) wm_concat(c)
--- --- ------------------------
10 9 CLARK,KING,MILLER
20 15 SMITH,FORD,ADAMS,SCOTT,JONES
30 20 ALLEN,BLAKE,MARTIN,TURNER,JAMES,WARD
by adding a function of sum () in the column mapping B.
The following query generates the ODI
SELECT A, SUM (B), WM_CONCAT (C) FROM <table> GROUP BY A, WM_CONCAT (C);
This means that the ODI does not recognize WM_CONCAT as aggregate function.
don't you think that it is possible to say ODI to do not function in the group by
PS: I use an Oracle 11 g database 2 which recognizes the WM_CONCAT function.
Thank you very much
Hello
WM_Concat is no longer valid, that it has been deprecated by oracle, a long time ago.
Using the LISTAGG function instead... It should work in ODI...
SELECT deptno, LISTAGG (ename, ',') INTRA GROUP (ORDER BY ename) as employees
WCP
GROUP BY deptno;
DEPTNO EMPLOYEES
---------- --------------------------------------------------
10 CLARK, KING, MILLER
ADAMS, FORD, JONES 20, SCOTT, SMITH
ALLEN, JAMES, MARTIN, BLAKE, TURNER, WARD 30
If this solves your problem... close the thread...
Thank you
ASP.
-
without using the listagg function
Hi Sir,
Today my Bishop asked me to write a sql query to display comma separated values using listagg, sys_connect_by_path, wm_concat?
I said, we can write with the cursor... without predefined oracle functions? is this correct? or a Counselor about it?
Please help me
Concerning
AR
SQL > create table SEPM (deptno number (2), ename varchar2 (2));
Table created
SQL > insert all
2 in samp (deptno, ename) values (10, 'A')
3 in the SEPM (deptno, ename) values (20, 'd')
4 in the samp (deptno, ename) values (20, 'E')
5 SELECT * FROM DUAL;3 lines inserted
SQL > SELECT * FROM SAMP;
DEPTNO ENAME
------ -----
10A
20 D
20 ENeed to display like this
10A
20 D, E
-
lines due to the wm_concat() in double request gorge yourself
Here's the query I need to run
SELECT the separate user interface. Index_name, UI. Owner, UI. Table_name, wm_concat (uic.column_name) on column_name (partition by order of position_colonne uic.index_name), the ui.index_type, the parameters
Of
all_IND_COLUMNS UI all_INDEXES JOIN UIC
ON UIC. INDEX_NAME = UI. INDEX_NAME
where
SUBSTR (UI.index_name, 1, 3) not IN ("PK_", 'UQ_', ' DR$ ")
and ui.index_name not like 'SYS_C00% '.
and ui.index_name not like 'SYS_IOT_TOP_ %' and owner = 'USER1 '.
control of the user interface. INDEX_NAME
The problem is wm_concat() because the all_IND_COLUMNS table contains the entry duplicated for index (index1 of the table(column1,column2,column3) type)
for this wm_concat returns the result as below:
--------------------
Column1
Column1, Column2
Column1, Column2, Column3
But in * result I don't need it for a particular name of index (separate index)
as an example, I have two indexes in schema:
index1 on table1 (column1, column2, column3) and
Index2 on table2 (column5)
This result need
Row1 - index1 Column1, Column2, Column3
Index2 column 5 row2-
my query returns
index1 Column1 row1-
row2 - index1 Column1, Column2
row3 - index1 Column1, Column2, Column3
row4 - column 5 index2Are you trying this?
SELECT UI.INDEX_NAME, ui.owner , UI.TABLE_NAME , ui.index_type, parameters, listagg(column_name,',') within GROUP ( ORDER BY column_position) column_name FROM all_INDEXES UI JOIN all_IND_COLUMNS UIC ON ( UIC.INDEX_NAME = UI.INDEX_NAME and uic.index_owner = ui.owner) WHERE SUBSTR(ui.index_name,1,3) NOT IN ('PK_', 'UQ_','DR$') AND ui.index_name NOT LIKE 'SYS_C00%' AND ui.index_name NOT LIKE 'SYS_IOT_TOP_%' GROUP BY UI.INDEX_NAME, ui.owner , UI.TABLE_NAME , ui.index_type, parameters ORDER BY UI.INDEX_NAME;
-
am getting error error when am with funcation wm_concat.
Hi all
am getting error error when am with funcation wm_concat.
Thanks to all in advanceSQL> DECLARE 2 ex VARCHAR2(200); 3 BEGIN 4 SELECT wm_concat(ename) INTO EX FROM EMP WHERE deptno=30; 5 DBMS_OUTPUT.PUT_LINE(EX); 6 END; 7 8 . SQL> SQL> / DECLARE * ERROR at line 1: ORA-06550: line 4, column 10: PL/SQL: ORA-00904: "WM_CONCAT": invalid identifier ORA-06550: line 4, column 3: PL/SQL: SQL Statement ignored
Published by: Maldini on 9 January 2012 22:02Cool wrote:
HelloPlease check the version of database you are using.
wm_concat is available from 11 g Release 2.
Incorrect answer.
wm_concat is undocumented and should not be used.
Even Tom Kyte tell you... Re: SEPARATE does not not with wmsys.wm_concat
11 GR 2, there is a documented feature called LISTAGG...
http://docs.Oracle.com/CD/E11882_01/server.112/e26088/functions089.htm
-
WM_CONCAT() not available
Hello
I tried the below in Oracle 10 g XE.
In fact, my requirement is, I have a table named "table1" that has a column ID.
The values are:
I need the result form:1 2 3 4
I tried the query below:1,2,3,4
Two permits ORA-00904.select wm_concat(ID) from table1 select listagg(ID,',') from table1
Please help me to achieve this goal.
Thank youTry this-
SELECT rtrim(xmlagg(xmlelement(e,column_name,',').extract('//text()')),',') aa from TABLE_NAME;
-
Hello
Is it possible to put the values in the WM_CONCAT function:
Statement:
wm_concat (rental_next_date) rental_date,
Output:
25-FEB-11,25-OCT-12,25-APR-12,25-DEC-11,25-APR-11
The above dates is controllable by Crescent?
Thank yousliderrules wrote:
Thank you all for your comments. The listagg has no effect on the order of dates.That's because you ordered solely on the id. If you want to order on the dates, you will have to ask him.
-
How to get distinct records by using the ListAgg OBIEE report function?
Hi all
I get a correct result as mentioned below. But I don't see duplicates in my result here, in my example, I get duplicate for the name of the employee 'Pat '. So how to get Distinct values by using the LISTAGG function?
Data set of sample with the Department and its employees
Service employee
---------- ----------
Marketing Michael
Pat of marketing
Pat of marketing
Pat of marketing
Purchase of Den
Purchase of Alexander
Purchase of Shelli
Purchase of Sigal
Guy of purchase
Purchase of Karen
Using the ListAgg function, we can convert it to:
Employees of the Department
----------- -------------------------------------
Marketing of Pat, Pat, Pat, Michael
Purchase of Sigal, Shelli, Karen, Guy, Den, Alexander
I tried a lot of things, but I'm not able to understand how exactly this can be achieved, if anyone has any idea or suggestions please do share, thanks in advance.
After much research, I found the solution & I want to share what he finds very useful, we can create SQL logic in the Advanced tab, as below and after you click Rescan, and then you will get your desired results.
SELECT saw_0, Evaluate_Aggr T1.dept ("ListAgg(%1,'' & '') intra group (about 1%)") ("as long as VarChar (1000), T1.emp) saw_1 FROM)
SELECT 'emp_dept '. "the Department dept,
'emp_dept '. "' employee ' emp
IN THE "DOMAIN".
GROUP BY dept, emp
) T1 GROUP FROM T1.dept ORDER BY saw_0
Also note here that we have good anti-aliasing for columns parent (ex: saw_0, saw_1), another by mistake oracle bi server.
-
Oracle 11 g 2 Server
You need to remove from a call LISTAGG dups.
create table ptpos_explanations ( id number , fr_id number , part_type_id number , position_id number , ptpos_list varchar2(4000) ); insert into ptpos_explanations values(182527,100, 10,1,'It seems like it was replaced by part_type(s)/position(s):10/1 from content: 100'); insert into ptpos_explanations values(182527,100, 10,2,'It seems like it was replaced by part_type(s)/position(s):10/1 from content: 100'); insert into ptpos_explanations values(182527,110, 20,1,'It seems like it was replaced by part_type(s)/position(s):20/2 from content: 100'); insert into ptpos_explanations values(182527,110, 20,2,'It seems like it was replaced by part_type(s)/position(s):20/2 from content: 100'); commit; select * from ptpos_explanations; ID FR_ID PART_TYPE_ID POSITION_ID ---------- ---------- ------------ ----------- PTPOS_LIST ----------------------------------------------------------------------------------------------------------------------------- 182527 100 10 1 It seems like it was replaced by part_type(s)/position(s):10/1 from content: 100 182527 100 10 2 It seems like it was replaced by part_type(s)/position(s):10/1 from content: 100 182527 110 20 1 It seems like it was replaced by part_type(s)/position(s):20/2 from content: 100 182527 110 20 2 It seems like it was replaced by part_type(s)/position(s):20/2 from content: 100 4 rows selected.
Can I use LISTAGG on ptpos_list to refine the results.
SELECT id, part_type_id, LISTAGG(ptpos_list,', ') WITHIN GROUP(ORDER BY ptpos_list) recommendations FROM ptpos_explanations GROUP BY id, part_type_id ; ID PART_TYPE_ID ---------- ------------ RECOMMENDATIONS ----------------------------------------------------------------------------------------------------------------------------- 182527 10 It seems like it was replaced by part_type(s)/position(s):10/1 from content: 100, It seems like it was replaced by part_type( s)/position(s):10/1 from content: 100 182527 20 It seems like it was replaced by part_type(s)/position(s):20/2 from content: 100, It seems like it was replaced by part_type( s)/position(s):20/2 from content: 100
However, there are duplicates in the recommendations. I tried to wrap LISTAGG inside a REGEXP_REPLACE function, without much success.
Here the final result, so I'm looking for:
ID PART_TYPE_ID ---------- ------------ RECOMMENDATIONS --------------------------------------------------------------------------------- 182527 10 It seems like it was replaced by part_type(s)/position(s):10/1 from content: 100 182527 20 It seems like it was replaced by part_type(s)/position(s):20/2 from content: 100
EDIT: There are "n" lines for ptpos_list. So, we need to manage the many values of ptpos_list.
Hello
This is a feature annoying LISTAGG - you cannot use DIFFERENT with her.
A workaround is to to a separate GROUP BY, or SELECT DISTINCT simply get the unique values, then call LISTAGG on these unique results, like this:
WITH got_distinct_ptpos_list AS
(
SELECT id, part_type_id, ptpos_list
OF ptpos_explanations
GROUP BY id, part_type_id, ptpos_list
)
SELECT id, part_type_id
LISTAGG (ptpos_list, ',')
THE Group (ORDER BY ptpos_list) in the form of recommendations
OF got_distinct_ptpos_list
GROUP BY id, part_type_id
;
LISTAGG isn't the only way to get the desired results. See https://oracle-base.com/articles/misc/string-aggregation-techniques for other ways to string aggregation, including a user-defined aggregate function and SYS_CONNECT_BY_PATH.
REGEXP_REPLACE should work, too. What exactly have you tried? (However, it is probably more effective to get the unique results immediately the bat, rather than producing more than you want and then by doing something more to get rid of the duplicates).
-
Hi all
I have a sample of data and I have provided the scripts below.
create the table test_data
(deptcode varchar2 (10), hid number, number of applevel, approver_employee varchar2 (10))
Insert into test_data
values ('051 ', 1,1,'1487 ');
Insert into test_data
values ('051 ', 1,2,'8806 ');
Insert into test_data
values ('051 ', 1,3,'9038 ');
Insert into test_data
values ('051 ', 2,1,'5167 ');
Insert into test_data
values ('051 ', 2.2,'8806 ');
Insert into test_data
values ('051 ', 2,3,'9038 ');
Insert into test_data
values ('051 ', 3,1,'5375 ');
Insert into test_data
values ('051 ', 3.2,'8806 ');
Insert into test_data
values ('051 ', 3.3,'9038 ');
Insert into test_data
values ('051 ', 1,'4367 ');
Insert into test_data
values ('051 ', 4.2,'8806 ');
Insert into test_data
values ('051 ', 4.3,'9038 ');
but when I run the following query
Select deptcode, hidden, wm_concat (applevel) wm
of test_data
Deptcode, hidden group
hidden agenda
HIDDEN WM DEPTCODE
----------------------------
051 1 1,2,3
051 2 1,2,3
051 3 1,3,2
051 4 1,2,3
the third line should also be 1,2,3
I need result in the following format
hidden deptcode applevel
1 051 1,2,3
2 051 1,2,3
3 051 1,2,3
4 051 1,2,3
Please notify
WM_CONCATE is undocumented and do not use undocumented features. They may not be available in future versions, or they could change. And we do not know what exactly they intend to do.
Try this
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options SQL> select deptcode, hid, ltrim(sys_connect_by_path(applevel, ','), ',') applevel 2 from test_data 3 where connect_by_isleaf = 1 4 start with applevel = 1 5 connect by applevel = prior applevel + 1 6 and prior deptcode = deptcode 7 and prior hid = hid; DEPTCODE HID APPLEVEL ---------- ---------- ---------- 051 1 1,2,3 051 2 1,2,3 051 3 1,2,3 051 4 1,2,3
-
How can I get the nested case statements to work with listagg?
I have a statement below that does not work as I want it, here is my code:
Select
cases where o.personal_label is not null
then
listagg (cases where s.subcodevalue like '% MON %')
then s.subcodevalue |' '|| o.personal_label
of other s.subcodevalue
end,': ')
the Group (order of s.subcodevalue) as subcodevalue
on the other
listagg (s.subcodevalue,': ')
the Group (order of s.subcodevalue) as subcodevalue
end
of mtm_styles_new s, order_mtm o
where INSTR (o.extras, s.code) > 0
and o.bodyfitting = s.bodyfitting
and o.division = s.division
and s.subcodevalue is not null
and o.ORDER_MTMID = 'somevalue '.
It should bring the following
* MY TEST: RPP
or the following if the first case is not completed:
* MONDAY: RPP
I get an error message saying 'missing keyword', but cannot make out where, can someone please help me here?
The following works fine as long as it is not a nested case statement, but I need to nest the case statement:
Select listagg (cases where s.subcodevalue like '% MON %')
then s.subcodevalue |' '|| o.personal_label
of other s.subcodevalue
end,': ')
the Group (order of s.subcodevalue) as subcodevalue
of mtm_styles_new s, order_mtm o
where INSTR (o.extras, s.code) > 0
and o.bodyfitting = s.bodyfitting
and o.division = s.division
and s.subcodevalue is not null
and o.ORDER_MTMID = 'somevalue ';
Out alias 'subcodevalue as' the case at the end of the case body.
-
Listagg works does not in mview with fast refresh on commit?
Version Info:
Oracle Database 11 g Release 11.2.0.3.0 - 64 bit Production
PL/SQL Release 11.2.0.3.0 - Production
CORE Production 11.2.0.3.0
AMT for 64-bit Windows: Version 11.2.0.3.0 - Production
NLSRTL Version 11.2.0.3.0 - Production
I have a materialized view that is defined as fast refresh on validation and includes a call to listagg. The update goes as planned, but the value of the column that is created by using the listagg not updated unless I have make an explicit refresh. I was able to recreate the problem with a simple case, pasted below. Someone knows how to fix this?
Thank you!
-Tom
Test scenario follows...
SQL> create table codes ( 2 id number primary key, 3 product varchar2(10) not null, 4 code varchar2(10) not null); Table created. SQL> create materialized view log on codes with rowid, sequence (product, code) including new values; Materialized view log created. SQL> create materialized view code_agg_mv 2 refresh fast on commit 3 with rowid 4 as 5 select c.product 6 , listagg(c.code, ',') within group (order by c.code) codes 7 , count(*) cnt 8 from codes c 9 group by c.product; Materialized view created. SQL> truncate table mv_capabilities_table; Table truncated. SQL> begin 2 dbms_mview.explain_mview('CODE_AGG_MV'); 3 commit; 4 end; 5 / PL/SQL procedure successfully completed. SQL> select capability_name, possible 2 from mv_capabilities_table 3 where capability_name like '%REFRESH%' 4 order by capability_name; CAPABILITY_NAME P ------------------------------ - REFRESH_COMPLETE Y REFRESH_FAST Y REFRESH_FAST_AFTER_ANY_DML Y REFRESH_FAST_AFTER_INSERT Y REFRESH_FAST_AFTER_ONETAB_DML Y REFRESH_FAST_PCT N 6 rows selected. SQL> insert into codes (id, product, code) values (1, 'Pants', 'Large'); 1 row created. SQL> insert into codes (id, product, code) values (2, 'Pants', 'Blue'); 1 row created. SQL> insert into codes (id, product, code) values (3, 'Pants', 'Itchy'); 1 row created. SQL> commit; Commit complete. SQL> select * 2 from code_agg_mv; PRODUCT CODES CNT ---------- ------------------------------ ---------- Pants Blue,Itchy,Large 3 SQL> -- ^^^ This is correct ^^^ SQL> delete from codes where id = 3; 1 row deleted. SQL> commit; Commit complete. SQL> select * from code_agg_mv; PRODUCT CODES CNT ---------- ------------------------------ ---------- Pants Blue,Itchy,Large 2 SQL> -- ^^^ CNT is correct, but codes should not contain "Itchy" ^^^ SQL> -- SQL> -- Try an explicit fast refresh... SQL> begin 2 dbms_mview.refresh('CODE_AGG_MV', 'F'); 3 end; 4 / PL/SQL procedure successfully completed. SQL> select * from code_agg_mv; PRODUCT CODES CNT ---------- ------------------------------ ---------- Pants Blue,Itchy,Large 2 SQL> -- ^^^ Nope, same issue. ^^^ SQL> -- SQL> -- Try an explicit complete refresh... SQL> begin 2 dbms_mview.refresh('CODE_AGG_MV', 'C'); 3 end; 4 / PL/SQL procedure successfully completed. SQL> select * from code_agg_mv; PRODUCT CODES CNT ---------- ------------------------------ ---------- Pants Blue,Large 2 SQL> -- ^^^ There we go. ^^^
Message edited by Tom N to include database version information.
Hello Tom,
listagg() is not supported for fast refresh.
http://docs.Oracle.com/CD/E11882_01/server.112/e25554/basicmv.htm#i1007028
Only SUM, COUNT, AVG, STDDEV, VARIANCE, MIN and MAX are supported to fast refresh.
Kind regards
Pravin
-
Oracle 11 g 2
It is a check-in process. MY_TAB is the source table and MY_TAB_ARC is the check-in table. MY_TAB_ARC has two additional columns - dt_archived and remarks.
Currently, these columns are the last columns of the table of check-in, but there is no guarantee of this. Because you can add new columns in the source table in the future.
create table my_tab ( id number , list varchar2(50) ) / create table my_tab_arc ( id number , list varchar2(50) , dt_archived date , remarks varchar2(255) ) / insert into my_tab values(1,'abc') / insert into my_tab values(2,'xyz') / insert into my_tab values(3,'123') / commit; set serveroutput on declare v_query varchar2(4000); c_arc_cur integer ; v_tbl_arc varchar2(61) := 'my_tab_arc'; v_tbl_src varchar2(61) := 'my_tab'; v_columnOutput varchar2(4000); v_columnValue varchar2(4000); v_status integer; v_col_cnt number default 0; v_separator varchar2(3) := ''; v_insert varchar2(4000); v_colDesc dbms_sql.DESC_TAB; begin v_query := 'with data as ( select listagg(trgt.column_name,'','') within group (order by trgt.column_id) tab_columns from user_tab_cols src inner join user_tab_cols trgt on trgt.table_name = src.table_name'||'||''_ARC'''||' and src.column_name = trgt.column_name where src.table_name = ''MY_TAB'' and trgt.table_name = ''MY_TAB_ARC'' ) select d.* ' || ',sysdate,' || '''archived'' from data d' ; c_arc_cur := dbms_sql.open_cursor ; dbms_sql.parse( c_arc_cur, v_query, dbms_sql.native ); FOR i IN 1 .. v_col_cnt LOOP dbms_sql.define_column( c_arc_cur, i, v_columnValue, 4000 ) ; END LOOP ; v_status := dbms_sql.execute(c_arc_cur) ; dbms_sql.describe_columns(c_arc_cur,v_col_cnt, v_colDesc) ; FOR i IN 1..v_col_cnt LOOP v_columnOutput := v_columnOutput || v_separator || Upper(v_colDesc(i).col_name); v_separator := ',' || chr(10); END LOOP ; v_columnOutput := TRIM(leading ',' from v_columnOutput); v_insert := 'INSERT INTO ' || v_tbl_arc || ' SELECT ' ; v_insert := v_insert || v_columnOutput || chr(10) || ' FROM ' || v_tbl_src || ' WHERE content_id = :B1' ; dbms_sql.close_cursor(c_arc_cur); dbms_output.put_line(v_query); -- verify insert statement is correct dbms_output.put_line(v_insert); EXCEPTION when others then RAISE ; end ; / OUTPUT: with data as ( select listagg(trgt.column_name,',') within group (order by trgt.column_id) tab_columns from user_tab_cols src inner join user_tab_cols trgt on trgt.table_name = src.table_name||'_ARC' and src.column_name = trgt.column_name where src.table_name = 'MY_TAB' and trgt.table_name = 'MY_TAB_ARC' ) select d.* ,sysdate,'archived' from data d INSERT INTO my_tab_arc SELECT TAB_COLUMNS, SYSDATE, 'ARCHIVED' FROM my_tab WHERE content_id = :B1
The insert statement has the alias TAB_COLUMNS, not the real column names.
Am I missing something here? Or you cannot use LISTAGG in DBMS_SQL?
I say knock yourself out.
Dynamic SQL has its place.
I have it would probably become a procedure you want to call it.
Things that you can examine and possibly already have:
This does not cover a deletion, nor is there follow-up to what has or has not been archived.
Depending on the size, link in bulk and batch inserts may need to be worked in code similar to this one. (Yes, she gets more complicated)
Make sure you have no constraints on your table to archive. (unless you want to build in the error handling)
I have built in error management then it throws an exception when a column has not yet been added to the table to archive.
You can write code to add columns to your table to automatically archive, but I just wanted to show that what you want is possible.
You a little too much code, but you were close.
declare v_source_table varchar2(30) := 'MY_TAB'; v_id_to_archive number := 1; v_destination_table varchar2(30); v_verify_cols varchar2(4000); tab_columns varchar2(4000); v_sql clob; begin v_destination_table := v_source_table||'_ARC'; select listagg(src.column_name,',') within group (order by src.column_id) tab_columns into v_verify_cols from user_tab_cols src where not exists (select 1 from user_tab_cols trgt where trgt.table_name = src.table_name||'_ARC' and src.column_name = trgt.column_name) and table_name = v_source_table; if v_verify_cols is not null then raise_application_error(-20001,'Columns Missing In Archive Table: '||v_verify_cols); end if; select listagg(trgt.column_name,',') within group (order by trgt.column_id) into tab_columns from user_tab_cols src inner join user_tab_cols trgt on trgt.table_name = src.table_name||'_ARC' and src.column_name = trgt.column_name where src.table_name = v_source_table and trgt.table_name = v_destination_table and trgt.virtual_column = 'NO'; v_sql := 'insert into '||v_destination_table||' ('||tab_columns||',dt_archived,remarks) select '||tab_columns||',sysdate,''ARCHIVED'' from '||v_source_table||' where id = :id'; dbms_output.put_line(v_sql); execute immediate v_sql using v_id_to_archive; commit; end; /
PL/SQL procedure successfully completed.
insert into MY_TAB_ARC (ID, LIST, dt_archived, remarks)
SELECT ID, LIST, sysdate, 'ARCHIVED' from MY_TAB where id =: id
ID LIST DT_ARCHIVED REMARKS 1 ABC 2015-07-07 19:07:02 ARCHIVED Table deleted MY_TAB_ARC.
create table my_tab_arc ( id number , dt_archived date , remarks varchar2(255) );
Run the block again.
Error report-
ORA-20001: missing columns in Archive Table: LIST
ORA-06512: at line 20
-
Hello world
I have a problem with a complex regular expression, maybe I'm over complicating it.
Essentially, what I have is some interactions, interaction can go to several queues over time, what I need to achieve is when the queue of the item is listed as WORKBIN or OFFICE I want to find the queue that was before that. Things get complicated, because sometimes I have an example where he goes queue > QUEUE > WORKBIN > TAIL > DESKTOP >TAIL> WORKBIN I need to find the line in "BOLD".
What I tried was the LISTAGG a partition of interactions for a list as a QUEUE. QUEUE | WORKBIN | QUEUE | DESKTOP COMPUTER | QUEUE: WORKBIN can use REGEXP_INSTR to cut the chain out, but I can't seem to find the latest iteration of the expression.
Here is an example of the data:
queue of the date interaction_id
1037150 2015-01-20 18:35:57 HMB_SITEL_BASIC_IXNQ
1037150 2015-01-20 20:59:47 desktop_in_progress
1037150 2015-01-20 21:44:18 TFR_HMB_SITELBASIC_IXNQ
1037150 2015-01-21 07:54:30 desktop_in_progress
1037150 2015-01-21 07:56:40 NO
1037150 2015-01-21 07:56:40 desktop_in_progress
And the statement that I have tried:
UBSTR (SUBSTR ('|)) ' || LISTAGG (LAST_QUEUE_NAME, ' |') Group (order of AGENT_END_TS) on (INTERACTION_ID score) |' | ', 1, REGEXP_INSTR ('|) ' || LISTAGG(LAST_QUEUE_NAME, '|') Group (order of AGENT_END_TS) on (INTERACTION_ID score) |' | ((',' desktop_in_progress', 1-2), INSTR (SUBSTR ('|)) ' || LISTAGG (QUEUE_NAME, ' |') Group (order of AGENT_END_TS) on (INTERACTION_ID score) |' | ', 1, REGEXP_INSTR ('|) ' || LISTAGG(QUEUE_NAME, '|') Group (order of AGENT_END_TS) on (INTERACTION_ID score) |' | ((',' desktop_in_progress ', 1-2),' | (',-1) + 1, REGEXP_INSTR ('|) ' || LISTAGG(QUEUE_NAME, '|') Group (order of AGENT_END_TS) on (INTERACTION_ID score) |' | ((',' desktop_in_progress', 1-2)
Any help or suggestions appreciated
Thomas
Select min (rn) of
with
data in the form of
(select 1037150 interaction_id, to_date ('2015-01-20 18:35:57 ',' yyyy-mm-dd hh24:mi:ss') date_, 'HMB_SITEL_BASIC_IXNQ' queue_ of all the double union)
Select 1037150, to_date ('2015-01-20 20:59:47 ',' yyyy-mm-dd hh24:mi:ss'), 'desktop_in_progress' from dual union all
Select 1037150, to_date ('2015-01-20 21:44:18 ',' yyyy-mm-dd hh24:mi:ss'), 'TFR_HMB_SITELBASIC_IXNQ' from dual union all
Select 1037150, to_date ('2015-01-21 07:54:30 ',' yyyy-mm-dd hh24:mi:ss'), 'desktop_in_progress' from dual union all
Select 1037150, to_date ('2015-01-21 07:56:40 ',' yyyy-mm-dd hh24:mi:ss'), 'NONE' from dual union all
Select 1037150, to_date ('2015-01-21 07:56:40 ',' yyyy-mm-dd hh24:mi:ss'), 'desktop_in_progress' from dual
)
Select interaction_id, to_char (date_, 'yyyy-mm-dd hh24:mi:ss') date_, queue_,.
cases where instr (upper (queue_), 'WORKBENCH') = 0
and instr (upper (queue_), 'DESKTOP') = 0
and instr (upper (queue_), 'NONE') = 0
then row_number() over (partition by interaction_id by date_ desc order)
end RN
from the data
order of interaction_id, date_
INTERACTION_ID DATE_ QUEUE_ RN 1037150 2015-01-20 18:35:57 HMB_SITEL_BASIC_IXNQ 6 1037150 2015-01-20 20:59:47 desktop_in_progress - 1037150 2015-01-20 21:44:18 TFR_HMB_SITELBASIC_IXNQ 4 1037150 2015-01-21 07:54:30 desktop_in_progress - 1037150 2015-01-21 07:56:40 NONE - 1037150 2015-01-21 07:56:40 desktop_in_progress - Concerning
Etbin
Maybe you are looking for
-
How can I flag a message for follow up to the top
I have a message that says that something will happen on a specific date. I would like to flag the message for follow-up, I hope say TB is specific to the date to which I need to track. I know that Outlook flags. TB has something similar?
-
NSContacts - how to get a unified contact-related contacts?
Hello In my address book, I unified contacts for some people: -a card with personal data and is shared with my family with iCloud account -for the same person, one card is business oriented, with data company, on another account iCloud I'm developing
-
How to store data points in the table
I'm new to labview and I am trying to store the output of the frequency of 'measures pulsed VI' in a table, add everything together and divide by the length of the array. I don't want a table of numbers to be shown on the indicator. Just average 25 n
-
OfficeJet 8600: default 2 sides print officejet 8600
my firmware updated and now 2 copy/printing face is the default value. It's very disruptive! I do not use 2 sided. How can we change this stupid default setting the Single value to face impression
-
How can I get the correct codec?
I copied a music file & tried to paste in my movie in movie maker, but it says that I don't have the right codec on my computer & need to download a. I have Vista. Could you tell me where to find the correct codec? Thank you Gloria