Oracle Select query

Posted on 2013-02-06
Last Modified: 2013-02-07

I was trying to get the records of select statement inside the procedure of Oracle (not sql server), the image is attached and then get the data in say Data Reader like

DataReader dr=ObjOracleHelper.ExecuteNonQuery("procedureName", oPara, CommandType.StoredProcedure);

but the procedure return error and don't allow me this. I don't want to use the query in the Data Access Layer.

The select statement return around 100 records.

Can anyone help!

Question by:Dinesh Kumar
LVL 42

Expert Comment

ID: 38858935
Oracle does not support that, you got to use INTO or use a variable:

Author Comment

by:Dinesh Kumar
ID: 38858946
BUT I have to return 100 records having 10 columns from Oracle Proecedure. There must be some way out!

By using INTO variable I can not select/retrieve say 100 records from the table.
LVL 42

Accepted Solution

sedgwick earned 450 total points
ID: 38858975
you can declare new type which consists of the fields in your select statement.
for instance,
the following won't work as explained:
if(lastid != 0 then
select a,b,c,d from table
end if;

Open in new window

so what you wanna do is to declare new type:
  TYPE SomeNewType IS RECORD (
    tmp_a table.a%TYPE,
    tmp_b table.b%TYPE,
    tmp_c table.b%TYPE
  recNewType SomeNewType;

Open in new window

and use it in your if expression:
if(lastid != 0 then
SELECT a, b,c  INTO recNewType 
  FROM table
end if;

Open in new window

check here for example:
SELECT INTO Assigns Values to Record Variable
LVL 48

Expert Comment

ID: 38859095
must it be a stored procedure? why not use a table function?

but: perhaps I'm missing the point
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

LVL 42

Expert Comment

ID: 38859114
i didn't say stored procedure, check the link I've posted and it explains how to achieve what u want.
LVL 42

Expert Comment

ID: 38859120
if you post the whole sql in here (rather than a picture) i'll modify it to make it work for you.
LVL 76

Assisted Solution

by:slightwv (䄆 Netminder)
slightwv (䄆 Netminder) earned 50 total points
ID: 38859216
You can declare a record and use an associative array but I would suggest you return a ref cursor.

There are a ton of examples out there if you look around:

Also, if you aren't using ODP.Net, I strongly encourage you to start.

Author Closing Comment

by:Dinesh Kumar
ID: 38863474

Author Comment

by:Dinesh Kumar
ID: 38863484
Hi slightwv,

Can you please help why on the following link,

any one is not posting any answer?

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Remove a text string from the end of another string 5 19
automatic email alert 1 20
Problem to page 4 17
sql query 9 18
Truncate is a DDL Command where as Delete is a DML Command. Both will delete data from table, but what is the difference between these below statements truncate table <table_name> ?? delete from <table_name> ?? The first command cannot be …
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
Via a live example, show how to take different types of Oracle backups using RMAN.
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now