<p>I have a dilemma, I'm using Java and Oracle and trying to keep queries on PL/SQL side. Everything is OK, until I have these complex queries which may and may not have conditions. <br></p>

<p>It's not hard in Java to put together <code>WHERE</code> clause with conditions, but it's not nice.
And on PL/SQL side I also found out that the only possibility for <code>dynamic queries</code> is string manipulations like</p>

<pre><code>IF inputname IS NOT NULL THEN    
    query := query ||' and NAME=' || inputname; 
END IF;
</code></pre>

<p>Now I'm thinking, I'm leaving query in PL/SQL and sending <code>WHERE</code> clause with function parameter.
Any good recommendations or examples please?</p>

SQLBuilder
might be useful to you from the Java side.  It allows you to write compile-time checked Java code that dynamically builds sql:
```
```
String selectQuery =
  (new SelectQuery())
  .addColumns(t1Col1, t1Col2, t2Col1)
  .addJoin(SelectQuery.JoinType.INNER_JOIN, joinOfT1AndT2)
  .addOrderings(t1Col1)
  .validate().toString();
```
```