oracle 상용 함수, sybase 상용 함수
20796 단어 Oacle
oracle -----------------------------------------------
SQL
1.ASCII
;
SQL> select ascii(’A’) A,ascii(’a’) a,ascii(’0’) zero,ascii(’ ’) space from dual;
A A ZERO SPACE
--------- --------- --------- ---------
65 97 48 32
2.CHR
, ;
SQL> select chr(54740) zhao,chr(65) chr65 from dual;
ZH C
-- -
A
3.CONCAT
;
SQL> select concat(’010-’,’88888888’)||’ 23’ from dual;
----------------
010-88888888 23
4.INITCAP
;
SQL> select initcap(’smith’) upp from dual;
UPP
-----
Smith
5.INSTR(C1,C2,I,J)
, ;
C1
C2
I , 1
J , 1
SQL> select instr(’oracle traning’,’ra’,1,2) instring from dual;
INSTRING
---------
9
6.LENGTH
;
SQL> select name,length(name),addr,length(addr),sal,length(to_char(sal)) from gao.nchar_tst;
NAME LENGTH(NAME) ADDR LENGTH(ADDR) SAL LENGTH(TO_CHAR(SAL))
------ ------------ ---------------- ------------ --------- --------------------
3 6 9999.99 7
7.LOWER
,
SQL> select lower(’AaBbCcDd’)AaBbCcDd from dual;
AABBCCDD
--------
aabbccdd
8.UPPER
,
SQL> select upper(’AaBbCcDd’) upper from dual;
UPPER
--------
AABBCCDD
9.RPAD LPAD( )
RPAD
LPAD
SQL> select lpad(rpad(’gao’,10,’*’),17,’*’)from dual;
LPAD(RPAD(’GAO’,1
-----------------
*******gao*******
*
10.LTRIM RTRIM
LTRIM
RTRIM
SQL> select ltrim(rtrim(’ gao qian jing ’,’ ’),’ ’) from dual;
LTRIM(RTRIM(’
-------------
gao qian jing
11.SUBSTR(string,start,count)
, start , count
SQL> select substr(’13088888888’,3,8) from dual;
SUBSTR(’
--------
08888888
12.REPLACE(’string’,’s1’,’s2’)
string
s1
s2
SQL> select replace(’he love you’,’he’,’i’) from dual;
REPLACE(’H
----------
i love you
13.SOUNDEX
SQL> create table table1(xm varchar(8));
SQL> insert into table1 values(’weather’);
SQL> insert into table1 values(’wether’);
SQL> insert into table1 values(’gao’);
SQL> select xm from table1 where soundex(xm)=soundex(’weather’);
XM
--------
weather
wether
14.TRIM(’s’ from ’string’)
LEADING
TRAILING
,
15.ABS
SQL> select abs(100),abs(-100) from dual;
ABS(100) ABS(-100)
--------- ---------
100 100
16.ACOS
SQL> select acos(-1) from dual;
ACOS(-1)
---------
3.1415927
17.ASIN
SQL> select asin(0.5) from dual;
ASIN(0.5)
---------
.52359878
18.ATAN
SQL> select atan(1) from dual;
ATAN(1)
---------
.78539816
19.CEIL
SQL> select ceil(3.1415927) from dual;
CEIL(3.1415927)
---------------
4
20.COS
SQL> select cos(-3.1415927) from dual;
COS(-3.1415927)
---------------
-1
21.COSH
SQL> select cosh(20) from dual;
COSH(20)
---------
242582598
22.EXP
e n
SQL> select exp(2),exp(1) from dual;
EXP(2) EXP(1)
--------- ---------
7.3890561 2.7182818
23.FLOOR
SQL> select floor(2345.67) from dual;
FLOOR(2345.67)
--------------
2345
24.LN
SQL> select ln(1),ln(2),ln(2.7182818) from dual;
LN(1) LN(2) LN(2.7182818)
--------- --------- -------------
0 .69314718 .99999999
25.LOG(n1,n2)
n1 n2
SQL> select log(2,1),log(2,4) from dual;
LOG(2,1) LOG(2,4)
--------- ---------
0 2
26.MOD(n1,n2)
n1 n2
SQL> select mod(10,3),mod(3,3),mod(2,3) from dual;
MOD(10,3) MOD(3,3) MOD(2,3)
--------- --------- ---------
1 0 2
27.POWER
n1 n2
SQL> select power(2,10),power(3,3) from dual;
POWER(2,10) POWER(3,3)
----------- ----------
1024 27
28.ROUND TRUNC
SQL> select round(55.5),round(-55.4),trunc(55.5),trunc(-55.5) from dual;
ROUND(55.5) ROUND(-55.4) TRUNC(55.5) TRUNC(-55.5)
----------- ------------ ----------- ------------
56 -55 55 -55
29.SIGN
n , 0 1, 0 -1, 0 0
SQL> select sign(123),sign(-100),sign(0) from dual;
SIGN(123) SIGN(-100) SIGN(0)
--------- ---------- ---------
1 -1 0
30.SIN
SQL> select sin(1.57079) from dual;
SIN(1.57079)
------------
1
31.SIGH
SQL> select sin(20),sinh(20) from dual;
SIN(20) SINH(20)
--------- ---------
.91294525 242582598
32.SQRT
n
SQL> select sqrt(64),sqrt(10) from dual;
SQRT(64) SQRT(10)
--------- ---------
8 3.1622777
33.TAN
SQL> select tan(20),tan(10) from dual;
TAN(20) TAN(10)
--------- ---------
2.2371609 .64836083
34.TANH
n
SQL> select tanh(20),tan(20) from dual;
TANH(20) TAN(20)
--------- ---------
1 2.2371609
35.TRUNC
SQL> select trunc(124.1666,-2) trunc1,trunc(124.16666,2) from dual;
TRUNC1 TRUNC(124.16666,2)
--------- ------------------
100 124.16
36.ADD_MONTHS
SQL> select to_char(add_months(to_date(’199912’,’yyyymm’),2),’yyyymm’) from dual;
TO_CHA
------
200002
SQL> select to_char(add_months(to_date(’199912’,’yyyymm’),-2),’yyyymm’) from dual;
TO_CHA
------
199910
37.LAST_DAY
SQL> select to_char(sysdate,’yyyy.mm.dd’),to_char((sysdate)+1,’yyyy.mm.dd’) from dual;
TO_CHAR(SY TO_CHAR((S
---------- ----------
2004.05.09 2004.05.10
SQL> select last_day(sysdate) from dual;
LAST_DAY(S
----------
31-5 -04
38.MONTHS_BETWEEN(date2,date1)
date2-date1
SQL> select months_between(’19-12 -1999’,’19-3 -1999’) mon_between from dual;
MON_BETWEEN
-----------
9
SQL>selectmonths_between(to_date(’2000.05.20’,’yyyy.mm.dd’),to_date(’2005.05.20’,’yyyy.mm.dd’)) mon_betw from dual;
MON_BETW
---------
-60
39.NEW_TIME(date,’this’,’that’)
this =other
SQL> select to_char(sysdate,’yyyy.mm.dd hh24:mi:ss’) bj_time,to_char(new_time
2 (sysdate,’PDT’,’GMT’),’yyyy.mm.dd hh24:mi:ss’) los_angles from dual;
BJ_TIME LOS_ANGLES
------------------- -------------------
2004.05.09 11:05:32 2004.05.09 18:05:32
40.NEXT_DAY(date,’day’)
date x
SQL> select next_day(’18-5 -2001’,’ ’) next_day from dual;
NEXT_DAY
----------
25-5 -01
41.SYSDATE
SQL> select to_char(sysdate,’dd-mm-yyyy day’) from dual;
TO_CHAR(SYSDATE,’
-----------------
09-05-2004
trunc(date,fmt) , fmt=’mi’ ,
SQL> select to_char(trunc(sysdate,’hh’),’yyyy.mm.dd hh24:mi:ss’) hh,
2 to_char(trunc(sysdate,’mi’),’yyyy.mm.dd hh24:mi:ss’) hhmm from dual;
HH HHMM
------------------- -------------------
2004.05.09 11:00:00 2004.05.09 11:17:00
42.CHARTOROWID
ROWID
SQL> select rowid,rowidtochar(rowid),ename from scott.emp;
ROWID ROWIDTOCHAR(ROWID) ENAME
------------------ ------------------ ----------
AAAAfKAACAAAAEqAAA AAAAfKAACAAAAEqAAA SMITH
AAAAfKAACAAAAEqAAB AAAAfKAACAAAAEqAAB ALLEN
AAAAfKAACAAAAEqAAC AAAAfKAACAAAAEqAAC WARD
AAAAfKAACAAAAEqAAD AAAAfKAACAAAAEqAAD JONES
43.CONVERT(c,dset,sset)
sset dset
SQL> select convert(’strutz’,’we8hp’,’f7dec’) "conversion" from dual;
conver
------
strutz
44.HEXTORAW
45.RAWTOHEXT
46.ROWIDTOCHAR
ROWID
47.TO_CHAR(date,’format’)
SQL> select to_char(sysdate,’yyyy/mm/dd hh24:mi:ss’) from dual;
TO_CHAR(SYSDATE,’YY
-------------------
2004/05/09 21:14:41
48.TO_DATE(string,’format’)
ORACLE
49.TO_MULTI_BYTE
SQL> select to_multi_byte(’ ’) from dual;
TO
--
50.TO_NUMBER
SQL> select to_number(’1999’) year from dual;
YEAR
---------
1999
51.BFILENAME(dir,file)
SQL>insert into file_tb1 values(bfilename(’lob_dir1’,’image1.gif’));
52.CONVERT(’x’,’desc’,’source’)
x source desc
SQL> select sid,serial#,username,decode(command,
2 0,’none’,
3 2,’insert’,
4 3,
5 ’select’,
6 6,’update’,
7 7,’delete’,
8 8,’drop’,
9 ’other’) cmd from v$session where type!=’background’;
SID SERIAL# USERNAME CMD
--------- --------- ------------------------------ ------
1 1 none
2 1 none
3 1 none
4 1 none
5 1 none
6 1 none
7 1275 none
8 1275 none
9 20 GAO select
10 40 GAO none
53.DUMP(s,fmt,start,length)
DUMP fmt VARCHAR2
SQL> col global_name for a30
SQL> col dump_string for a50
SQL> set lin 200
SQL> select global_name,dump(global_name,1017,8,5) dump_string from global_name;
GLOBAL_NAME DUMP_STRING
------------------------------ --------------------------------------------------
ORACLE.WORLD Typ=1 Len=12 CharacterSet=ZHS16GBK: W,O,R,L,D
54.EMPTY_BLOB() EMPTY_CLOB()
55.GREATEST
, .
SQL> select greatest(’AA’,’AB’,’AC’) from dual;
GR
--
AC
SQL> select greatest(’ ’,’ ’,’ ’) from dual;
GR
--
56.LEAST
SQL> select least(’ ’,’ ’,’ ’) from dual;
LE
--
57.UID
SQL> show user
USER "GAO"
SQL> select username,user_id from dba_users where user_id=uid;
USERNAME USER_ID
------------------------------ ---------
GAO 25
58.USER
SQL> select user from dual;
USER
------------------------------
GAO
59.USEREVN
,opt :
ENTRYID,SESSIONID,TERMINAL,ISDBA,LABLE,LANGUAGE,CLIENT_INFO,LANG,VSIZE
ISDBA DBA true
SQL> select userenv(’isdba’) from dual;
USEREN
------
FALSE
SQL> select userenv(’isdba’) from dual;
USEREN
------
TRUE
SESSION
SQL> select userenv(’sessionid’) from dual;
USERENV(’SESSIONID’)
--------------------
152
ENTRYID
SQL> select userenv(’entryid’) from dual;
USERENV(’ENTRYID’)
------------------
0
INSTANCE
INSTANCE
SQL> select userenv(’instance’) from dual;
USERENV(’INSTANCE’)
-------------------
1
LANGUAGE
SQL> select userenv(’language’) from dual;
USERENV(’LANGUAGE’)
----------------------------------------------------
SIMPLIFIED CHINESE_CHINA.ZHS16GBK
LANG
SQL> select userenv(’lang’) from dual;
USERENV(’LANG’)
----------------------------------------------------
ZHS
TERMINAL
SQL> select userenv(’terminal’) from dual;
USERENV(’TERMINA
----------------
GAO
VSIZE(X)
X ( )
SQL> select vsize(user),user from dual;
VSIZE(USER) USER
----------- ------------------------------
6 SYSTEM
60.AVG(DISTINCT|ALL)
all ,distinct
SQLWKS> create table table3(xm varchar(8),sal number(7,2));
。
SQLWKS> insert into table3 values(’gao’,1111.11);
SQLWKS> insert into table3 values(’gao’,1111.11);
SQLWKS> insert into table3 values(’zhu’,5555.55);
SQLWKS> commit;
SQL> select avg(distinct sal) from gao.table3;
AVG(DISTINCTSAL)
----------------
3333.33
SQL> select avg(all sal) from gao.table3;
AVG(ALLSAL)
-----------
2592.59
61.MAX(DISTINCT|ALL)
,ALL ,DISTINCT ,
SQL> select max(distinct sal) from scott.emp;
MAX(DISTINCTSAL)
----------------
5000
62.MIN(DISTINCT|ALL)
,ALL ,DISTINCT ,
SQL> select min(all sal) from gao.table3;
MIN(ALLSAL)
-----------
1111.11
63.STDDEV(distinct|all)
,ALL ,DISTINCT
SQL> select stddev(sal) from scott.emp;
STDDEV(SAL)
-----------
1182.5032
SQL> select stddev(distinct sal) from scott.emp;
STDDEV(DISTINCTSAL)
-------------------
1229.951
64.VARIANCE(DISTINCT|ALL)
SQL> select variance(sal) from scott.emp;
VARIANCE(SAL)
-------------
1398313.9
65.GROUP BY
SQL> select deptno,count(*),sum(sal) from scott.emp group by deptno;
DEPTNO COUNT(*) SUM(SAL)
--------- --------- ---------
10 3 8750
20 5 10875
30 6 9400
66.HAVING
SQL> select deptno,count(*),sum(sal) from scott.emp group by deptno having count(*)>=5;
DEPTNO COUNT(*) SUM(SAL)
--------- --------- ---------
20 5 10875
30 6 9400
SQL> select deptno,count(*),sum(sal) from scott.emp having count(*)>=5 group by deptno ;
DEPTNO COUNT(*) SUM(SAL)
--------- --------- ---------
20 5 10875
30 6 9400
67.ORDER BY
SQL> select deptno,ename,sal from scott.emp order by deptno,sal desc;
DEPTNO ENAME SAL
--------- ---------- ---------
10 KING 5000
10 CLARK 2450
10 MILLER 1300
20 SCOTT 3000
20 FORD 3000
20 JONES 2975
20 ADAMS 1100
20 SMITH 800
30 BLAKE 2850
30 ALLEN 1600
30 TURNER 1500
30 WARD 1250
30 MARTIN 1250
30 JAMES 950
sybase ------------
Sybase
Sybase
datalength(char_expr)
char_expr ,
substring(expression,start,length)
right(char_expr,int_expr)
char_expr int_expr
upper(char_expr)
char_expr
lower(char_expr)
char_expr
space(int_expr)
int_expr
replicate(char_expr,int_expr)
char_expr,int_expr
stuff(expr1,start,length,expr2)
expr2 epxr1 start length
reverse(char_expr)
char_expr
ltrim(char_expr)
rtrim(char_expr)
ascii(char_expr)
char_expr ASCII
char(int_expr)
ASCII
str(float_expr[,length[,decimal]])
soundex(char_expr)
char_expr soundex
difference(char_expr1,char_expr2)
soundex
charindex(char_expr,expression)
char_expr , 0
patindex("%pattern%",expression)
, 0
datalength
soundex
difference 0-4 ,0 ,4
%
_ ( )
[] , "OR"
[ABG] A,B,G
[A-C] A,B,C
[A-CE-G] A,B,C,E,F,G
[^ABG] A,B,G
[^A-C] A,B,C
escape
。
ANSI-89 SQL escape
,[] , :
select * from test_tab
where description like "%20[%]%"
:
like char_expression escape escape_character
select * from test_tab
where description like "%20#%%" escape "#"
+
select au_laname+","+au_fname from authors
abs(numeric_expr)
ceiling(numeric_expr)
exp(float_expr)
floor(numeric_expr)
pi()
3.1415926
power(numeric_expr,power)
numeric_expr power
rand([int_expr])
0-1 ,
round(numeric_expr,int_expr)
int_expr
sign(int_expr)
+1, 0 -1
sqrt(float_expr)
SQL SERVER
getdate()
datename(datepart,date_expr)
date_expr ,
datepart(datepart,date_expr)
date_expr
datediff(datepart,date_expr1,date_expr2)
date_expr2-date_expr1, datepart
dateadd(datepart,number,date_expr)
, date_expr number
datepart
yy 1753-9999
qq 1-4
mm 1-12
dy 1-366
dd 1-31
wk 1-54
dw 1-7(1=sunday)
hh 0-23
mi 0-59
ss 0-59
ms 0-999
:
select invoice_no,
datediff(dd,date_shipped,getdate())
from invoices
where balance_due>0
convert
convert(datetype [(length)],expression)
select "Advance="+convert(char(12),advance)
from titles
convert(datetype[(length)],expression,format)
format , :
0 or 100 mon dd yyy hh:miAM(or PM)
1 101 mm/dd/yy
2 102 yy.mm.dd
3 103 dd/mm/yy
4 104 dd.mm.yy
5 105 dd-mm-yy
6 106 dd mon yy
7 107 mon dd,yy
8 108 hh:mm:ss
9 or 109 mon dd,yyyy hh:mi:ss:mmmAM(or PM)
10 110 mm-dd-yy
11 111 yy/mm/dd
12 112 yymmdd
host_id() ID
host_name()
suser_id(["login_name"]) SQL Server ID
suser_name([server_user_id]) SQL Server
user_id(["name_in_db"]) ID
user_name([user_id])
user
show_role()
db_id(["db_name"]) ID
db_name([db_id])
object_id("objname") ID
object_name(obj_id])
col_name(obj_id,col_id)
col_length("objname","colname")
index_col("objname",index_id,key#)
valid_name(char_expr) char_expr , 0
datalength(expression) expression
tsequal(timestamp1,timestamp2) , ,
isnull()
isnull
:
select avg(isnull(total_order,$0))
from invoices
str_replace (필드, 대체 문자, 대체 문자)
Sybase 데이터베이스 에서 필드 부분 을 바 꾸 는 SQL 문 Sql Server 에서 특정한 데이터 시트 table 1 의 Email 필드 의 모든 값 중 "@" 을 "\ #" 로 바 꾸 려 면 다음 과 같이 사용 할 수 있 습 니 다. Sql 구문: update table1 set Email=replace(Email,'@','#') where Email like '%@%' Sybase 에서 데이터베이스 에서 이 작업 을 수행 하려 면 strreplace 가 아니 라 replace 입 니 다.위의 그 요 구 는 Sybase 에서 이 루어 집 니 다. 구조의 Sql 문 구 는 다음 과 같 습 니 다: update table 1 set Email = strreplace(Email,'@','#') where Email like '%@%'
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
activemq 5.5 의 입문 은 설치, 시작, 데이터베이스 지속 화 를 포함한다Apache ActiveMQ 5.5.0 은 주로 유지보수 버 전 으로 130 개가 넘 는 문 제 를 복 구 했 으 며 대부분 bug 와 개선 이 었 다. Improved performance for offline d...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.