tags:

views:

1245

answers:

3

I am trying to concatenate some fields to return a single string for each row from an oracle table. This is in 10g. Here is my query:

SELECT t.value || '|' || t.label || '|' t.label_abbrv || '||' "mylist" 
  FROM list_value t
 WHERE t.value BETWEEN 195001 AND 195300;

I'm getting the "FROM keyword not found where expected" error. This is really annoying. It's a simple query. I'm sure it's something simple I'm missing.

+2  A: 

D'oh! I found the problem. I'm missing a concat!

SELECT value || '|' || label || '|' ****||**** label_abbrv || '||' "mylist" from list_value where (value between 195001 and 195300);
Theresa
The "mylist" might be a problem too... but I suspect you didn't mean it literally. If you replaced it with 'bananas|apples|sofas', then no problems.
Kieveli
I suppose "mylist" is a column alias ;)
Juergen Hartelt
@jhartelt: yes, "mylist" is just the column header; I fixed where the missing pipes were...I couldn't copy/paste as the query is on a different network/computer
Theresa
+1  A: 

I think your answer to your own question is still wrong - it should be:

SELECT value || '|' || label || '|' || label_abbrv || '||' "mylist" 
                                   ^^^^
Tony Andrews
+2  A: 

If you used SQLPLUS client, it would have saved you a little time:

SQL> SELECT value || '|' || label || '|' label_abbrv || '||' "mylist"
  2  from list_value where (value between 195001 and 195300);
SELECT value || '|' || label || '|' label_abbrv || '||' "mylist"
                                                *
ERROR at line 1:
ORA-00923: FROM keyword not found where expected

You can break up your query to multiple lines to isolate the problem:

SQL> edit
Wrote file afiedt.buf

  1  SELECT value || '|'
  2  || label ||
  3  '|' label_abbrv ||
  4  '||' "mylist"
  5  from list_value
  6  where
  7* (value between 195001 and 195300)
SQL> /
'|' label_abbrv ||
                *
ERROR at line 3:
ORA-00923: FROM keyword not found where expected

You might find SQLPLUS to be "primitive," but, hmmm, that's good for another question. Let me see if anyone else has asked about it yet.

ericp
SQLPlus may be primitive but its the only tool that always works and never lies. (for the record I spend most my day in TOAD). One up vote for the great answer.
caddis
@ericp: great suggestion! I'll have to try breaking up the query into multiple lines the next time it won't run.
Theresa