Home > Contents > Index >
Expanded TOC | Accordion TOC | Annotated TOC | Index
ICS.SQLExp
Creates a string that can be used as part of an SQL WHERE clause.
Syntax
public String SQLExp(String table, String type, String verb, String arg, String columnString exp)Parameters
table- The table for which the statement is being executed.
type- The expression type. Specify one of the following constants:
ICS.SQLExpAND(AND operation)ICS.SQLExpOR (OR operation)ICS.SQLExpIN(IN operation)verb- The verb for the
WHEREclause (for example, "LIKE", "=", "!=", "IN", "NOTIN").
arg- Comma-separated list of values for the expression.
column- The column for which the expression is being generated.
exp (Optional)- An optional expression; for example:
lower(color)Description
The
SQLExpmethod creates a string that can be used as part of a SQL where clause. For a description of SQL where clauses, see a SQL tutorial.
SQLExptakes a comma-separated string of items and a column name and places a relational operator between each item/column name pair. A logical operator is placed between each item/column name comparison.SQLExpdeals with values of different types correctly. If you provide an argument forexp, the argumentUse the optional
expargument to specify an expression to be used as part of the where clause. The following table demonstrates some sample input parameters and the affect ofexpon the resulting where clause:
Input Parameters Resulting Value of where clause table type verb arg column expFloraAND=greencolor omittedcolor='green'FloraAND=greencolorcolorcolor='green'FloraAND=greencolorlower(color)lower(color)='green'
Returns
String containing the generated expression.
Example
Consider a database table named
Moviesthat contains the following rows:
id title director1000001The GeneralBuster Keaton10000003Jules et JimFrancois Truffaut10000004Seven SamuraiAkira Kurosawa10000005General PostThomas Bentley
The following code uses
SQLExp(without anexp) to create a SQL expression that will ultimately find all titles that contain the wordGeneral:
String table = "Movies"; String type = ICS.SQLExpOR; String verb = "LIKE"; String arg = "General"; String column = "title"; String WhereClause = ics.SQLExp(table, type, verb, arg, column);When executed,
WhereClausewill contain:
title LIKE '%General%'The following code uses the returned
WhereClauseas a portion of a larger SQL statement and then invokes that SQL statement:
String SQLStart = "SELECT title,director FROM Movies WHERE "; String SQLStatement = SQLStart + WhereClause; String from = "Movies"; String listname = null; int limit = 5; boolean bCache = true; StringBuffer errstr = new StringBuffer(128); ics.ClearErrno(); IList MyList = ics.SQL(from, SQLStatement, listname, limit, bCache, errstr);
MyListshould now contain the rows from theMoviestable that matched the query; that is, the rows whosetitlecontainedGeneral.See Also
Home > Contents > Index > ![]()
Oracle JAVA Reference
Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.