Selecting a top value and storing it into a parameter

I have some Sql server code, and I need it converted to Oracle

SET @tmp = (SELECT TOP 1 tmpColzer FROM tecoTable);

Can someone show me how this is done in Oracle?
LVL 2
brgdotnetcontractorAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

slightwv (䄆 Netminder) Commented:
You need to define the colum that needs to order by then something like:
SELECT tmpColzer into tmp FROM (
SELECT tmpColzer, row_number() over(order by some_column) rn  FROM tecoTable
)
where rn=1
0
awking00Information Technology SpecialistCommented:
declare
tmp datatype;
begin
select tmpColzer into tmp from tecoTable where rownum = 1;
end;
0
brgdotnetcontractorAuthor Commented:
Neither of these are working for me? I am getting some compile errors in both which I cannot resolve.
0
slightwv (䄆 Netminder) Commented:
Need more information.  What are the error messages.  How are you executing it?

Mine works for me.

Here is my complete test setup and run:
create table mytecotable (tmpcolzer number, some_column number);
insert into mytecotable values(1,1);
insert into mytecotable values(2,2);
commit;


declare
	tmp number;
begin
SELECT tmpColzer into tmp FROM (
SELECT tmpColzer, row_number() over(order by some_column) rn  FROM mytecoTable
)
where rn=1 ;

dbms_output.put_line('Got: ' || to_char(tmp));
end;
/

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mark GeerlingsDatabase AdministratorCommented:
This looks like just one small part of what may be a bigger problem (or program).  What will this result be used for?  In Oracle, maybe you don't need to declare a parameter to hold a value, only to pass it to some other program or query.  But, we have no idea of what the big picture is here for you.  If you describe the bigger business problem, we may be able to help you solve it in a simpler way in Oracle.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.