I'm Currently working on a small project where i have to generate a fully functional
Oracle Curosr text (with params) based on a SQL query the user enters. I'm planing to do this as a C# program.
currently having problems with generating the parameters for the Cursor.
Ex:
if the user enters something like:
SELECT a , b, c FROM TABLE t WHERE t.d = d_ AND t.e = e_
the generated cursor text should be like:
CURSOR get_data(d_ datatype , e_ datatype) IS
SELECT a,b,c
FROM TABLE t
WHERE t.d = d_
AND t.e = e_ ;
it'll be great if someone can explain me what approach to take on this
Thanks in Advance.
Rahul BansalPosted Feb 26, 2015, 4:46 AM
string str = TextBox1.Text;// "SELECT a, b, c FROM TABLE t WHERE t.d = d_ AND t.e = e_";
string[] st = new string[str.Split('=').Length - 1];
for (int i = 1; i < str.Split('=').Length; i++)
st[i - 1] = str.Split('=')[i].Trim().Split(' ')[0].ToString();
string cursor = "CURSOR get_data(";
for (int i = 0; i < st.Length; i++)
{
cursor += st[i] + "datatype ,";
}
cursor= cursor.Substring(0, cursor.Length-1);
cursor += ")
" + str;
Response.Write(cursor);
------------------------------------------------
output will be-
------------------------------------------------
CURSOR get_data(d_datatype ,e_datatype )
SELECT a, b, c FROM TABLE t WHERE t.d = d_ AND t.e = e_