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;
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
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.
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.
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.
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]...
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.
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.
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
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.
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.
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.
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.
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 :
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
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;
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?
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.
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.
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'
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.