Oracle用随机数据填充表
同样来自AskTom的脚本,可以对一个表填充随机数据 create or replace procedure gen_data( p_tname in varchar2, p_records in n
同样来自AskTom的脚本,可以对一个表填充随机数据
create or replace
procedure gen_data( p_tname in varchar2, p_records in number )
-- This routine is designed to be installed ONCE pre database, hence
-- the CURRENT_USER AUTHORIZATION.
authid current_user
as
l_insert long;
l_rows number default 0;
begin
-- dbms_random can be very cpu intensive. I use dbms_application_info
-- to instrument this routine, so I can monitor how far along it is
-- from another session. Every bulk insert will update v$session for us.
dbms_application_info.set_client_info( 'gen_data ' || p_tname );
-- The beginning of our insert into statement. Using a direct path
-- insert, if you alter your table to be nologging in an archive
-- log mode database, it'll generate no redo (assuming the table
-- is not indexed).
l_insert := 'insert /*+ append */ into ' || p_tname ||
' select ';
-- Now, we build the rest of our insert. We select the datatype
-- and size of each column. MAXVAL is used for numbers only. Using
-- the precision defined for the column, we determine the maximum number
-- that we can stuff in there.
for x in
( select data_type, data_length,
nvl(rpad( '9',data_precision,'9')/power(10,data_scale),9999999999) maxval
from user_tab_columns
where table_name = upper(p_tname)
order by column_id )
loop
-- If number, generate a number in the range 1 .. maxval.
if ( x.data_type in ('NUMBER', 'FLOAT' ))
then
l_insert := l_insert ||
'dbms_random.value(1,' || x.maxval || '),';
-- if a date/timestamp type, add some random number to sysdate.
elsif ( x.data_type = 'DATE' or x.data_type like 'TIMESTAMP%' )
then
l_insert := l_insert ||
'sysdate+dbms_random.value(1,1000),';
-- If a string, generate a random string between 1 and data length.
-- bytes in length
else
l_insert := l_insert || 'dbms_random.string(''A'',
trunc(dbms_random.value(1,' || x.data_length || '))),';
end if;
end loop;
l_insert := rtrim(l_insert,',') ||
' from all_objects where rownum
-- Now, wo just execute the insert into as many times as needed
-- in order to put L_ROWS rows in the table. Since we are direct path
-- loading, we must commit after each insert. In this case, since
-- we are generating test data, it is OK from a transactional perspective.
-- And since this operation should generate little redo in all cases,
-- it will not affect our performance as well.
loop
execute immediate l_insert using p_records - l_rows;
l_rows := l_rows + sql%rowcount;
commit;
dbms_application_info.set_module
( l_rows || ' rows of ' || p_records, '' );
exit when ( l_rows >= p_records );
end loop;
end;
/
以Hr的depertment表为例,
SQL> create table dept as select * from departments where 1=0;
Table created.
但是需要注意的是 字段的取值范围不能小于1
以HR的employees表的COMMISSION_PCT字段为例,
执行到过程的第36行
最大值应该是0.99
但是实际执行的结果却是 超过了最大值,导致溢出。
解决这个问题,可以将下限设置为0
本文永久更新链接地址:
,
熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

Go語言是一種高效、簡潔且易於學習的程式語言,因其在並發程式設計和網路程式設計方面的優勢而備受開發者青睞。在實際開發中,資料庫操作是不可或缺的一部分,本文將介紹如何使用Go語言實作資料庫的增刪改查操作。在Go語言中,我們通常會使用第三方函式庫來操作資料庫,例如常用的sql套件、gorm等。這裡以sql包為例介紹如何實作資料庫的增刪改查操作。假設我們使用的是MySQL資料庫。

蘋果公司最新發布的iOS18、iPadOS18以及macOSSequoia系統為Photos應用程式增添了一項重要功能,旨在幫助用戶輕鬆恢復因各種原因遺失或損壞的照片和影片。這項新功能在Photos應用的"工具"部分引入了一個名為"已恢復"的相冊,當用戶設備中存在未納入其照片庫的圖片或影片時,該相冊將自動顯示。 "已恢復"相簿的出現為因資料庫損壞、相機應用未正確保存至照片庫或第三方應用管理照片庫時照片和視頻丟失提供了解決方案。使用者只需簡單幾步

Hibernate多態映射可映射繼承類別到資料庫,提供以下映射類型:joined-subclass:為子類別建立單獨表,包含父類別所有欄位。 table-per-class:為子類別建立單獨資料表,僅包含子類別特有列。 union-subclass:類似joined-subclass,但父類別表聯合所有子類別列。

如何在PHP中使用MySQLi建立資料庫連線:包含MySQLi擴充(require_once)建立連線函數(functionconnect_to_db)呼叫連線函數($conn=connect_to_db())執行查詢($result=$conn->query())關閉連線( $conn->close())

PHP處理資料庫連線報錯,可以使用下列步驟:使用mysqli_connect_errno()取得錯誤代碼。使用mysqli_connect_error()取得錯誤訊息。透過擷取並記錄這些錯誤訊息,可以輕鬆識別並解決資料庫連接問題,確保應用程式的順暢運作。

HTML無法直接讀取資料庫,但可以透過JavaScript和AJAX實作。其步驟包括建立資料庫連線、發送查詢、處理回應和更新頁面。本文提供了利用JavaScript、AJAX和PHP來從MySQL資料庫讀取資料的實戰範例,展示如何在HTML頁面中動態顯示查詢結果。此範例使用XMLHttpRequest建立資料庫連接,發送查詢並處理回應,從而將資料填入頁面元素中,實現了HTML讀取資料庫的功能。

在Golang中使用資料庫回呼函數可以實現:在指定資料庫操作完成後執行自訂程式碼。透過單獨的函數新增自訂行為,無需編寫額外程式碼。回調函數可用於插入、更新、刪除和查詢操作。必須使用sql.Exec、sql.QueryRow或sql.Query函數才能使用回呼函數。

透過Go標準庫database/sql包,可以連接到MySQL、PostgreSQL或SQLite等遠端資料庫:建立包含資料庫連接資訊的連接字串。使用sql.Open()函數開啟資料庫連線。執行SQL查詢和插入操作等資料庫操作。使用defer關閉資料庫連線以釋放資源。
