1. 程式人生 > 實用技巧 >Linux安裝zookeeper

Linux安裝zookeeper

//PS:SET SERVEROUTPUT ON;
//DBMS_OUTPUT.PUT_LINE();--輸出
--實現操控程式處理的細節過程

PL/SQL程式以塊(BLOCK)為基本單位,分三部分:宣告部分(用declare開頭)、執行部分(以begin開頭)和異常處理部分(以exception開頭)
--語法格式:
declare
   --宣告部分,可選
  begin
  --執行部分,可選
  exception
  --異常處理部分,可選
  end
  
  
  --識別符號
  
  --分界符
  % --屬性指示符= --賦值操作符
  => --連結操作符
  ..  --
範圍操作符 || --範圍操作符 <space>空格 --資料型別 數值型別: number(p,s) --p表示精度,s是刻度範圍 pls_integer、binary_integer 字元型別: varchar2(maxlength)、char(maxlength)、long 日期型別:date 布林型別:boolean 特殊型別:%type、record、%rowtype %type:宣告一個與指定列相同的資料型別 record:記錄型別 --語法 type record_type is record --
宣告record型別record_type ( var_member1 data_type [not null][:=default_value], ... var_membern data_type [not null] [:=dafault_value] ) record_name record_type --定義變數 %rowtype : 根據結構表中行的結構定義的特殊的資料型別,用來儲存從資料表中檢索到的一行資料 --語法 rowVar_name table_name%rowtype; --rowVar_name:表示儲存一行資料的變數名,table_name 指定表名
-- 變數、常量的定義 語法: <變數名><資料型別>[(長度):=<初始值>];--變數 <常量名> constant <資料型別>:=<常量值>];--變數 ,關鍵字:constant -- 流程控制語句 1.if...then 2.if...then...else 3.if...then...else if... 4.case --迴圈語句 5.loop...exit...end 6.loop...exit when...end 7.while...loop...end 8.for 9.goto --if...then declare age int:=55; begin if age>54 then dbms_output.put_line("退休"); else dbms_output.put_line("不能退休"); end if; end; --case declare season int:=3; aboutinfo varchar2(50); begin case season when 1 then aboutinfo:=season||'季度包括1,2,3月份'; when 2 then aboutinfo:=season||'季度包括1,2,3月份'; else aboutinfo:=season||'不合法'; end case; end; --loop...exit declare sum int:=0; i int:=0; begin loop i:=i+1; sum:=sum+i; exit when i=10; end loop; end; --while...loop...end declare s int:=1; i int:=0; begin while i>10 loop i:=i+1; s:=s*i; end loop; end; -- for declare sum int:=0; begin for i in reverse 1...100 loop if mod(i,2)=0 then sum:=sum+i; end if; end loop; end; ---遊標 宣告遊標 --語法 cursor cur_name(input_parameter1,...) [return ret_type]--可選,返回值型別 is select_sentence --select語句,反覆讀取結果集 --例子: declare cursor cur_emp(var_job in varchar2:='11') is select empno,ename,sal from emp where job=var_job; --開啟遊標 open curso_name; --有引數的要帶引數,預設可以不用帶引數; --讀取遊標 fetch ...into ... --fetch 遊標名稱 into 記錄變數 --關閉遊標 close cursor_name; --隱式遊標(處理資料操縱語句,如update,delete語句) --遊標的屬性 %found:布林型別,如果sql語句影響到一行資料,為trun,否則為false; %notfound :與%found相反; %rowcount:遊標行數 %ISOPEN:遊標是否開啟; 1.寫一段PL/SQL語句,使用loop語句求得前10各自然數的積 declare int i:=0; int s:=1; begin loop i:=i+1; s:=s*i; exit when i=10; end loop; dbms_output.put_line(s): end;