oraclesql长度
⑴ 变更表字段长度的sql语句是什么(Oracle)
oracle变更字段长度的语句如下:
altertable表名modify(字段名,字段类型长度);
注意事项:
如果是增加字段长度,用上述语句是没问题的。
但要是缩减字段长度,如果原表中数据有大于缩减后字段长度的内容,语句会执行失败。
⑵ 在oracle中怎么查询某个字段的长度
select * from 表名 wherelength(nvl(字段,''))=1order by 字段
例如:一个列里面有长短不一的数字如何判断数字的长度
如:I_CODE
使用selectI_CODEfromtablename wherelength(I_CODE)=4。即可算出答案
另外,一个汉颤高茄字在Oracle数据库里占多少字节跟数据库的字符集有关,UTF8时,长度为三。select lengthb('飘') from al 可查询汉字在Oracle数据库念橡里占多少字节
(2)oraclesql长度扩展阅读
查询包含DNO字段,且字段茄察长度<10的表,使用如下函数
select * from user_tab_cols t where t.column_name like '%DNO%' and data_length < 10;
有时候数据库中有很多表包含同一个字段时,要修改表字段长度,可以通过这个查询哪些需要修改。
⑶ oracle如何用sql语句获取varchar2字段的长度
oracle中获取纳塌燃字符串varchar2的长度衫码的方法:
select length(laytitle) from xxx
这洞虚样就可以返回字符串的实际长度。
⑷ ORACLE的SQL书写规范
/**
ORACLE的SQL规范,目的避免SQL执行错误,提高SQL脚本的质量;
一般执行SQL在command模式下,所以每个完整的语句需要在后面加上斜杠("/"),特别是过程或函数必须在其后加上斜杠("/")
多条非过程SQL语句在最后面一条语句后加上斜杠("/"),如insert、update、delete。在执行完基裤辩,做下commit;
例子以表名TEST1说明,注意:create_str使用的varchar2类型,长度5000,如果SQL太长,要调整长度。
*/
declare
create_str varchar2(5000) := 'create table TEST1(ID int,REALNAME varchar2(32))';
count_flag number;
begin
select count(*)
into count_flag
from user_tables
where table_name = 'TEST1';
if count_flag < 1 then
execute immediate create_str;
else
execute immediate 'drop table TEST1';
execute immediate create_str;
--字段注解规范
execute immediate 'COMMENT ON COLUMN "TEST1"."ID" IS ''编号''';
execute immediate 'COMMENT ON COLUMN "TEST1"."REALNAME" IS ''姓名''';
end if;
end;
/
declare
add_str varchar2(5000) := 'alter table TEST1 add NICKNAME varchar(32)';
count_flag number;
begin
select count(*)
into count_flag
from user_tab_columns
where table_name = 'TEST1'
and column_name = 'NICKNAME';
if count_flag < 1 then
execute immediate add_str;
--字段注解规范
execute immediate 'COMMENT ON COLUMN "TEST1"."NICKNAME" IS ''昵称''';
end if;
end;
/
declare
add_str varchar2(5000) := 'alter table TEST1 modify NICKNAME varchar(100)';
count_flag number;
begin
select count(*)
into count_flag
from user_tab_columns
where table_name = 'TEST1'
and column_name = 'NICKNAME';
if count_flag = 1 then
execute immediate add_str;
--字纯肢段搏缺注解规范
execute immediate 'COMMENT ON COLUMN "TEST1"."NICKNAME" IS ''昵称''';
end if;
end;
/
declare
add_str varchar2(5000) := 'alter table TEST1 drop column NICKNAME';
count_flag number;
begin
select count(*)
into count_flag
from user_tab_columns
where table_name = 'TEST1'
and column_name = 'NICKNAME';
if count_flag = 1 then
execute immediate add_str;
end if;
end;
/
declare
create_str varchar2(5000) := 'create index IDX_TEST1_ID on TEST1(id)';
count_flag number;
begin
select count(*) into count_flag from user_indexes where table_name='TEST1' and index_name='IDX_TEST1_ID';
if count_flag < 1 then
execute immediate create_str;
else
execute immediate 'drop index IDX_TEST1_ID';
execute immediate create_str;
end if;
end;
/
declare
create_str varchar2(5000) := 'create sequence SEQ_TEST1 minvalue 1 maxvalue 999999999999 start with 1 increment by 1';
count_flag number;
begin
select count(*) into count_flag from user_sequences where sequence_name='SEQ_TEST1';
if count_flag < 1 then
execute immediate create_str;
else
execute immediate 'drop sequence SEQ_TEST1';
execute immediate create_str;
end if;
end;
/
insert into TEST1
(id, realname, nickname)
select 1, '网名', '网虫'
from al
where not exists (select * from TEST1 where id = 1);
/
update TEST1 set realname='网名', nickname='网虫' where id=1;
/
delete from TEST1 t where t.id=1;
/
⑸ Oracle SQL如何判断一个字段值的长度
判断长度一般用于字符型字段
如果是某个值的长度
selectlength(字段名)from表名
如果是表中这个字段的长度
selectdata_lengthfromuser_tab_columnswheretable_name='表名'andcloumn_name='字段名'
其中后一条语句表名和字段名需要大写
⑹ Oracle数据库表名支持的最大长度是多少
Oracle数据库表名输入标识符,最大长度是30个字符。关于标识符主要有以下几点:
1、所谓标识符,是用户自定义的关键词,比如表名、字段名、视图名、序列名、主键等,因此,数据库表名也属于标识符。
2、标识符是有长度限制的。
3、标识符的最大长度在Oracle中是30个字符。
如果创建包含31个字符的Oracle数据库表名,会显示创建失败。
⑺ oracle动态执行SQL字符串,字符串最大的长度是多少
你好:我知道的是最大可执行长度为6000个字符。通常在procere中sql拼接的时候会有这个问题,一边解决方案是设置function对逻辑分别处理来实现减少sql长度的。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
VAR_DYNAMIC_SQL := 'INSERT INTO RP_TRANS_LOG_MINUTE
(
TRANS_TIME,
TRANS_PROVINCE,
TRANS_TYPE,
SCORE_RANGE,
RULE_NAME,
POLICY_ACTION,
/*新加字段开始*/
CHALLENGE_SUCCESSFUL,
CHALLENGE_AUTH_METHOD,
PRIORITY,---
DESCRIBE,--
IS_USE_DEVICE,--
TRANS_DITCH,
TRANS_OPER_SYSTEM,
TRANS_BROWSER,
FLAGGED,
RESOLUTION,
/*新加字段结束*/
TRANS_NUM,
TRIGGERED_NUM,
TRIGGERED_SUCCESSFUL_NUM,
/*新加字段开始*/
WEB_TRANS_NUM,
MOBILE_TRANS_NUM,
IPAD_TRANS_NUM,
QA_LOGIN_NUM,
SMS_LOGIN_NUM,
CC_LOGIN_NUM,
REGISTRAR_QA_NUM,--***
CREATE_CUSTOMR_FILE_NUM,
ALLOW_TRANS_NUM,
REVIEW_TRANS_NUM,
CHALLENGE_TRANS_NUM,
DENY_TRANS_NUM,
TOTAL_SCORE_RANGE,
TOTAL_AMOUNT
/*新加字段结束*/
)
SELECT
TO_DATE(SUBSTR(TO_CHAR(SYS_CREATION_DATE,''YYYY-MM-DD HH24:MI:SS''),0,16),''YYYY-MM-DD HH24:MI''),
get_province(IP_COUNTRY,IP_CITY,ip_region) AS TRANS_PROVINCE,
GET_NAME_BY_CODE(GET_TOTAL_EVENT_TYPE(T.EVENT_TYPE,T.USER_DEFINED_EVENT_TYPE),''eventType'') AS TRANS_TYPE,
GET_SCORE_RANGE(T.RISK_SCORE) AS RISK_SCORE_RANGE,
NVL(POLICY_RULE_ID,''FALLBACK_RULE'') AS RULE_NAME,
POLICY_ACTION,
CHALLENGE_SUCCESSFUL,
CHALLENGE_AUTH_METHOD,
SUBSTR(GET_RULE_ORDER_ID(ORG_ID,POLICY_RULE_ID),0,INSTR(GET_RULE_ORDER_ID(ORG_ID,POLICY_RULE_ID),''+'')-1),--优先级
SUBSTR(GET_RULE_ORDER_ID(ORG_ID,POLICY_RULE_ID),INSTR(GET_RULE_ORDER_ID(ORG_ID,POLICY_RULE_ID),''-'')+1),--描述
NVL(IS_DEVICE_BOUND,''N''),
CHANNEL_INDICATOR,
OPERATING_SYSTEM,
BROWSER_TYPE,
FLAGGED,
RESOLUTION,
COUNT(1) AS TRANS_NUM,
SUM(CASE WHEN POLICY_ACTION = ''CHALLENGE'' THEN 1 ELSE 0 END) AS TRIGGERED_NUM,
SUM(CASE WHEN POLICY_ACTION = ''CHALLENGE'' AND CHALLENGE_SUCCESSFUL = ''Y'' THEN 1 ELSE 0 END) AS TRIGGERED_SUCCESSFUL_NUM,
SUM(case WHEN CHANNEL_INDICATOR = ''WEB'' then 1 else 0 end ) AS WEB_TRANS_NUM,--WEB交易量
SUM(case WHEN CHANNEL_INDICATOR = ''MOBILE'' then 1 else 0 end ) AS MOBILE_TRANS_NUM,--Mobile交易量
SUM(case WHEN '||get_vale_from_cd1('6','4')||' = ''IPAD'' then 1 else 0 end ) AS IPDA_TRANS_NUM,--Ipad交易量
(SELECT SUM(CASE WHEN T1.ACSPNAME = ''QUESTION'' AND T1.STATUS = ''ACTIVE'' THEN 1 ELSE 0 END) FROM ACSPUSERACCOUNT T1 WHERE TO_DATE(to_char( T1.lastmodified,''yyyy-mm-DD HH24:MI:SS'' ),''yyyy-mm-DD HH24:MI:SS'') > TO_DATE('''||TO_CHAR(VAR_BEGIN_TIME,'YYYY-MM-DD HH24:MI:SS')||''',''YYYY-MM-DD HH24:MI:SS'') AND TO_DATE(to_char( T1.lastmodified,''yyyy-mm-DD HH24:MI:SS'' ),''yyyy-mm-DD HH24:MI:SS'') <= TO_DATE('''||TO_CHAR(VAR_END_TIME,'YYYY-MM-DD HH24:MI:SS')||''',''YYYY-MM-DD HH24:MI:SS'') )AS QA_LOGIN_NUM,
(SELECT SUM(CASE WHEN T1.ACSPNAME = ''SMS'' AND T1.STATUS = ''ACTIVE'' THEN 1 ELSE 0 END) FROM ACSPUSERACCOUNT T1 WHERE TO_DATE(to_char( T1.lastmodified,''yyyy-mm-DD HH24:MI:SS'' ),''yyyy-mm-DD HH24:MI:SS'') > TO_DATE('''||TO_CHAR(VAR_BEGIN_TIME,'YYYY-MM-DD HH24:MI:SS')||''',''YYYY-MM-DD HH24:MI:SS'') AND TO_DATE(to_char( T1.lastmodified,''yyyy-mm-DD HH24:MI:SS'' ),''yyyy-mm-DD HH24:MI:SS'') <= TO_DATE('''||TO_CHAR(VAR_END_TIME,'YYYY-MM-DD HH24:MI:SS')||''',''YYYY-MM-DD HH24:MI:SS''))AS SMS_LOGIN_NUM,
(SELECT SUM(CASE WHEN T1.ACSPNAME = ''CCC'' AND T1.STATUS = ''ACTIVE'' THEN 1 ELSE 0 END) FROM ACSPUSERACCOUNT T1 WHERE TO_DATE(to_char( T1.lastmodified,''yyyy-mm-DD HH24:MI:SS'' ),''yyyy-mm-DD HH24:MI:SS'') > TO_DATE('''||TO_CHAR(VAR_BEGIN_TIME,'YYYY-MM-DD HH24:MI:SS')||''',''YYYY-MM-DD HH24:MI:SS'') AND TO_DATE(to_char( T1.lastmodified,''yyyy-mm-DD HH24:MI:SS'' ),''yyyy-mm-DD HH24:MI:SS'') <= TO_DATE('''||TO_CHAR(VAR_END_TIME,'YYYY-MM-DD HH24:MI:SS')||''',''YYYY-MM-DD HH24:MI:SS''))AS CC_LOGIN_NUM,
''11111'',
(SELECT COUNT(USERNAME) FROM USERS T2 WHERE T2.CREATED >= TO_DATE( '''||TO_CHAR(VAR_BEGIN_TIME,'YYYY-MM-DD HH24:MI:SS')||''',''YYYY-MM-DD HH24:MI:SS'')
AND T2.CREATED <= TO_DATE('''||TO_CHAR(VAR_END_TIME,'YYYY-MM-DD HH24:MI:SS')||''',''YYYY-MM-DD HH24:MI:SS'') ) AS CREATE_CUSTOMR_FILE_NUM ,
SUM(CASE WHEN POLICY_ACTION = ''ALLOW'' then 1 else 0 end ) as ALLOW_TRANS_NUM,
SUM(CASE WHEN POLICY_ACTION = ''REVIEW'' then 1 else 0 end ) as REVIEW_TRANS_NUM,
SUM(CASE WHEN POLICY_ACTION = ''AHALLENGE'' then 1 else 0 end ) as CHALLENGE_TRANS_NUM,
SUM(CASE WHEN POLICY_ACTION = ''DENY'' then 1 else 0 end ) as DENY_TRANS_NUM,
SUM(RISK_SCORE) AS TOTAL_SCORE_RANGE,
SUM(GET_AMT_BY_CURRENCY(AMOUNT_ORIGINAL,AMOUNT_CURRENCY)) AS TOTAL_AMOUNT--通过汇率表和币种转换再求和
FROM EVENT_LOG_REALTIME T
WHERE SYS_CREATION_DATE >= TO_DATE('''||TO_CHAR(VAR_BEGIN_TIME,'YYYY-MM-DD HH24:MI:SS')||''',''YYYY-MM-DD HH24:MI:SS'') AND SYS_CREATION_DATE <= TO_DATE('''||TO_CHAR(VAR_END_TIME,'YYYY-MM-DD HH24:MI:SS')||''' ,''YYYY-MM-DD HH24:MI:SS'')
AND HAS_USED = ''T''
AND T.HAS_USED_TIME=T.LASTMODIFIED
GROUP BY
TO_DATE(SUBSTR(TO_CHAR(SYS_CREATION_DATE,''YYYY-MM-DD HH24:MI:SS''),0,16),''YYYY-MM-DD HH24:MI''),
get_province(IP_COUNTRY,IP_CITY,ip_region) ,
GET_NAME_BY_CODE(GET_TOTAL_EVENT_TYPE(T.EVENT_TYPE,T.USER_DEFINED_EVENT_TYPE),''eventType'') ,
GET_SCORE_RANGE(T.RISK_SCORE) ,
NVL(POLICY_RULE_ID,''FALLBACK_RULE'') ,
POLICY_ACTION,
CHALLENGE_SUCCESSFUL,
CHALLENGE_AUTH_METHOD,
SUBSTR(GET_RULE_ORDER_ID(ORG_ID,POLICY_RULE_ID),0,INSTR(GET_RULE_ORDER_ID(ORG_ID,POLICY_RULE_ID),''+'')-1),--优先级
SUBSTR(GET_RULE_ORDER_ID(ORG_ID,POLICY_RULE_ID),INSTR(GET_RULE_ORDER_ID(ORG_ID,POLICY_RULE_ID),''-'')+1),--描述
NVL(IS_DEVICE_BOUND,''N''),
CHANNEL_INDICATOR,
OPERATING_SYSTEM,
BROWSER_TYPE,
FLAGGED,
RESOLUTION ';
-- insert into test (test_name) values(VAR_DYNAMIC_SQL);
--insert into test (test_name) values(TO_CHAR(VAR_BEGIN_TIME));
--insert into test (test_name) values(TO_CHAR(VAR_END_TIME));
-- commit;
execute immediate VAR_DYNAMIC_SQL;