-1

Getting error when executing below code.

java.sql.SQLSyntaxErrorException: ORA-00933: SQL command not properly ended

StringBuilder sb = new StringBuilder();
        sb.append("select");
        sb.append(" region_name,");
        sb.append(" sum(case when  SUBCASE_MEASURED = '1'");
        sb.append(" AND FE_TYPE = 'ASP'");
        sb.append(" AND MONTH = '2018-Jun'");
        sb.append(" then 1");
        sb.append(" else 0 end) count1,");
        sb.append(" sum(case when");
        sb.append(" SUBCASE_MEASURED = '1' AND FE_TYPE = 'ASP' AND QUARTER = 'Q2-2018' then 1 else 0 end) count2");
        sb.append(" from late_start_conf_dsptch_accu");
        sb.append(" GROUP BY region_name;");
simba
  • 277
  • 4
  • 19
  • 1
    It's interesting how you say you're getting the error from that code specifically. All your code is doing is creating a StringBuilder object. – Phylogenesis Jul 06 '18 at 10:00
  • 1
    Remove the semicolon at the end – Maurice Perry Jul 06 '18 at 10:01
  • This isn't a duplicate of that questions; this isn't an update and the error isn't caused by joins. It's just the same error code... – Alex Poole Jul 06 '18 at 10:21
  • Why are you even using StringBuilder for this? Just using plain concatenation it would be simpler to read and if everything is String literals as in your question, it will even produce a single string at **compile** time. – Mark Rotteveel Jul 06 '18 at 13:11

2 Answers2

1

Try to remove ; at the end of your sql

flyingfox
  • 13,414
  • 3
  • 24
  • 39
0

You should not have semi colon at the end of your sql command,

GROUP BY region_name;" should be " GROUP BY region_name

soorapadman
  • 4,451
  • 7
  • 35
  • 47
dursun
  • 1,861
  • 2
  • 21
  • 38