473,405 Members | 2,176 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

[pl/sql] Problem of select and display the result

17
Hello everybody,
i have a problem that i don't know how to solve it.
I created a procedure like this:

create or replace
PROCEDURE Employee_LoadById
(
p_Id NVARCHAR2
)
AS
BEGIN
EXECUTE IMMEDIATE 'SELECT DISTINCT "Employee"."Id", "Employee"."Name", "Employee"."LastWriteTime", "Employee"."CreationTime"
FROM "Employee"
WHERE "Employee"."Id" = :1' USING p_Id;
END;

My questions are:
1- I tried to create this procedure without the command "EXECUTE IMMEDIATE", but i have an error because the pl/sql don't allow to write the select statement without this key word or without the "Select INTO".
That why i use the key word "EXECUTE IMMEDIATE".
I want to know it's a good way to do or not for such procedure (to load the data in the table).
2- This procedure is no problem to compile or to exec by using the command " CALL ..." or "EXEC ..." and it display repectively that "Appel terminé" = "call finished" or " Procédure PL/SQL terminé avec succès" = "PL/SQL procedure finished with success".
This procedure doesn't display the result (the rows in the table) for me.
It has a problem with my procedure or not.

I search in the internet and most of the my result's research, it use the select statement without the command "EXECUTE IMMEDIATE". So can anyone give me any ideas?
Hope to receive some replies for this problem, i say thanks very much in advance.
Have a nice day.
Sep 12 '07 #1
10 4510
amitpatel66
2,367 Expert 2GB
Hello everybody,
i have a problem that i don't know how to solve it.
I created a procedure like this:

create or replace
PROCEDURE Employee_LoadById
(
p_Id NVARCHAR2
)
AS
BEGIN
EXECUTE IMMEDIATE 'SELECT DISTINCT "Employee"."Id", "Employee"."Name", "Employee"."LastWriteTime", "Employee"."CreationTime"
FROM "Employee"
WHERE "Employee"."Id" = :1' USING p_Id;
END;

My questions are:
1- I tried to create this procedure without the command "EXECUTE IMMEDIATE", but i have an error because the pl/sql don't allow to write the select statement without this key word or without the "Select INTO".
That why i use the key word "EXECUTE IMMEDIATE".
I want to know it's a good way to do or not for such procedure (to load the data in the table).
2- This procedure is no problem to compile or to exec by using the command " CALL ..." or "EXEC ..." and it display repectively that "Appel terminé" = "call finished" or " Procédure PL/SQL terminé avec succès" = "PL/SQL procedure finished with success".
This procedure doesn't display the result (the rows in the table) for me.
It has a problem with my procedure or not.

I search in the internet and most of the my result's research, it use the select statement without the command "EXECUTE IMMEDIATE". So can anyone give me any ideas?
Hope to receive some replies for this problem, i say thanks very much in advance.
Have a nice day.

EXECUTE IMMEDIATE command is used to execute Dynamic SQL statements and not the one that you have used here. From your SELECT statement, I could say since there are many columns, you can use a CURSOR rather using INTO clause. A single CURSOR will hold all the columns and you can LOOP through Cursor to perform required operations on each record.
Sep 12 '07 #2
trakal
17
EXECUTE IMMEDIATE command is used to execute Dynamic SQL statements and not the one that you have used here. From your SELECT statement, I could say since there are many columns, you can use a CURSOR rather using INTO clause. A single CURSOR will hold all the columns and you can LOOP through Cursor to perform required operations on each record.
Hello amitpatel66
Thanks alot for your answer. Yes sure, i can use the cursor. But my project is not to use that because this procedure will be used with the application writing by C#.
Because we use the procedure by using the OracleCommand and to read the data by OracleDataReader of ODP.Net. So we don't want to create the cursor in the server (oracle).
do you have any suggestions?
i'm ready to answer you all the questions, if my explication is not enought to understand.

Thanks in advance
ps: may you send me the reference to understand more about that?
Sep 12 '07 #3
debasisdas
8,127 Expert 4TB
why you need to use EXECUTE IMMEDIATE for this.

and since you are only selecting ,why u need a procedure.

why not execute the SQL query directly.
Sep 12 '07 #4
trakal
17
why you need to use EXECUTE IMMEDIATE for this.

and since you are only selecting ,why u need a procedure.

why not execute the SQL query directly.
1. I use "EXECUTE IMMEDIATE" as i wrote before that this procedure is not compiled without this command.
2. This procedure is very important for my application console writing in C#.
In my application, i create a method called LoadById(string id). This methode use this procedure to get the data from the Oracle database. For example, i use this method by using the parameter "id", so this parameter's value will be used for the parameter (input type) of the procedure. One time the procedure is executed, so the method will use the OracleDataReader to get the result of the procedure.
3.the execution of SQL Query is not required for my application. the objectif of my application is to use the procedure to get the data from Oracle database.

