當前位置:首頁 » 編程語言 » oraclesql長度

oraclesql長度

發布時間: 2023-03-17 18:54:51

⑴ 變更表欄位長度的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;

熱點內容
動態規劃01背包演算法 發布:2024-11-05 22:17:40 瀏覽:847
nasm編譯器如何安裝 發布:2024-11-05 22:01:13 瀏覽:177
登錄密碼在微信的哪裡 發布:2024-11-05 22:00:29 瀏覽:736
c防止反編譯工具 發布:2024-11-05 21:56:14 瀏覽:244
安卓虛擬機怎麼用 發布:2024-11-05 21:52:48 瀏覽:342
php時間搜索 發布:2024-11-05 20:58:36 瀏覽:478
燕山大學編譯原理期末考試題 發布:2024-11-05 20:13:54 瀏覽:527
華為電腦出現臨時伺服器 發布:2024-11-05 20:05:08 瀏覽:407
斗戰神免費挖礦腳本 發布:2024-11-05 19:53:25 瀏覽:664
網吧伺服器分別是什麼 發布:2024-11-05 19:45:32 瀏覽:391