450 likes | 455 Views
Learn how to create and use anonymous blocks in SQLPlus, including inserting records, updating rows, and using bind and substitution variables.
E N D
Chapter 2Anonymous Block DasarPemrograman Basis Data MI2163
Block Types • unnamed blocks • are not stored in the database
Create An Anonymous Block • Type the anonymous block in SQLPlus environment: SQL> BEGIN 2 DBMS_OUTPUT.PUT_LINE('Hello World'); 3 END; 4 / Hello World PL/SQL procedure successfully completed.
Example of Bind Variables in SQLPlus Environment SQL> VARIABLE v_word1 VARCHAR2(5); SQL> VARIABLE v_word2 VARCHAR2(5); SQL> BEGIN 2 :v_word1:='Hello'; 3 :v_word2:='World'; 4 DBMS_OUTPUT.PUT_LINE(:v_word1||' '||:v_word2); 5 END; 6 / Hello World PL/SQL procedure successfully completed.
Example of Substitution Variables in SQLPlus Environment SQL> -- input nilaimenggunakanvariabelsubstitusi SQL> DECLARE 2 v_word1 VARCHAR2(5):= '&input1'; 3 v_word2 VARCHAR2(5):= '&input2'; 4 BEGIN 5 DBMS_OUTPUT.PUT_LINE(v_word1||' '||v_word2); 6 END; 7 / Enter value for input1: Hello Enter value for input2: World Hello World PL/SQL procedure successfully completed.