Home » RDBMS Server » Server Administration » Dynamic SQL
Dynamic SQL [message #369965] |
Tue, 21 November 2000 02:43 |
Kiki
Messages: 13 Registered: November 2000
|
Junior Member |
|
|
I heard that Dynamic SQL can give the simplicity when we want to select many column names from many table names. Does anyone give me the example or maybe the walkthrough.
Thanks,
|
|
|
|
|
|
|
Re: Dynamic SQL [message #369988 is a reply to message #369967] |
Wed, 22 November 2000 21:02 |
Kiki
Messages: 13 Registered: November 2000
|
Junior Member |
|
|
Thanks!
example:
I have 2 tables:customer and company.
Inside customer table, there is cust_id, cust_name, cust_addr. while company table has company_id, company_name.
In my query, Instead of repeating some many boring lines, I thought that it is better to have only one select statement which I can call it and pass the table name and column name.
so what I did:
sql_statement :='select :column_name from :table_name';
then if I want to get result for cust_id from customer table, this is what I did.
table_name='customer';
column_name='cust_id';
Execute Immediate sql_statement using column_name,table_name;
However, I got syntax error. does anyone can help to fix it up. and also after we run execute immediate, there is anyway we can store that results on the variable, so that I can use that for other purposes.
Thanks very much for your helps :)
|
|
|
|
Re: Dynamic SQL [message #369997 is a reply to message #369967] |
Thu, 23 November 2000 18:24 |
Kiki
Messages: 13 Registered: November 2000
|
Junior Member |
|
|
thx for your help. It is very helpful.
However, I found out that your technique is only effective by using prompt only. While in my case, I don't want to use prompt because This is suppose to look automatically. What I mean is that I want to store the table name, for example, in the variable inside my script.
Example,
table_name:='customer';
Anywayz, Thanks for your helps!:P
If you can, can you send me email privately to thegiggsy@mailcity.com. thx!
|
|
|
Goto Forum:
Current Time: Fri Jan 10 16:47:59 CST 2025
|