SQL & PL/SQL :: Concatenation On Columns

Feb 23, 2012

I have problem with query ( i'll only use DUAL table for example):

SELECT T.DUMMY P1,
T.DUMMY P2,
T.DUMMY C1,
T.DUMMY C2,
T.DUMMY C3,
T.DUMMY C4,
T.DUMMY C5
FROM DUAL T;

I need to concatenate only columns with name starting with C and add separator between them. Is there any function do concatenate columns using separator like:

SELECT T.DUMMY P1,
T.DUMMY P2,
DBMS_SOMETHING.SOME_FUNCTION(',', C1,C2,C3,C4,C5)
FROM DUAL T;

Or I must do like this:

SELECT T.DUMMY P1,
T.DUMMY P2,
C1 || ',' || C2 || ',' || C3 || ',' || C4 || ',' || C5
FROM DUAL T;

problem is that I have 3.000+ columns in 23 different selects :/

View 3 Replies


ADVERTISEMENT

PL/SQL :: How To Do String Concatenation

Nov 22, 2012

I am trying
  
IF LENGTH(v_final_string) < 3800 THEN
        SELECT nvl2(v_final_string,v_final_string
          ||',' ,v_final_string)
          || temp.temp_string
        INTO v_final_string
        FROM DUAL;
        DBMS_OUTPUT.put_line ('v_final_string=' || v_final_string );
      ELSE
        EXIT;
      END IF;inside a loop.

But it's not concatenating. I am alwas getting empty v_final_string

View 9 Replies View Related

Recursion - Concatenation On Database?

Nov 27, 2009

We are using Oracle 11g (11.1.0).I'm not all that prolific when it comes to writing queriesI have a table...

Table1
-----------------------------------------
oid narr parent
-----------------------------------------
1 some narrative null
2 more narrative 1
3 a bit of test narrative 2

Simply put, I need a query that will recurse up through each rows parent and return the concatination of all parents and itself narrative.

Expected output
------------------------------------
some narrative
more narrative some narrative
a bit of test narrative more narrative some narrative

The requirement is that this is one single query as it will be called from a third party application we are using. We need this recursion and concatenation to be done on the database, as while we have control over the database queries that get executed we have no control over the internal source of this third party applications.I have been digging around for a bit, I have tried using a combination of JOINS and UNIONS but keep hitting a brick wall.

The best I could come up with is...
SELECT concat(n1.narr, n2.narr) FROM table1 n1
JOIN table1 n2 ON n1.oid = n2.parent

But this only returns two lines, for oid's 2 and 3, and only concatinates with the immediate parent.

View 1 Replies View Related

Concatenation Of Fields For Output

Mar 15, 2007

I have the following fields:

Addressln1
Addressln2
Suburb
Town

I know how to concatenate them

trim(Addressln1) || ',' || trim(Addressln2) || ',' || trim(Suburb) || ',' || trim(Town) as Address

1. I would like to know if any of the fields are empty I would like to eliminate the comma character from the string.
2. Can I replace the comma with a new line character and what character to be used in the syntax.

View 2 Replies View Related

PL/SQL :: Result String Concatenation

Jul 11, 2012

I am trying to spool the data to a file , and my query has 115 columns and out of which 20 columns have varchar2(2000). And its throwing result string concatenation too long.

I tried using to_clob function , but spool file does not show the complete result set.

View 4 Replies View Related

Result Of String Concatenation Is Too Long

Jan 4, 2008

I am receiving a ORA-01489: result of string concatenation is too long error on the following code. The size of the MNO_NOTE fields is: MNO_NOTES_1 X(2000). I'd rather not modify the DB table column size, but rather that capacity of the "notes", or whatever structure the concatenated string is stored in. Could I use the substring method?

SELECT TO_DATE(TO_CHAR(mno_date_recorded,'yyyymmdd')||
TO_CHAR(mno_time_recorded,'0009'),'yyyymmddhh24mi')
AS create_date,
stf_id AS create_user,
RTRIM(MNO_NOTES_1)||
RTRIM(MNO_NOTES_2)||
RTRIM(MNO_NOTES_3)||
RTRIM(MNO_NOTES_4)||
RTRIM(MNO_NOTES_5)||
[code]...

View 1 Replies View Related

SQL & PL/SQL :: Tricky Concatenation Of Data In One Column

Nov 26, 2010

Every prospect person in the prospect table are approached with a proposal. This proposal record is stored in the proposal table. Proposal is managed by many primary and proposal managers over the period of proposal. They are assigned the proposal in the assignment table. Primary managers have an assignment type 'PM' and proposal manager have a assignment type of 'PS'

i Need to make below1 and 2 changes to the script.

1-when proposal is current (proposal.active_ind = 'Y' ) then extract only currently assigned primary and proposal managers (assignment active_ind = 'Y') and these managers should be assigned after the proposal has started (assignment.start_date >= proposal.start_date )

2-when proposal is not current (proposal.active_ind = 'N' ) then extract even not curRent assigned primary and proposal managers (not use this in criteria assignment active_ind = 'Y') and these managers should be assigned only after the proposal has started (assignment.start_date >= proposal.start_date )

Primary/Proposal Manager column : Format to print as below:

All Primary managers seperated with space "/" between and all proposal managers after that and "*" at the end

For Example : Mary Steve Roger / Chris Danny Veronica * also, current script only extracts 5 primary managers and 4 proposal managers but thats ok. i can put 10 max(decode statements in the output cause i think they cannot have more than 10 managers.

/*script*/
SELECT DISTINCT p.prospect_id "PROSPECT ID"
,p.prospect_name "Prospect Name"
,pro.proposal_id
,pro.proposal_title "Proposal Title/Purpose"
, MAX(decode(pm_seq
,1
,primary_manager_name
,NULL)) || ' ' ||
[code]...

View 4 Replies View Related

ORA-01489 - Result Of String Concatenation Is Too Long

Jul 25, 2012

I have a sql query which has around 115 columns and out of which 25 columns are of varchar2(2000) and when I run the query I get the ORA-01489: result of string concatenation is too long error.

I tried to use to_clob function for the columns having varchar2(2000) and if I run the sql from toad , it works fine, but when I tried to run the same query from sqlplus and spool to a file, the result doesn't come in a single line. I have tried to import the spool file to my local and open it , but still it doesn't come in a single line, the data is trucated This is how my data looks in the spool file.

1-L31OGM|Red|1|Due|Qualified|02/08/2012||02/08/2012| you are missing a message.

These are the below set options used in the query . I even tried set long 100000000 and also set longchucksize option also, I have tried with WRAP OFF and WRAP ON also ,but still it doesn't work.

SET HEADING OFF
SET WRAP OFF
SET LINESIZE 32000
SET FEEDBACK OFF
SET PAGESIZE 0
SET LONG 32000
SET TRIMSPOOL ON
SET ECHO OFF
SET TERMOUT OFF

get the data in a single line and using utl_file package is not an option in our project due to security reason.

View 4 Replies View Related

Sql Query - Insert Concatenation String To Table?

Aug 6, 2012

i try to insert Concatenation string to my table,i need that all traps that has 12 length will be insert the new trapnum like this:

for example: 26001005CC45 = 260001005CC0045 ....... 08060027RF05 = 080600027RF0005 ......... and so....

update trap set TrapNum = (
select trim(both from to_char(substr(TrapNum,1,4),'0000'))||
trim(both from to_char(substr(TrapNum,5,1),'00'))||
trim(both from to_char(substr(TrapNum,6,3),'000'))||
substr(TrapNum,9,2)||
trim(both from to_char(substr(TrapNum,11,2),'0000')) from Trap)
where length(Trapnum)=12

but i got error ORA-01427

View 1 Replies View Related

SQL & PL/SQL :: Generate PAN Number By Concatenation Of Data From Different Tables?

Jul 11, 2011

How to generate a PAN number by concatenation of data from different tables

View 3 Replies View Related

SQL & PL/SQL :: Column Values Concatenation From Multiple Rows

May 30, 2013

I am currently doing column values concatenation from multiple rows and then removing duplicates as in the following example:

SQL> select pid
2 , regexp_replace(ltrim(sentence), '([A-Za-z0-9]+,)1+', '1')
3 from ( select pid
4 , seq
5 , sentence
6 from b
7 model
8 partition by (pid)
9 dimension by (seq)
[code]....

but for some reason regexp_replace does not seem to work with clob and I get:

ORA-00932: inconsistent datatypes: expected - got CLOB
00932. 00000 - "inconsistent datatypes: expected %s got %s"

Is it possible to eliminate duplicates in the model before the concatenation?

View 6 Replies View Related

SQL & PL/SQL :: ORA-01489 - Result Of String Concatenation Is Too Long

Aug 8, 2011

my rdbms, os version

SYS@prod> select PLATFORM_ID, PLATFORM_NAME from v$database;
PLATFORM_ID
-----------
PLATFORM_NAME
-------------------------------------------------------------------------
12
Microsoft Windows x86 64-bit
[code]...

as I googled the solution does not seems to apply to my case.it very puzzling that such a short query can produce

ORA-01489: result of string concatenation is too long.

View 3 Replies View Related

ORA-01489 / Result Of String Concatenation Is Too Long

Jul 30, 2013

when i run the interrogation bellow :

SELECT 'Existing Tables: ' || LISTAGG(table_name, ',') WITHIN GROUP (ORDER BY table_name) tablenames FROM user_tables;

i receive the error :

ORA-01489: result of string concatenation is too long
01489. 00000 - "result of string concatenation is too long"
*Cause: String concatenation result is more than the maximum size.
*Action: Make sure that the result is less than the maximum size.

View 1 Replies View Related

SQL & PL/SQL :: ERROR At Line 1 - ORA-01489 - Result Of String Concatenation Is Too Long

Aug 13, 2013

I am getting below error when i try to update in my table

ERROR at line 1:
ORA-01489: result of string concatenation is too long

how to resolve this. Note :This is Update query not select query

View 2 Replies View Related

Reports & Discoverer :: Create A Report By Using One Field / Text As Columns Name In Layout But Display All Columns

Jun 16, 2010

I want to create a report by using one field and one text as columns name in layout but display the all the columns. I mention the 5 column names in query.how can I write function in summary column.

View 4 Replies View Related

Performance Tuning :: Index 15 Columns When Cannot Predict Columns Will Be Used In Where Clause?

Apr 4, 2011

I am running a fairly busy Oracle 10gR2 DB, one of the tables has about 120 columns and this table receives on average 1500 insertions per second. The table is partitioned and the partitioning is based on the most important of the two timestamp columns. There are two timestamps, they hold different times.

Out of these 120 columns, about 15 need to be indexed. Out of the 15 two of them are timestamp, at least one of these two timestamp columns is always in the where clause the queries.

Now the challenge is, the queries we run can have any combination of the 13 other columns + one timestamp. In reality the queries never have more than 7 or 8 columns in the where clause but even if we had only 4 columns in the where clause we would still have the same problem.

So if I create one concatenated index for all these columns it will not be very efficient because after the 4th or 5th column the sorting would no longer be very useful and I believe the optimiser would simply not use the rest of the index. So queries that use the leading columns of the index in sequence work well, but if I need to query the 10th column the I have performance issues.

Now, if I create multiple single column indexes oracle will have to work a lot harder to maintain all these indexes and it will create performance issues (I have tried that). Besides, if I have multiple single column indexes the optimiser will do nested loops twice or three times and will hit only the first few columns of the where clause so I think it will kind of be the same as the long concatenated index.

What I am trying to do is exactly what the Bitmap index would do, it would be very good if I could use the AND condition that a Bitmap index uses. This way I could have N number of single column indexes which the optimiser could pick from and serve the query with exactly the ones it needs. But unfortunately using the Bitmap index here is not an option given the large amount of inserts that I get on this table.

I have been looking for alternatives, I have considered creating multiple shorter concatenated indexes but this still would not address the issue since many queries would still not be served properly and therefore would take a very long time to complete.

What I had in mind would be some sort of multidimensional index, I am not even sure if such thing exists. But essentially it would be some sort of index that could serve a query efficiently regardless of the fact that the where clause has the 1st, 3rd and last columns of the index.

So considering how widely used Oracle is and how many super large databases there are out there, this problem must be common.

View 12 Replies View Related

SQL & PL/SQL :: How To Select All Columns From Table Except Those Columns Which Type In Query

Jan 21, 2011

I have a two question.

Question 1:How to select all columns from table except those columns which i type in query

Question 2:How to select all columns from table where all columns are not null without type each column name which is in empty data

View 5 Replies View Related

SQL & PL/SQL :: Function In Oracle To Select Not-null Columns At Beginning And Null Columns At End?

Jul 12, 2012

I have 8 columns. Some of them might be null.I want to display all 8 columns in my result. Not null columns will be first and null at the end.Here is a sample data :

Employee table :
Employee_id Emp_fname emp_lname emp_mname dept salary emp_height emp_weight
1 aaa ddd d1 100 6 180
2 bbb ccc 120 169
3 dfe d2 5.9 223

The expected result is :
result1 result2 result3 result4 result5 result6 result7 result8
1 aaa ddd d1 100 6 180
2 bbb ccc 120 169
3 dfe d2 5.9 223

View 8 Replies View Related

PL/SQL :: How To Transpose A Table From Rows To Columns Or Columns Into Rows

Aug 22, 2012

what are the collections available in Oracle Plsql, what are concepts of collection.

How to Transpose a Table from rows to columns or columns into rows.

DDL and DML concepts.

What is the concepts of statistics in Oracle Plsql.

View 4 Replies View Related

SQL & PL/SQL :: Transpose Rows-to-columns And Columns-to-rows

Oct 6, 2010

I need to transpose the following table columns to rows and rows to columns...Im not quite sure how to acheive this...I have the following table with fixed number of columns and dynamic number of rows based on date filter in query

MONTH_YEAR RMS RMS_OCC TTL_RMS
---------------------------------------
SEPTEMBER 200917790017790
OCTOBER 2009183831278818347
NOVEMBER 2009177901460517762

and I need to display this as

COL1 SEPTEMBER 2009 OCTOBER 2009 NOVEMBER 2009
--------------------------------------------------------------
RMS 17790 18383 17790
RMS_OCC 0 12788 14605
TTL_RMS 17790 18347 17762

View 3 Replies View Related

Add Two Columns Together In SQL

Mar 13, 2010

My database has three tables: members (with member name, member number and club number), clubs (with club name and club number) and matches (with win member number, lose member number and score).

I have a query which displays total number of matches won by a club, and number of matches lost by a club:

Quote: select c.clubname,
(select count (*) from members wm, matches w where wm.memberno = w.winmember and wm.clubno = c.clubno) WINS,
(select count (*) from members lm, matches l where lm.memberno = l.losemember and lm.clubno = c.clubno) LOSSES
from clubs c
order by WINS desc;

How can I modify this to add the WINS and LOSSES columns together in a new column? I have modified the query as such:

select c.clubname,
(select count (*) from members wm, matches w where wm.memberno = w.winmember and wm.clubno = c.clubno) WINS,
(select count (*) from members lm, matches l where lm.memberno = l.losemember and lm.clubno = c.clubno) LOSSES,
(select count (*) from members wm, matches w where wm.memberno = w.winmember and wm.clubno = c.clubno) +
(select count (*) from members lm, matches l where lm.memberno = l.losemember and lm.clubno = c.clubno) PLAYED,
from clubs c
order by WINS desc;

View 1 Replies View Related

DEFAULT Value On Columns?

Mar 24, 2011

I wanted to know the consequences of adding a DEFAULT value to an existing column in a table.I understand that when you add a DEFAULT value to a column which is Nullable, Oracle updates all the null values for the column to the DEFAULT value, generating a lot of undo/redo data.

Is adding a DEFAULT value to a NOT NULL column a problem? As the column is NOT NULL, an update would not be done, so no undo/redo data will be generated.But will this cause a whole table scan? Is this advisable?

View 6 Replies View Related

SQL & PL/SQL :: Specific Columns In For All

Jun 9, 2010

I want to insert only specific number of columns into a table by using Bulk collect and Forall.

SQL> create or replace procedure bifa_proc
2 is
3 type etab is table of emp%rowtype index by binary_integer;
4 erec etab;
5 cursor c is select * from emp;
6 begin
7 open c;
[code]...

Warning: Procedure created with compilation errors.

PLS-00382: expression is of wrong type
PLS-00436: implementation restriction: cannot reference fields of
BULK In-BIND table of records

How to insert specific number of columns without declaring multiple table type definitions for each column by using bulk collect and forall.

View 5 Replies View Related

SQL & PL/SQL :: Count In Columns?

Feb 14, 2012

I have the following table with insert below.

CREATE TABLE ATTENDANCE
(
"REG_NO" NUMBER(7,0),
"COURSE_SEQ_NO" NUMBER(4,0),
"SECTION" VARCHAR2(1 BYTE),
"SEMESTER_CODE" NUMBER(1,0),

[code]...

How can I have the following output?

course_seq_nosectiontotal_recordscount_1count_0
322X20137

I tried decode but it could not find its way

View 9 Replies View Related

SQL & PL/SQL :: Display In Two Different Columns

Feb 1, 2013

Below is returning rows in single column.I need to display in two different columns

SELECT * FROM TABLE(PLUSER.SPLIT('a,b,c'))
union all
SELECT * FROM TABLE(PLUSER.SPLIT('1,2,3'))

this returning result like
a
b
c
1
2
3

but need abc in one column and 1,2 3 in one column
a 1
b 2
c 3

i was tried like

select * from TABLE(PLUSER.SPLIT('1,2,3')),(select * from TABLE(PLUSER.SPLIT('a,b,c')));

but it's giving cartesion result like below
1a
1b
1c
2a
2b
2c
3a
3b
3c

View 8 Replies View Related

SQL & PL/SQL :: How Many Columns Will Have Query

Apr 29, 2012

I'm a beginner in PL/SQL ! --> " get_sql_metadata(p_query IN Varchar2) RETURN VARCHAR2;" I have to display the names and columns of the query by using the package dbms_sql and how can I know how many columns will have my query.

View 4 Replies View Related

SQL & PL/SQL :: From Columns To A Single Row

Sep 22, 2011

I need to make the following transposition:

from this:

CUST_IDPLAN_IDNOREM_M4M ADD_M4M

6871 1231Yes Yes
68711232Yes NULL

into this:

CUST_ID PLAN_ID REM_M4M1 REM_M4M2 ADD_M4M1 ADD_M4M2

6871 123 Yes Yes Yes NULL

View 18 Replies View Related

Aggregate Two Columns

Oct 25, 2011

I have two table and I want to merge them

TERMS_TABLE
ID | TERMS
309 | 'hardware'
309 | 'software'
309 | 'computer'

TFIDF_TABLE
ID | TERMS
309 |'computer,phone,mp3....'

Now I want to add TERMS column of TERMS_TABLE to terms column of TFIDF_TABLE but If TFIDF_TABLE already contains TERMS of TERMS_TABLE then I should not insert this term to the NEW_TFIDF_TABLE , like that

result should be:

NEW_TFIDF_TABLE
ID | TERMS
309 |'computer,phone,mp3....,hardware,software'

How can I do that ?

View 1 Replies View Related

SQL & PL/SQL :: More Columns Into One Column?

Aug 10, 2010

I just ponder how to write SQL or PLSQ if I'd like to get more columns into the one column.

For example:

I have table T1 where are 10 records. One columns TEXT is VARCHAR2. And I need to get by SQL/PLSQL one record with the new column VARCHAR2 where will be written 3 records as I wrote.

select TEXT from T1:
result: aa
bb
cc

And the desire result should lool like:

aa bb cc

how to quickly do it?

View 2 Replies View Related

SQL & PL/SQL :: Other Columns When Using Group By

Feb 18, 2011

I have a table OS_CURRENTSTEP , and OS_WFENTRY

CREATE TABLE OS_CURRENTSTEP
(
ID NUMBER,
ENTRY_ID NUMBER NOT NULL,
STEP_ID INTEGER NOT NULL,
ACTION_ID INTEGER,
OWNER VARCHAR2(20 BYTE),
START_DATE DATE,

[Code]...

I need count of step_id from os_currentstep wh

here is the query

select count(step_id), step_id from os_currentstep where owner='Marty' group by step_id

this gives me the count I also need the name associated with this step_id from table OS_WFENTRY

, I cannot query name from step_id ,

View 5 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved