The program written below assigns a string to a variable and prints it.
Before writing your PL/SQL block set your serveroutput on in Sql plus. We set serveroutput on, so that we could see output on sql plus.
SET SERVEROUTPUT ONNow we will write the block/program.
DECLARE
v_name varchar2(20);
BEGIN
v_name:='John';
DBMS_OUTPUT.PUT_LINE('My name is '||v_name);
END;
/
Above block is divided into 3 sections, i.e.
DECLARE: We have declared a variable "v_name" in this section.
BEGIN: In this section we assign a value to v_name and later print it using PUT_LINE procedure of DBMS_OUTPUT package. "||" is the concatenation operator as we have "+'' in java or "." in PHP. Also notice the line of code after BEGIN, we use ":=" for assignment in oracle instead of "=".
END: END is used to end the block and after that "/" is used to execute the block.
If everything goes right, you will see the output "John" on Sql plus.
No comments:
Post a Comment