How to add symbols to SQLquery output (oracle)

时间:2017-04-10 00:39:15

标签: sql oracle

The code I have here works and pulls the correct data and makes the right calculations with all the tables, but I would like to add a '#' symbol before the rendezvous.nordv number and a '$' symbol to the prices. I have found a way to add the '$' symbol using TO_CHAR but I would rather concatenate the symbols when issuing the select statement.

Any help is appreciated.

SELECT rendezvous.nordv,
       rendezvous.nopatient Numero_patient,
       rendezvous.noservicessupp Type_Service_Supplementaire,
       TO_CHAR(SUM(servicessupplementaires.prix), 'L999,999,999.00') AS ss_prix,
       TO_CHAR(COUNT( rendezvous.noservicessupp ) * servicessupplementaires.prix, 'L999,999,999.00') AS Total_Services_Supplementaires,
       rendezvous.notypeexamen Type_Examen,
       TO_CHAR(SUM(typeexamen.prix), 'L999,999,999.00') AS examen_prix,
       TO_CHAR(COUNT( rendezvous.notypeexamen ) * typeexamen.prix, 'L999,999,999.00') AS Total_Examen_Clinique,
       TO_CHAR(CASE WHEN COUNT( rendezvous.noservicessupp ) * servicessupplementaires.prix IS NULL THEN COUNT( rendezvous.notypeexamen ) * typeexamen.prix
           WHEN COUNT( rendezvous.notypeexamen ) * typeexamen.prix IS NULL THEN COUNT( rendezvous.noservicessupp ) * servicessupplementaires.prix
           ELSE COUNT( rendezvous.noservicessupp ) * servicessupplementaires.prix +
           COUNT( rendezvous.notypeexamen ) * typeexamen.prix END, 'L999,999,999.00') AS Addition,
       TO_CHAR(CASE WHEN TO_CHAR(rendezvous.debutrdv, 'DY','NLS_DATE_LANGUAGE=AMERICAN') NOT IN ('SAT', 'SUN') 
           THEN (CASE WHEN COUNT( rendezvous.noservicessupp ) * servicessupplementaires.prix IS NULL THEN COUNT( rendezvous.notypeexamen ) * typeexamen.prix
           WHEN COUNT( rendezvous.notypeexamen ) * typeexamen.prix IS NULL THEN COUNT( rendezvous.noservicessupp ) * servicessupplementaires.prix
           ELSE COUNT( rendezvous.noservicessupp ) * servicessupplementaires.prix +
           COUNT( rendezvous.notypeexamen ) * typeexamen.prix END) 
           ELSE (CASE WHEN COUNT( rendezvous.noservicessupp ) * servicessupplementaires.prix IS NULL THEN COUNT( rendezvous.notypeexamen ) * typeexamen.prix
           WHEN COUNT( rendezvous.notypeexamen ) * typeexamen.prix IS NULL THEN COUNT( rendezvous.noservicessupp ) * servicessupplementaires.prix
           ELSE COUNT( rendezvous.noservicessupp ) * servicessupplementaires.prix +
           COUNT( rendezvous.notypeexamen ) * typeexamen.prix END) * 1.1 END, 'L999,999,999.00') AS SousTotal,
        TO_CHAR((1 - patient.couvertureass) * 
           (CASE WHEN TO_CHAR(rendezvous.debutrdv, 'DY','NLS_DATE_LANGUAGE=AMERICAN') NOT IN ('SAT', 'SUN') 
           THEN (CASE WHEN COUNT( rendezvous.noservicessupp ) * servicessupplementaires.prix IS NULL THEN COUNT( rendezvous.notypeexamen ) * typeexamen.prix
           WHEN COUNT( rendezvous.notypeexamen ) * typeexamen.prix IS NULL THEN COUNT( rendezvous.noservicessupp ) * servicessupplementaires.prix
           ELSE COUNT( rendezvous.noservicessupp ) * servicessupplementaires.prix +
           COUNT( rendezvous.notypeexamen ) * typeexamen.prix END) 
           ELSE (CASE WHEN COUNT( rendezvous.noservicessupp ) * servicessupplementaires.prix IS NULL THEN COUNT( rendezvous.notypeexamen ) * typeexamen.prix
           WHEN COUNT( rendezvous.notypeexamen ) * typeexamen.prix IS NULL THEN COUNT( rendezvous.noservicessupp ) * servicessupplementaires.prix
           ELSE COUNT( rendezvous.noservicessupp ) * servicessupplementaires.prix +
           COUNT( rendezvous.notypeexamen ) * typeexamen.prix END) * 1.1 END), 'L999,999,999.00') AS Total_a_payer
FROM rendezvous 
FULL JOIN servicessupplementaires ON rendezvous.noservicessupp = servicessupplementaires.noservicessupp
FULL JOIN typeexamen ON rendezvous.notypeexamen = typeexamen.notypeexamen
FULL JOIN patient ON rendezvous.nopatient = patient.nopatient
WHERE rendezvous.noservicessupp >= 1
   OR rendezvous.notypeexamen >= 1
GROUP BY rendezvous.nopatient,
         patient.couvertureass,
         patient.nopatient,
         servicessupplementaires.prix,
         rendezvous.noservicessupp,
         rendezvous.debutrdv,
         rendezvous.nordv,
         typeexamen.prix,
         rendezvous.notypeexamen;

2 个答案:

答案 0 :(得分:0)

For #:

'#' || rendezvous.nordv

or, for $:

'$' || your_column

or

TO_CHAR( your_column, 'FM$999,999,999.00' )

or, if the NLS_CURRENCY session parameter is set to $:

TO_CHAR( your_column, 'FML999,999,999.00' )

The FM format modifier suppresses any extra white space.

答案 1 :(得分:0)

  

“当我将'#'|| rendezvous.nordv添加到select语句时,它会错误地给我一个组。”

有趣。这是一个简单的测试用例,没有证明这种行为:

SQL> select col1, max(col2) from t23
  2  group by col1
  3  /

      COL1  MAX(COL2)
---------- ----------
         1          3
         0          4

SQL> select '#'||col1 as col1, max(col2) from t23
  2  group by col1
  3  /

COL1                                       MAX(COL2)
----------------------------------------- ----------
#1                                                 3
#0                                                 4

SQL>