473,385 Members | 1,622 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,385 software developers and data experts.

bind variable

35
can i use the bind variable inside a procedure
and the query like update emp set empname=:name where empno=:no;

but i work like update emp set empname=&name where empno=&no inside procedures it works properly

Expand|Select|Wrap|Line Numbers
  1. declare
  2. i number:=0;
  3. begin
  4. while i<3
  5. loop
  6. update dept set empno=&empno where dname='&deptname';
  7. i:=i+1;
  8. end loop;
  9. end;
but here it prompts empno and deptname for first time and then uses it for all three times of the loop.how do i give three diff values for each of the three execution
Dec 14 '07 #1
5 2179
debasisdas
8,127 Expert 4TB
If you want to pass 3 different values ,why using loop. directly execute three different SQL statments.
Dec 15 '07 #2
femina
35
no sir,
is there any provision to get different input from user for every time i enter the loop and dipslay the new value.
example
Expand|Select|Wrap|Line Numbers
  1.  declare
  2.    eno number(4);
  3.    begin
  4.        for i in 1..5
  5.         loop
  6.             eno:=&eno;
  7.            dbms_output.put_line(eno);
  8.        end loop;
  9.    end;
here i give an input 1 , but thats taken granted for all 5 times and it displays 1 1 1 1 1 but i want to give 5 differnet numbers each time i enter the loop.
please help me to know whether this is possible or not
If you want to pass 3 different values ,why using loop. directly execute three different SQL statments.
Dec 17 '07 #3
amitpatel66
2,367 Expert 2GB
no sir,
is there any provision to get different input from user for every time i enter the loop and dipslay the new value.
example
Expand|Select|Wrap|Line Numbers
  1.  declare
  2.    eno number(4);
  3.    begin
  4.        for i in 1..5
  5.         loop
  6.             eno:=&eno;
  7.            dbms_output.put_line(eno);
  8.        end loop;
  9.    end;
here i give an input 1 , but thats taken granted for all 5 times and it displays 1 1 1 1 1 but i want to give 5 differnet numbers each time i enter the loop.
please help me to know whether this is possible or not
No, that is not possible unless you make use of 5 different variables.
Alternative could be to use start and end value as an input parameter. Say you want employees whose empno is between 1 and 8 then you can use this code as shown below:

Expand|Select|Wrap|Line Numbers
  1. SQL> ed
  2. Wrote file afiedt.buf
  3.  
  4.   1  declare
  5.   2  TYPE empdet IS TABLE OF emp%ROWTYPE;
  6.   3  empd empdet;
  7.   4  eno number(4);
  8.   5     eno1 NUMBER;
  9.   6     begin
  10.   7              eno:=&1;
  11.   8              eno1:=&2;
  12.   9  SELECT * BULK COLLECT INTO empd FROM emp WHERE empno between eno AND eno1;
  13.  10  FOR I IN 1..empd.COUNT LOOP
  14.  11  DBMS_OUTPUT.PUT_LINE(empd(i).empno||','||empd(i).ename);
  15.  12  END LOOP;
  16.  13*    end;
  17. SQL> /
  18. Enter value for 1: 1
  19. old   7:             eno:=&1;
  20. new   7:             eno:=1;
  21. Enter value for 2: 2
  22. old   8:             eno1:=&2;
  23. new   8:             eno1:=2;
  24. 1,AAAA
  25. 2,AAAA
  26.  
  27. PL/SQL procedure successfully completed.
  28.  
Dec 17 '07 #4
femina
35
thanks a lot for the reply sir

No, that is not possible unless you make use of 5 different variables.
Alternative could be to use start and end value as an input parameter. Say you want employees whose empno is between 1 and 8 then you can use this code as shown below:

Expand|Select|Wrap|Line Numbers
  1. SQL> ed
  2. Wrote file afiedt.buf
  3.  
  4.   1  declare
  5.   2  TYPE empdet IS TABLE OF emp%ROWTYPE;
  6.   3  empd empdet;
  7.   4  eno number(4);
  8.   5     eno1 NUMBER;
  9.   6     begin
  10.   7              eno:=&1;
  11.   8              eno1:=&2;
  12.   9  SELECT * BULK COLLECT INTO empd FROM emp WHERE empno between eno AND eno1;
  13.  10  FOR I IN 1..empd.COUNT LOOP
  14.  11  DBMS_OUTPUT.PUT_LINE(empd(i).empno||','||empd(i).ename);
  15.  12  END LOOP;
  16.  13*    end;
  17. SQL> /
  18. Enter value for 1: 1
  19. old   7:             eno:=&1;
  20. new   7:             eno:=1;
  21. Enter value for 2: 2
  22. old   8:             eno1:=&2;
  23. new   8:             eno1:=2;
  24. 1,AAAA
  25. 2,AAAA
  26.  
  27. PL/SQL procedure successfully completed.
  28.  
Dec 17 '07 #5
amitpatel66
2,367 Expert 2GB
thanks a lot for the reply sir
You are welcome:)

MODERATOR
Dec 17 '07 #6

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

Similar topics

2
by: Jack | last post by:
Hi All, What is the PHP equivilent of Oracle bind variables in a SQL statement, e.g. select x from y where z=:parameter Which in asp/jsp would be followed by some statements to bind a value...
1
by: Achille Carette | last post by:
Hello all, I noticed a difference in the explain plans between JDBC using bind variables (PreparedStatement) and SQLPlus for the same query. The query made through JDBC using bind variables...
1
by: Daniel Roy | last post by:
Hi gurus, I just started to look at a very slow-running SQL statement generated by an application (Siebel). I spooled the SQL from the application, replaced the bind variables by their values, and...
1
by: Hermes | last post by:
Hi all, I'm using bind variables in sql in some asp pages, but something strange is happening with a few of the pages. I'm trying to add a bind variable to do an arrange and order of the output....
3
by: AH | last post by:
Hi all, I noticed this strange behavior; I created a new control (example inherits from textbox) and add a new property, then I bind this new property to a field in my dataTable in a dataSet....
0
by: lnd | last post by:
A few question regarding PostgreSQL handling of queries: - Is each query submitted parsed and planned even if it is identical to a query submitted before? For example, 10 queries "select * from...
12
by: Monty | last post by:
Hope this is an easy one: How can I bind a text on a form to a an integer variable? Possible? Thanks!
2
by: duancg | last post by:
Hi, I wonder if someone could help since I wasn't able to find the answer through search. I have a simple .aspx page that shows data from a database table, as a table in UI. Now the data uses...
1
by: David C | last post by:
I have a DataList that displays photos and is bound to a list of files. Is there a way to combine the value of a variable (strpath) with the # Bind(...) in the ImageURL field. Below is what I...
3
by: Giovanni Gherdovich | last post by:
Hello, in the following code I have a pointer (to function), say p, of type double (*)(double, double, void*) and I try to fix the second argument of the function *p to a given value (using...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.