Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

select count into versus create table as in functions/procedures

sgonos-OracleJul 24 2009 — edited Jul 24 2009
I am working on a dynamic PL/SQL script that will count the number of records in a remote database
based on certain criteria and then if the number is "acceptable" will create a table in the connecting
database with those records.

My where clauses are supposed to be the same but I am presented with the problem, when I run the
first code ... select in to rowcount I get 122000 records, when I later do the create table as
with the same whereclause code, I get 77 records. So now I am attempting to validate that the two
where clauses are the same ... you'd think it would be obvious, but it's not.

My first operation does a select count(*) into rowcount with the where clause behind it.
The second operations creates a "sql command literal' that gets executed and returns the less value.

I build it like testscript := 'create table '||tablename ||'as select * from '||remotetablename||'@'||linkname;
testwhere := ' xxxxxxx'
then I do an execute immediate teststring ||' ' testwhere; which works but gives me 77 rows in the table.

Since I believe my where clause might be different, how can I run the first operation ... select count into rowcount
as a normal SQL statement in the script...

When I attempt to just run it I get -- PLS-00428: an into clause expected in this select statement......

I will provide the source code in my next posting. Working to get it moved to this system.. Once you see it you'll understand
why I don't think, it's the same, but I need a way to run them exactly as they are written to understand the different results.

so How can I make the select count (*) into rowcount from .... work just like a normal select
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 21 2009
Added on Jul 24 2009
3 comments
877 views