on 03-19-2014 11:10 PM
Hi,
I had been trying to get user input for schema name(X) and table name(Y) . Then concatenate it to a string "X"."Y". Then select * from "X"."Y"
I am getting an error saying its not possible to select from a string.
Any thoughts on how i can proceed?
Thank you for your time .
Regards
Meenu
Hi Meenu
I cannot look into the future, so I may be wrong, in fact I will probably be wrong.
But I believe what will happen now is this:
1. You'll somehow hear about dynamic SQL and get all excited about it as it seems to solve your problem.
2. You stop looking for a solution, because you think you found the perfect answer at step 1. And when the problems with this approach start to surface you likely won't be there (as you are the developer of the system, not the user, administrator or maintainer).
Please carefully think about the requirement here.
You have a query that you want to run against a table in a schema of which both is unknown at the time you design the query.
What kind of super-clever-flexible data design might that be?
- Lars
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Lars,
Yes you got it wrong .. those are similar resultant tables from one algorithm , written back as hana tables. gonna sip this as a solution to customer . So i dont want them to be restricted to which schema they write on the results. so results give answers for different questions. I am trying to put it into an explorer and do same analysis for may be 7-8 different resultant tables.
Hope that clears the doubt ..
Thank You
Meenu
Did you keep the EXEC statement in the procedure as shown in that document and then called the procedure? And you landed up with that error?
Can you share the error screenshot?
On the side note-- You are running some algorithim for which you will get results in multiple tables and then you want to use BO Explorer on top of the views created on this table? Some how i got lost in requirement and the solution you are trying to work on. Can you explain a bit further?
Regards,
Krishna Tangudu
Meenu
I told you how this would work.dynamic SQL.
Krishna told you how this would work: EXEC (IMMEDIATE) which is, guess what: dynamic SQL (the same I told you about).
I even pointed to the fact that dynamic SQL is the wrong tool 99% of the time just to make sure you don't waste your time with something that sound alluring to most SQL developers first and that turns out to be not the right thing afterwards.
That what not about proving you wrong but providing help.
If you don't want to take advise - fine with me.
Be happy with just the correct use of syntax instead:
create schema S1;
create schema S2;
create column table s1.tab1 (id integer, name varchar(20));
insert into s1.tab1 values (1, 'LARS');
create column table s2.tab1 (id integer, name varchar(20));
insert into s2.tab1 values (1, 'PAUL');
create procedure sel_switch (IN schema_name varchar, IN table_name varchar)
LANGUAGE SQLSCRIPT
as
BEGIN
EXECUTE IMMEDIATE ( 'SELECT * FROM ' || :schema_name || '.' || :table_name );
END;
call sel_switch ('S1', 'TAB1');
/*
ID NAME
1 LARS
*/
call sel_switch ('S2', 'TAB1');
/*
ID NAME
1 PAUL
*/
Works on my Rev 70 instance without any "type cast" issue...
- Lars
Hi Lars,
Sorry for misinterpreting . I appreciate your help
I was doing
EXEC('select * from ' || :full_qualifier); which apparently did not work .
Somehow I overlook Krishna saying execute immediate .
Your suggestion works.EXECUTE IMMEDIATE('select * from ' || :full_qualifier) ;
I am rethinking options, The main concern in my project was to give the end user an interactive GUI experience. I will send you a detailed mail on what I was thinking to achieve ,May be you can guide me in the thought process. I am sure there will be some issues in thought process.
Thank You for helping out .
Have a good day!
Regards
Meenu
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.