sqlplus變數定義, 呼叫過程
oracle定義變數(常量)常用:declare、define、variable
1)define、variable用於sqlplus中,在整個sqlplus連線中都生效(until exit,disc是cut down session),而declare用於pl/sql中。
2)variable(var)和define區別在於,前者用於繫結變數,後者是用於&或&&進行變數替換(使用場合,拿來當輸入引數)。
define
SQL> define x='SCOTT'
SQL> define
DEFINE _DATE = "29-9月 -13" (CHAR)
DEFINE _CONNECT_IDENTIFIER = "myorcl11" (CHAR)
DEFINE _USER = "SYS" (CHAR)
DEFINE _PRIVILEGE = "AS SYSDBA" (CHAR)
DEFINE _SQLPLUS_RELEASE = "1102000100" (CHAR)
DEFINE _EDITOR = "vim" (CHAR)
DEFINE _O_VERSION = "Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options" (CHAR)
DEFINE _O_RELEASE = "1102000100" (CHAR)
DEFINE X = "SCOTT" (CHAR)
SQL> select distinct owner from dba_segments where wner='&x';
old 1: select distinct owner from dba_segments where wner='&x'
new 1: select distinct owner from dba_segments where wner='SCOTT'
OWNER
------------------------------------------------------------
SCOTT
SQL> define
DEFINE _DATE = "29-9月 -13" (CHAR)
DEFINE _CONNECT_IDENTIFIER = "myorcl11" (CHAR)
DEFINE _USER = "SYS" (CHAR)
DEFINE _PRIVILEGE = "AS SYSDBA" (CHAR)
DEFINE _SQLPLUS_RELEASE = "1102000100" (CHAR)
DEFINE _EDITOR = "vim" (CHAR)
DEFINE _O_VERSION = "Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options" (CHAR)
DEFINE _O_RELEASE = "1102000100" (CHAR)
DEFINE X = "SCOTT" (CHAR)
SQL> select distinct owner from dba_segments where wner='&x';
old 1: select distinct owner from dba_segments where wner='&x'
new 1: select distinct owner from dba_segments where wner='SCOTT'
OWNER
------------------------------------------------------------
SCOTT
var
SQL> var y numb
Usage: VAR[IABLE] [ [ NUMBER | CHAR | CHAR (n [CHAR|BYTE]) |
VARCHAR2 (n [CHAR|BYTE]) | NCHAR | NCHAR (n) |
NVARCHAR2 (n) | CLOB | NCLOB | BLOB | BFILE
REFCURSOR | BINARY_FLOAT | BINARY_DOUBLE ] ]
SQL> var y varchar2(20)
SQL> var
variable y
datatype VARCHAR2(20)
SQL> exec :y := 'SCOTT'
PL/SQL procedure successfully completed.
SQL> print :y
Y
-------
SCOTT
SQL> select distinct owner from dba_segments where owner=':y'; --wrong
no rows selected
SQL> select distinct owner from dba_segments where wner=:y;
OWNER
------------------------------------------------------------
SCOTT
Usage: VAR[IABLE] [
VARCHAR2 (n [CHAR|BYTE]) | NCHAR | NCHAR (n) |
NVARCHAR2 (n) | CLOB | NCLOB | BLOB | BFILE
REFCURSOR | BINARY_FLOAT | BINARY_DOUBLE ] ]
SQL> var y varchar2(20)
SQL> var
variable y
datatype VARCHAR2(20)
SQL> exec :y := 'SCOTT'
PL/SQL procedure successfully completed.
SQL> print :y
Y
-------
SCOTT
SQL> select distinct owner from dba_segments where owner=':y'; --wrong
no rows selected
SQL> select distinct owner from dba_segments where wner=:y;
OWNER
------------------------------------------------------------
SCOTT
SQL> variable dba varchar2(30)
SQL> exec :dba := dbms_utility.make_data_block_address(4, 20);
PL/SQL procedure successfully completed.
SQL> print dba
DBA
--------------------------------
16777236
執行儲存過程:(加樓上共4種方法)
法1
BEGINgetDeptCount;END;
法2
EXEC getDeptCount
法3
CALL getDeptCount();
注意:
定義無參儲存過程時,儲存過程名後不能加()
在塊中或是通過EXEC呼叫儲存過程時可以省略()
通過CALL呼叫無參儲存過程必須加上()
引數只能指定型別,不能指定長度精度範圍,可以指定預設值:
varchar2(200) ,只能用varchar2
...PROCEDURE add_deptno(v_deptno IN dept.deptno%TYPE,
v_dname IN VARCHAR2,
v_loc IN dept.loc%TYPE DEFAULT 'BEJING')...
給過程傳遞引數的方法:
1,位置傳遞 exec add_dept(50,'SALES','BEIJING')
2,名稱傳遞 exec add_dept(v_dname=>'SALES',v_deptno=>50,v_loc=>'BEIJING')
3,組合傳遞 exec add_dept(50,v_loc=>'BEIJING,v_dname=>'SALES')
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28859270/viewspace-773572/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- oracle sqr之多個procedure過程變數傳遞及同名變數定義Oracle變數
- Python 動態變數名定義與呼叫Python變數
- Python動態變數名定義與呼叫Python變數
- mysql 儲存過程中變數的定義與賦值操作MySql儲存過程變數賦值
- sqlplus中define定義的常量和variable定義的變數的區別!SQL變數
- sqlplus中的變數定義和簡單使用.txtSQL變數
- extjs特殊用法--js--呼叫變數方法定義前提最先變數要用var定義JS變數
- 在oracle sqlplus中通過new_value及define傳遞或定義變數variableOracleSQL變數
- 如何刪除使用export定義過的變數?Export變數
- 在sqlplus中呼叫in out輸入輸出引數的儲存過程SQL儲存過程
- 變數定義錯誤變數
- 01.變數定義變數
- java呼叫oracle儲存過程的自定義型別(可變陣列)JavaOracle儲存過程型別陣列
- mysql-定時呼叫儲存過程MySql儲存過程
- 變數的定義和使用變數
- oracle 過程函式定義字典Oracle函式
- TCL: 變數和過程variable變數
- c+++變數宣告和定義C++變數
- PHP核心定義變數的方式PHP變數
- nginx內建預定義變數Nginx變數
- 預定義的SQL*Plus變數SQL變數
- grafana如何使用定義的變數Grafana變數
- 恢復出廠設定 Factory Reset 呼叫過程
- 把匿名函式賦值給變數,通過變數來呼叫函式賦值變數
- 把匿名函式賦值給變數,透過變數來呼叫函式賦值變數
- MySQL中變數的定義和變數的賦值使用MySql變數賦值
- Shell程式設計-shell變數2-位置變數和預定義變數程式設計變數
- 你還在用var定義變數嗎?變數
- maven中properties標籤定義變數Maven變數
- C# WebForm定義全域性變數C#WebORM變數
- 【圖文】函式呼叫過程中棧的變化函式
- 儲存過程輸入引數型別定義引起的問題儲存過程型別
- 【OH】SET System Variable Summary SQLPLUS 系統變數設定SQL變數
- Java呼叫儲存過程(帶輸出引數)Java儲存過程
- 動態呼叫帶引數的儲存過程儲存過程
- C++教程-----C++變數型別和變數的定義C++變數型別
- angular中定義全域性變數及全域性變數的使用Angular變數
- 呼叫儲存過程儲存過程