List Oracle multiple rows into one w/o a primary key field.
I want to write the output of the below sql in a variable (varchar2 2000) inside a Oracle procedure. This could return multiple rows. How could I concatenate this into one -- so that I could always assign the o/p to the variable.
I do not see any primary key to LISTAGG on...
SELECT 'username: ' || s.username || ', osuser: ' || s.osuser || ', machine: ' || s.osuser || ', sid: ' || s.sid || ', serial#-program-terminal-sessinfo: ' || s.serial#||' '||s.program||'@'||s.terminal || ', blocking_session: ' || s.blocking_session || ', seconds_in_wait: ' || s.seconds_in_wait || ', sql_text: ' || l.sql_text FROM v$session s, v$sql l WHERE s.sql_id = l.sql_id(+) AND ((lower(l.sql_text) LIKE '%mytab1%') OR (lower(l.sql_text) LIKE '%mytab2%'));
Is sid the Primary key in v$session .. if it is.. then not sure if the attached sql could work.
Also is there any way to limit the o/p to less than 2000 character..?
SELECT NVL(substr(TRIM(session_info), 1, 1500), 'No CWV table session detected') INTO v_LockText FROM (SELECT one, LISTAGG(session_info, ';') WITHIN GROUP(ORDER BY one) as session_info FROM (SELECT '1' as one, 'username: ' || s.username || ', osuser: ' || s.osuser || ', machine: ' || s.osuser || ', sid: ' || s.sid || ', serial#-program-terminal-sessinfo: ' || s.serial# || ' ' || s.program || '@' || s.terminal || ', blocking_session: ' || s.blocking_session || ', seconds_in_wait: ' || s.seconds_in_wait || ', sql_text: ' || substr(TRIM(l.sql_text), 1, 200) session_info FROM v$session s, v$sql l WHERE s.sql_id = l.sql_id(+) AND ((upper(l.sql_text) LIKE '%mytab1%') OR (upper(l.sql_text) LIKE '%mytab2%'))) GROUP BY one);
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
Also is there any way to limit the o/p to less than 2000 character..?
Open in new window