Hope that i answer for your question.
thanks in advance for your help.
Sep 12 '07 #5
Saii
145 Expert 100+
you can directly call this select statement in UI and assign to resultset.
Sep 12 '07 #6
trakal
17
you can directly call this select statement in UI and assign to resultset.
Hello,
As i said recently that my application need to use the procedure in the Oracle Server and display the result in client. We don't want to use the query directly.
All the method, that we use in the application (in C#), call the procedure to display the data.
Thanks before for all and so welcome for all your suggestions.
Sep 13 '07 #7
Saii
145 Expert 100+
Add an OUT parameter to your procedure of type SYS_REFCURSOR(9i onwards).
Open refcursor for <your query>;
Handle OUT refcursor resultset in UI.
Sep 13 '07 #8
trakal
17
Hello Saii and all readers,
Sorry that i couldn't have a good explaination in english. I try now to re-ask the question in another way. here are my problems.
My application is writed in C#, use ODP.Net and call the stored procedures in Oracle database (the procedures are created in the type of method CRUD "Create, Read, Update and Delete").

In fact, i want to create a procedure to replace the select query such the example below. The procedure have a parameter in input named "Id".

*****************************************
OracleCommand cmd = conn.CreateCommand();
cmd.CommandText = "SELECT DISTINCT Id, Name from \"Employee\" where \"Id\" = 3";
cmd.CommandType = CommandType.Text;
OracleDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
Console.WriteLine(reader.GetString(0));
Console.WriteLine(reader.GetString(1));
}
*****************************************

Do you have any ideas for that?
So thanks in advance for your help.
Trakal
Sep 14 '07 #9
Saii
145 Expert 100+
Hello Saii and all readers,
Sorry that i couldn't have a good explaination in english. I try now to re-ask the question in another way. here are my problems.
My application is writed in C#, use ODP.Net and call the stored procedures in Oracle database (the procedures are created in the type of method CRUD "Create, Read, Update and Delete").

In fact, i want to create a procedure to replace the select query such the example below. The procedure have a parameter in input named "Id".

*****************************************
OracleCommand cmd = conn.CreateCommand();
cmd.CommandText = "SELECT DISTINCT Id, Name from \"Employee\" where \"Id\" = 3";
cmd.CommandType = CommandType.Text;
OracleDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
Console.WriteLine(reader.GetString(0));
Console.WriteLine(reader.GetString(1));
}
*****************************************

Do you have any ideas for that?
So thanks in advance for your help.
Trakal
Create the procedure with OUT refcursor in Oracle. Then call that procedure in you UI code. I am not sure about the syntax in C#. maybe something like CommandType = CommandType.StoredProcedure and then handle the paramters and their direction(input and output)
hope that helps!!!
Sep 14 '07 #10
trakal
17
Hello Saii and all the reader,
So thanks alot for your helps Saii, it's so helpful. i can now solve my problem as your proposition by creating the procedure with OUT refcursor in Oracle and (Id) IN number.
One time again so thanks.
Trakal
Sep 17 '07 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Martin | last post by:
Hi I'm having trouble with the script below that it just won't do a correct ORDER BY for a date field. When executing the two SELECT TOP statements on their own the records are sorted...
10
by: JMorrell | last post by:
First post to this community so am not sure if this is the correct place. Here goes. I have a MS Access db that keeps track of employees sick and annual leave balances. In it, I have a report,...
24
by: clare at snyder.on.ca | last post by:
I have a SQL query I need to design to select name and email addresses for policies that are due and not renewed in a given time period. The problem is, the database keeps the information for every...
18
by: Terry Holland | last post by:
I have an asp.net (1.1) application that connects to a SQL server 2000 db. I have a stored procedure in my db that out puts data in xml format. What I need to be able to do is display that xml...
6
by: Fuzzydave | last post by:
I am back developing futher our Python/CGI based web application run by a Postgres DB and as per usual I am having some issues. It Involves a lot of Legacy code. All the actual SQL Querys are...
8
by: nick02895 | last post by:
I am not a programmer, just putting bits and pieces I've found on the net. I am missing something here, can you help? The "publishcityonline" checkbox is not sending the required 0 or 1 to mysql...
3
by: vozzek | last post by:
Hi everyone, I'm very new to MySQL, so please bear with me. I have a shopping cart table called 'tbl_cart', and I need to display it's contents on my View Cart page. This is no problem. ...
1
by: HSXWillH | last post by:
I hope my question here is clear. I have a table GovVotes that contains the following fields: Year/State/ElectionType/Candidate/Party/PopularVotes. Via net-searching, I found a code for a query...
1
ssnaik84
by: ssnaik84 | last post by:
Hi Guys, Last year I got a chance to work with R&D team, which was working on DB scripts conversion.. Though there is migration tool available, it converts only tables and constraints.. Rest of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.