Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7702993
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:21:29+00:00 2026-05-31T23:21:29+00:00

I wanted to replace not just values stored in columns with parameters, but table

  • 0

I wanted to replace not just values stored in columns with parameters, but table names, column names, etc., so I tried this:

    // Can get any string value based on any string key with this function
    public string GetValForKeyVal(string ATable, string AKeyVal, string AColumnToQuery, string AColumnToReturn) {
        String qry = "SELECT :ColOfInterest FROM :TableToQuery WHERE :KeyValColumn = :KeyVal";
        OracleCommand cmd = new OracleCommand(qry, con);
        cmd.CommandType = CommandType.Text;
        OracleParameter opColOfInterest = cmd.Parameters.Add("ColOfInterest", OracleDbType.Varchar2,
          AColumnToReturn, ParameterDirection.Input);
        OracleParameter opTableToQuery = cmd.Parameters.Add("TableToQuery", OracleDbType.Varchar2,
          ATable, ParameterDirection.Input);
        OracleParameter opKeyValColumn = cmd.Parameters.Add("KeyValColumn", OracleDbType.Varchar2,
          AColumnToQuery, ParameterDirection.Input);
        OracleParameter opKeyVal = cmd.Parameters.Add("KeyVal", OracleDbType.Varchar2,
          AKeyVal, ParameterDirection.Input);
        return cmd.ExecuteScalar().ToString();
    }

…but get, "ORA-00903 invalid table name"

So, I tried doing in the C# way:

    public string GetValForKeyVal(string ATable, string AKeyVal, string AColumnToQuery, string AColumnToReturn) {
        String qry = String.Format("SELECT {0} FROM {1} WHERE {2} = {3}", AColumnToReturn, ATable, AColumnToQuery, AKeyVal);
        OracleCommand cmd = new OracleCommand(qry, con);
        cmd.CommandType = CommandType.Text;
        return cmd.ExecuteScalar().ToString();
    }

…but that too failed, in fact with, "ORA-00904 "WHYAMINOTQUOTINGTHEDOT"."EXE": invalid identifier"

Am I barking up the wrong tree, or simply using the wrong way to filet a cat?

In olden times (Delphi), you could make a string safe for passing to the DB engine by encasing it in something like QueryStr(). Is there an analogous helper function for C#/Oracle?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T23:21:30+00:00Added an answer on May 31, 2026 at 11:21 pm

    You can’t use parameters to replace table names and column names in Oracle. One of the major benefits of using parameterized queries from the database perspective is that Oracle can parse the query once (generating the query plan among other things) and then execute it many times with different parameter values. If the table or columns change, that requires a new hard parse of the query so it would not be eligible to be a bind variable.

    Can you explain a bit more about the problem you’re trying to solve? It seems unusual that you’d want to write code that could query an arbitrary column of an arbitrary table– that generally implies that you have a number of different tables that store the same basic sort of data in which case you would generally be better served by revisiting the normalization of your data model. If you want to determine whether a particular table name or column name is safe to pass to the database from a SQL injection standpoint, you could use the DBMS_ASSERT package but at that point you might be better served just querying ALL_TAB_COLUMNS for the specified table name and column name to see whether there are actually columns AColumnToReturn and AColumnToQuery in ATable in the database.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wanted to create an external table, but did not have the CREATE ANY
I've been able to find similar, but not identical questions to this one. How
I wonder if I can just check something that I have not tried before,
so I'm not entirely sure this is possible, but I am curious if it
For instance, if I wanted to a find and replace with strings containing backward
I wanted to check whether the variable is defined or not. For example, the
I just wanted to know what happens behind my program when I declare and
I just wanted to know how to use C to automatically assign a free
This is a followup question to the one I posted last week Ajax.ActionLink not
I'm playing around with redis and wanted to recreate a table I have in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.