Where Clause from table [message #245801] |
Mon, 18 June 2007 18:05 |
tj_orafaq
Messages: 5 Registered: June 2007
|
Junior Member |
|
|
I have a requirement in which I need to generate a where clause for query stored in table.
Table EMP
Table:FilterStore (filter varchar2(1000))
The table filterstore has value as ename-'KING' and job='PRESIDENT'
Now I need to generate a query in whcih the where clause comes from other table..like this
select * from emp where (select filter from filterstore)
(f I run the aboe query it gives an error missing expression
Has anyone gone thru this?
Thanks for the help.
|
|
|
|
Re: Where Clause from table [message #245807 is a reply to message #245801] |
Mon, 18 June 2007 18:53 |
tj_orafaq
Messages: 5 Registered: June 2007
|
Junior Member |
|
|
I still get the same error
SQL> declare
2 v_qry varchar2(1000);
3 v_temp varchar2(100);
4 begin
5 v_qry:='select ename from emp where (select filter from filterstore)';
6 execute immediate v_qry into v_temp;
7 dbms_output.put_line(v_temp);
8 end;
9 /
declare
*
ERROR at line 1:
ORA-00936: missing expression
ORA-06512: at line 6
|
|
|
|
|
|
|
Re: Where Clause from table [message #245813 is a reply to message #245801] |
Mon, 18 June 2007 19:50 |
tj_orafaq
Messages: 5 Registered: June 2007
|
Junior Member |
|
|
I did this earlier in office but didnt work..guess it was late and my brain dumped
declare
v_qry varchar2(1000);
v_bind varchar2(1000);
begin
select filter into v_bind from filterstore;
dbms_output.put_line(v_bind);
v_qry:='select ename from emp where '||v_bind;
execute immediate v_qry into v_temp;
dbms_output.put_line(v_temp);
exception when others then
dbms_output.put_line('Exception is '||sqlerrm);
end;
/
[Updated on: Mon, 18 June 2007 19:50] Report message to a moderator
|
|
|
|
|
|
|
|
Re: Where Clause from table [message #246018 is a reply to message #245942] |
Tue, 19 June 2007 10:23 |
Frank
Messages: 7901 Registered: March 2000
|
Senior Member |
|
|
caliguardo wrote on Tue, 19 June 2007 13:56 | I can see the error message and can try debugging with the error message obtained to get errorfree code if i use SQLERRM.
I mean if my procedure returns too many rows exception, As a beginner i may not be knowing about this. So i will try and display the error message using SQLERRM so thst my debugging becomes easy.
|
And what do you think you will see if you remove the exception handler?
Exactly the same message. Oracle even shows you the line number the error was raised on...
|
|
|
|
|
|
Re: Where Clause from table [message #246255 is a reply to message #246251] |
Wed, 20 June 2007 07:55 |
|
Michel Cadot
Messages: 68718 Registered: March 2007 Location: Saint-Maur, France, https...
|
Senior Member Account Moderator |
|
|
The correct to develop, in any language, is to trap exception not to return an error message.
Exceptions are great. They raise exactly where there is an error and gives you all information about your environment when the error occurs.
If you hide them through "when other then return error messsage" you loose many of useful information.
"Exception" block should only exists for expected errors, the one you know how to handle in the program, not others.
Regards
Michel
|
|
|