- 1
Connect to Oracle SQL*Plus. Click "Start," "All Programs" and "SQLPlus."
- 2
Login to the SQL*Plus. Once the Oracle SQL*Plus Dialogue Box appears, enter your user name and password, then click "OK."
- 3
Create a Select statement in a PL/SQL program. At the SQL prompt, enter the code:
SQL >
" Set serveroutput on
DECLARE
-- variable declaration
v_prod_name varchar2(80);
BEGIN
-- retrieve the product_name into a variable
SELECT product_name
INTO v_prod_name
FROM product
WHERE product_id = 2;
-- display the product_name to the screen
DBMS_OUTPUT.PUT_LINE (v_prod_name);
END;
/ "
Example of the results obtained from the select statement of a PL/SQL:
pepsi
PL/SQL procedure successfully completed.
5/15/11
How to Create a Select Statement in PL/SQL
When creating a PL/SQL, or Procedural Language for Structured Query Language program, you will always have a "Begin" and "End" statement and may have an optional "Declare" and "Exception" statement. In addition, variables, loops or logic control may also be incorporated. When creating a basic Select Statement in PL/SQL, the standard "Select" and "From" statements are used and may include the optional "Into," "Where," "Having" or "Order By" clauses. All of these optional clauses assist with data retrieval.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment