Variable table or column names
INFORMIX-SQL or any other SQL-based DB:
Suppose I have an app 开发者_StackOverflowwhere depending on the value of some columns, example:
company.code char(3) {abc}
company.branch char(2) {01}
Can I construct table name "abc01" for inclusion in SELECT * FROM abc01; ? In other words, a variable table name.. same question applies for column names.
Only in a language which can manipulate character strings and handle Dynamic SQL. It has to create the statement on the fly.
You can only use placeholders in queries for values, not for the structural elements of the query such as the table name or column name.
Only if you use dynamic sql. It's like you build sql code in your app, then use something like execute immediate.
sprintf(cdb_text1, "create table %s (field1 char(3));", usr_db_id);
EXEC SQL execute immediate :cdb_text;
If you use dynamic sql, it's bad because of sql injections.
精彩评论