### Start Job Monitoring Service Example Source: https://eco.dameng.com/document/dm/zh-cn/pm/monitoring-job.html An example of how to start the job monitoring server using dmjmon with specific user credentials, password, server IP, and port. ```bash ./dmjmon userid=SYSDBA/DMdba_123@192.168.0.38:5236 ``` -------------------------------- ### Install dmPython from Source Source: https://eco.dameng.com/document/dm/zh-cn/pm/dmpython-installation.html Install dmPython using its source code. Navigate to the source directory and run the setup script. This method is applicable on both Windows and Linux. ```bash D:\dmdbms\drivers\python\dmPython>python setup.py install ``` -------------------------------- ### Start DM Database via Command Line (Linux) Source: https://eco.dameng.com/document/dm/zh-cn/pm/start-shut-down.html Navigate to the bin directory of the DM installation and execute './dmserver' to start the database. Parameters are similar to Windows. ```bash ./dmserver ``` -------------------------------- ### Example install.log Entry Source: https://eco.dameng.com/document/dm/zh-cn/pm/install-uninstall This log records installation module information, service registration, and uninstallation details, including timestamps and log levels (INFO/WARN/ERROR/FATAL). ```log 2022-09-14 14:55:30 [INFO] 安装达梦数据库... 2022-09-14 14:55:30 [INFO] 安装 基础 模块... 2022-09-14 14:55:31 [INFO] 安装 服务器 模块... 2022-09-14 14:55:31 [INFO] 安装 客户端 模块... 2022-09-14 14:55:34 [INFO] 安装 驱动 模块... 2022-09-14 14:55:35 [INFO] 安装 手册 模块... 2022-09-14 14:55:35 [INFO] 安装 服务 模块... 2022-09-14 14:55:35 [INFO] 注册ODBC完成。 ``` -------------------------------- ### Install and Enable Multipath Source: https://eco.dameng.com/document/dm/zh-cn/pm/dsc-build.html Installs multipath software, generates the configuration file, and starts/enables the multipath daemon. This is the initial setup for multipath. ```bash yum install *multipath* -y mpathconf --enable # 生成/etc/multipath.conf systemctl start multipathd systemctl enable multipathd ``` -------------------------------- ### Start Monitor Process Source: https://eco.dameng.com/document/dm/zh-cn/pm/data-guard-construction.html Command to start a monitor process. For multi-instance setups, start each monitor individually. Use the 'help' command within the monitor for available commands. ```bash ./dmmonitor /dm/data/dmmonitor.ini ``` -------------------------------- ### Example install_ant.log Entry Source: https://eco.dameng.com/document/dm/zh-cn/pm/install-uninstall This log records file copying information during the installation process, detailing each file copied from the source to the installation directory. ```log Build sequence for target(s) `default' is [jdk, default] Complete build sequence is [jdk, default, ent.default, manual, ent.postinstall, clt, postinstall, gui, client, ent.drivers, ent.server, ent.clt, install, drivers, server, ent.service, ent.manual, ent.jdk, ent.client, ent.gui, service, ] fileset: Setup scanner in dir C:\Users\dameng\Downloads\dm8_20220908_x86_win_64_ent_8.1.2.159\source\jdk with patternSet{ includes: [] excludes: [] } Copying 201 files to d:\dmdbms\jdk Copying C:\Users\dameng\Downloads\dm8_20220908_x86_win_64_ent_8.1.2.159\source\jdk\ASSEMBLY_EXCEPTION to d:\dmdbms\jdk\ASSEMBLY_EXCEPTION Copying C:\Users\dameng\Downloads\dm8_20220908_x86_win_64_ent_8.1.2.159\source\jdk\LICENSE to d:\dmdbms\jdk\LICENSE Copying C:\Users\dameng\Downloads\dm8_20220908_x86_win_64_ent_8.1.2.159\source\jdk\THIRD_PARTY_README to d:\dmdbms\jdk\THIRD_PARTY_README …… ``` -------------------------------- ### Create Installation User and Group (Linux/Unix) Source: https://eco.dameng.com/document/dm/zh-cn/pm/install-uninstall Example commands for creating a dedicated system user and group for installing and running DM Database on Linux/Unix. This is a recommended practice to minimize impact on the operating system. ```bash groupadd -g 12349 dinstall ``` ```bash useradd -u 12345 -g dinstall -m -d /home/dmdba -s /bin/bash dmdba ``` ```bash Copypasswd dmdba ``` -------------------------------- ### Table Setup for Rewrite Example Source: https://eco.dameng.com/document/dm/zh-cn/pm/dbms_advances_rewrite-package.html Sets up two tables, x1 and x2, with sample data for demonstrating query rewrite functionalities. Includes dropping existing tables and committing the changes. ```SQL drop table x1; drop table x2; create table x1(c1 int, c2 char(20)); insert into x1 values(12, 'test12'); insert into x1 values(13, 'test13'); insert into x1 values(14, 'test14'); insert into x1 values(15, 'test15'); create table x2(d1 int, d2 char(30)); commit; ``` -------------------------------- ### Example: Starting dmfldr with USERID Source: https://eco.dameng.com/document/dm/zh-cn/pm/getting-started-dmfldr.html Demonstrates how to start the dmfldr tool using the USERID parameter with a Unix socket connection. ```bash Copy./dmfldr SYSDBA/Dmsys_123@/home/test/foo.sock#{inet_type=UNIXSOCKET} control=\"/home/test/dmfldr_test.ctrl\" ``` -------------------------------- ### Example: Put and Get Line with DBMS_OUTPUT Source: https://eco.dameng.com/document/dm/zh-cn/pm/dbms_output-package.html An example demonstrating how to enable DBMS_OUTPUT, use PUT_LINE to add text to the buffer, and GET_LINE to retrieve it. The output shows the retrieved buffer content and status. ```sql Copy//启用DBMS_OUTPUT包 DBMS_OUTPUT.ENABLE(); //使用put_line和get_line declare buffer varchar; status int; begin dbms_output.put_line('达梦数据库有限公司'); dbms_output.get_line(buffer,status); dbms_output.put_line('BUFFER:'||buffer||' status:'||status); commit; end; / //打印结果:BUFFER:达梦数据库有限公司 status:0 ``` -------------------------------- ### DMMPP Single-Node Login Example Setup Source: https://eco.dameng.com/document/dm/zh-cn/pm/sql-tuning.html Setup for demonstrating MPP_LOCAL hint in DMMPP environment, including creating a distributed table and inserting data. This is used to show the effect of single-node login on query results. ```SQL DROP TABLE TEST; CREATE TABLE TEST(C1 INT,C2 INT,C3 INT) DISTRIBUTED BY HASH(C1) ; insert into test select level,level,level from dual connect by level <8; commit; ``` -------------------------------- ### DMDPC Single-Node Login Example Setup Source: https://eco.dameng.com/document/dm/zh-cn/pm/sql-tuning.html Setup for demonstrating DPC_LOCAL hint, including creating tablespaces on different nodes and a partitioned table. This is used to show the effect of single-node login on query results. ```SQL //创建表空间 CREATE TABLESPACE TS1 DATAFILE 'opt/ts/ts01.dbf' SIZE 128 STORAGE (ON RAFT_1); CREATE TABLESPACE TS2 DATAFILE 'opt/ts/ts02.dbf' SIZE 128 STORAGE (ON RAFT_2); //创建表 DROP TABLE TEST; CREATE TABLE "SYSDBA"."TEST" ( "C1" INT, "C2" INT, "C3" INT) PARTITION BY HASH("C1") ( PARTITION "P1" STORAGE(ON "TS1", CLUSTERBTR) , PARTITION "P2" STORAGE(ON "TS2", CLUSTERBTR) , PARTITION "P3" STORAGE(ON "TS1", CLUSTERBTR) ) STORAGE(HASHPARTMAP(2), ON "TS2", CLUSTERBTR) ; INSERT INTO TEST SELECT LEVEL,LEVEL,LEVEL FROM DUAL CONNECT BY LEVEL <8; COMMIT; ``` -------------------------------- ### Example: Get and Set Object Values Source: https://eco.dameng.com/document/dm/zh-cn/pm/dmpython-interface.html Demonstrates initializing an Object, retrieving its initial null value, setting new values, and then retrieving the updated values. ```python import dmPython conn = dmPython.connect('SYSDBA/Dmsys_123') obj = dmPython.objectvar(conn, 'CLS1') obj.getvalue() tp = ['test1','test2',8098] obj.setvalue(tp) obj.getvalue() ``` -------------------------------- ### Get Integer Parameter Example Source: https://eco.dameng.com/document/dm/zh-cn/pm/external-function.html Retrieves an integer parameter from the argument list. The parameter ID starts from 0. ```c int de_get_int( de_args *args, int arg_id ); ``` -------------------------------- ### Get Double Parameter Example Source: https://eco.dameng.com/document/dm/zh-cn/pm/external-function.html Retrieves a double-precision floating-point parameter from the argument list. The parameter ID starts from 0. ```c double de_get_double( de_args *args, int arg_id ); ``` -------------------------------- ### Initialize Database Example Source: https://eco.dameng.com/document/dm/zh-cn/pm/use-dminit.html Example of initializing a database with a specified path, page size, and administrator passwords. Ensure passwords meet the specified restrictions. ```bash ./dminit PATH=/home/test/dmdbms PAGE_SIZE=16 SYSDBA_PWD=DMdba_123 SYSAUDITOR_PWD=DMauditor_123 ``` -------------------------------- ### Run Script at DIsql Startup Source: https://eco.dameng.com/document/dm/zh-cn/pm/disql-script.html Example of executing a script file when starting the DIsql client. This method is suitable for initial setup or batch operations upon login. ```sql disql SYSDBA/Dmsys_123 `D:\test.sql ``` -------------------------------- ### Write Initial Content for GET_RAW Example Source: https://eco.dameng.com/document/dm/zh-cn/pm/utl_file-package.html Writes 'HELLO WORLD!' to the file 'u12345.tmp' in 'DIR01' directory using 'W' mode. This prepares the file for the GET_RAW example. ```PL/SQL DECLARE HANDLE UTL_FILE.FILE_TYPE; BEGIN HANDLE := UTL_FILE.FOPEN('DIR01','u12345.tmp','W'); UTL_FILE.PUT(HANDLE,'HELLO WORLD!'); UTL_FILE.FFLUSH(HANDLE); UTL_FILE.FCLOSE(HANDLE); END; / ``` -------------------------------- ### Command-line Installation of DM Database Source: https://eco.dameng.com/document/dm/zh-cn/pm/install-uninstall Execute this command in the terminal within the installation directory to start the command-line installation process for DM. ```bash ./DMInstall.bin -i ``` -------------------------------- ### Create System Packages and Enable Server Output Source: https://eco.dameng.com/document/dm/zh-cn/pm/dbms_output-package.html Demonstrates the initial setup required before using DBMS_OUTPUT. This includes creating necessary system packages and enabling server output in the client. ```sql CopySP_CREATE_SYSTEM_PACKAGES (1,'DBMS_OUTPUT'); SET SERVEROUTPUT ON; //DBMS_OUTPUT.PUT_LINE需要设置这条语句,才能打印出消息 ``` -------------------------------- ### Example: BFILE operations with dmPython Source: https://eco.dameng.com/document/dm/zh-cn/pm/dmpython-interface.html Demonstrates creating a directory, retrieving a BFILE, and then using its size and read methods. ```python import dmPython conn = dmPython.connect('SYSDBA/Dmsys_123') cursor = conn.cursor() cursor.execute("create or replace directory TEST as '/opt/dmdata';") cursor.execute("select bfilename('TEST','test.txt') FROM DUAL;") value=cursor.fetchone()[0] value.size() value.read(1,5) ``` -------------------------------- ### Create Partitioned Table and Use Hints Source: https://eco.dameng.com/document/dm/zh-cn/pm/sql-tuning.html Example demonstrating the creation of a hash-partitioned table and the usage of COLLECT_ALL_SUB_TAB and NO_COLLECT_ALL_SUB_TAB hints for controlling dictionary information caching. ```SQL drop table TEST; CREATE TABLE TEST(C1 INT,C2 INT,C3 INT) PARTITION BY HASH(C1) ( PARTITION p1, PARTITION p2, PARTITION p3); select /*+COLLECT_ALL_SUB_TAB*/ * from TEST; select /*+NO_COLLECT_ALL_SUB_TAB*/ * from TEST; ``` -------------------------------- ### Get Context Attribute Example Source: https://eco.dameng.com/document/dm/zh-cn/pm/definition-statement.html Example of retrieving the value of the 'u_k2' attribute from the 'c_user01' context using the test_pk package. ```sql call test_pk.get_context('c_user01', 'u_k2'); ``` -------------------------------- ### LOCATE Example 2 (without start position) Source: https://eco.dameng.com/document/dm/zh-cn/pm/function.html Finds the first occurrence of 'man' in 'The manager is a man' starting from the beginning. ```sql SELECT LOCATE('man', 'The manager is a man'); ``` -------------------------------- ### Prepare Data for SQL Tuning Examples Source: https://eco.dameng.com/document/dm/zh-cn/pm/sql-tuning.html This snippet sets up two tables, T1 and T2, and populates them with sample data for demonstrating SQL join hints. It includes dropping existing tables, creating new ones, and inserting 1000 rows into each. ```sql Copy//数据准备 DROP TABLE T1 CASCADE; DROP TABLE T2 CASCADE; CREATE TABLE T1 (ID INTEGER,NAME VARCHAR(128)); CREATE TABLE T2 (ID INTEGER,NAME VARCHAR(128)); begin for i in 1..1000 loop insert into T1 values(i,'dameng'||i); insert into T2 values(i+500,'damengsh'||i); end loop; end; ``` -------------------------------- ### User and Directory Setup Source: https://eco.dameng.com/document/dm/zh-cn/pm/utl_file-package.html Create a user, a directory object pointing to a file path, and grant necessary read/write permissions to the user for file operations. ```SQL CREATE USER USER01 IDENTIFIED BY "USER01_psd"; CREATE DIRECTORY DIR01 AS 'E:\UTL_FILE_TEMP'; GRANT READ ON DIRECTORY DIR01 TO USER01; GRANT WRITE ON DIRECTORY DIR01 TO USER01; GRANT CREATE PROCEDURE TO USER01; ``` -------------------------------- ### LOCATE Example 1 (with start position) Source: https://eco.dameng.com/document/dm/zh-cn/pm/function.html Finds the first occurrence of 'man' in 'The manager is a man' starting from position 10. ```sql SELECT LOCATE('man', 'The manager is a man', 10); ``` -------------------------------- ### Start DTS Graphical Tool Source: https://eco.dameng.com/document/dm/zh-cn/pm/introduction_to_dts.html Start the DTS graphical tool on Windows or Linux. This command assumes you are in the 'tool' directory of the DTS installation. ```bash dts.exe ``` ```bash ./dts ``` -------------------------------- ### Basic Precompilation Example Source: https://eco.dameng.com/document/dm/zh-cn/pm/proc-overview.html This example shows how to precompile a test.pc file using the dpc_new command. Successful compilation generates a test.c file. ```bash ./dpc_new FILE=test.pc ``` -------------------------------- ### Create Job and Configure Steps Source: https://eco.dameng.com/document/dm/zh-cn/pm/job.html Demonstrates creating a job, adding multiple steps with specific actions, and configuring the next steps for success and failure, including setting up a potential loop. ```SQL CopySP_CREATE_JOB('test_job',1,0,'',0,0,'',2,''); SP_JOB_CONFIG_START('test_job'); SP_ADD_JOB_STEP('test_job','STEP1',0,'DROP TABLE IF EXISTS TAB_TEST;',3,1,0,0,NULL,0); SP_ADD_JOB_STEP('test_job','STEP2',0,'CREATE TABLE TAB_TEST(C1 INT,C2 INT);',3,1,0,0,NULL,0); SP_ADD_JOB_STEP('test_job','STEP3',0,'INSERT INTO TAB_TEST VALUES(1,1);',3,1,0,0,NULL,0); SP_ADD_JOB_STEP('test_job','STEP4',0,'INSERT INTO TAB_TEST VALUES(1,1);',3,1,0,0,NULL,0); SP_JOB_STEP_SET_NEXT_STEP('test_job','STEP1','STEP2',''); SP_JOB_STEP_SET_NEXT_STEP('test_job','STEP2','STEP3',''); SP_JOB_STEP_SET_NEXT_STEP('test_job','STEP4','STEP3',''); SP_JOB_CONFIG_COMMIT('test_job'); ``` -------------------------------- ### Initialize Target Database Example Source: https://eco.dameng.com/document/dm/zh-cn/pm/backup-restore-combat.html This command initializes a new database instance to be used as the target for restoration. It sets up the database path, name, and administrator passwords. ```Shell ./dminit path=/opt/dmdbms/data db_name=DAMENG_FOR_RESTORE sysdba_pwd=DMdba_123 sysauditor_pwd=DMauditor_123 ``` -------------------------------- ### Get DBMS_SCHEDULER System Package Enabled Status Source: https://eco.dameng.com/document/dm/zh-cn/pm/dbms_scheduler-package.html Example of how to get the enabled status of the DBMS_SCHEDULER system package using a SELECT statement. ```sql select SF_CHECK_DBMS_SCHEDULER_SYS(); ``` -------------------------------- ### Asynchronous Session Setup and Operations Source: https://eco.dameng.com/document/dm/zh-cn/pm/dmsqlalchemy-dialect-package.html Demonstrates setting up an asynchronous engine and sessionmaker, creating tables, inserting objects, and performing select and update operations asynchronously. ```python import asyncio import datetime from typing import List from sqlalchemy import ForeignKey from sqlalchemy import func from sqlalchemy import select from sqlalchemy.ext.asyncio import AsyncAttrs from sqlalchemy.ext.asyncio import async_sessionmaker from sqlalchemy.ext.asyncio import AsyncSession from sqlalchemy.ext.asyncio import create_async_engine from sqlalchemy.orm import DeclarativeBase from sqlalchemy.orm import Mapped from sqlalchemy.orm import mapped_column from sqlalchemy.orm import relationship from sqlalchemy.orm import selectinload class Base(AsyncAttrs, DeclarativeBase): pass class B(Base): __tablename__ = "b" id: Mapped[int] = mapped_column(primary_key=True) a_id: Mapped[int] = mapped_column(ForeignKey("a.id")) data: Mapped[str] class A(Base): __tablename__ = "a" id: Mapped[int] = mapped_column(primary_key=True) data: Mapped[str] create_date: Mapped[datetime.datetime] = mapped_column(server_default=func.now()) bs: Mapped[List[B]] = relationship() async def insert_objects(async_session: async_sessionmaker[AsyncSession]) -> None: async with async_session() as session: async with session.begin(): session.add_all( [ A(bs=[B(data="b1", id=1), B(data="b2", id=2)], data="a1",id=1), A(bs=[], data="a2",id=2), A(bs=[B(data="b3", id=3), B(data="b4", id=4)], data="a3",id=3), ] ) async def select_and_update_objects( async_session: async_sessionmaker[AsyncSession], ) -> None: async with async_session() as session: stmt = select(A).order_by(A.id).options(selectinload(A.bs)) result = await session.execute(stmt) for a in result.scalars(): print(a, a.data) print(f"created at: {a.create_date}") for b in a.bs: print(b, b.data) result = await session.execute(select(A).order_by(A.id).limit(1)) a1 = result.scalars().one() a1.data = "new data" await session.commit() print(a1.data) for b1 in await a1.awaitable_attrs.bs: print(b1, b1.data) async def async_main() -> None: engine = create_async_engine("dm+dmAsync://SYSDBA:sysDBA*00@localhost:5236", echo=True) async_session = async_sessionmaker(engine, expire_on_commit=False) async with engine.begin() as conn: await conn.run_sync(Base.metadata.create_all) await insert_objects(async_session) await select_and_update_objects(async_session) await engine.dispose() asyncio.run(async_main() ``` -------------------------------- ### Example: Set and Get Varchar using DBMS_BINARY Source: https://eco.dameng.com/document/dm/zh-cn/pm/dbms_binary-package.html This example demonstrates writing a varchar value to a binary stream using binary_set_varchar and then reading it back using binary_get_varchar. ```plsql DECLARE BIN VARBINARY(50); VAL VARCHAR; BEGIN BIN = 'ABCDEF87'; DBMS_BINARY.BINARY_SET_VARCHAR(BIN,0,'AAAA'); VAL = DBMS_BINARY.BINARY_GET_VARCHAR(BIN,0,4); PRINT VAL; END; / ``` -------------------------------- ### Table Creation and Insertion Example Source: https://eco.dameng.com/document/dm/zh-cn/pm/oracle-compatible.html Example demonstrating the creation of a table and insertion of data, relevant for testing CHAR_MAP options. ```sql CREATE TABLEchar_test (c1 int,c2 varchar(100)); INSERT INTO char_test VALUES(1,'abcde'); COMMIT; ``` -------------------------------- ### Example: Set and Get Tinyint using DBMS_BINARY Source: https://eco.dameng.com/document/dm/zh-cn/pm/dbms_binary-package.html This example demonstrates writing a tinyint value to a binary stream using binary_set_tinyint and then reading it back using binary_get_tinyint. ```plsql DECLARE BIN VARBINARY(50); VAL TINYINT; BEGIN BIN = 'ABCDEF87'; VAL = 127; DBMS_BINARY.BINARY_SET_TINYINT(BIN,0,VAL); VAL = DBMS_BINARY.BINARY_GET_TINYINT(BIN,0); PRINT VAL; END; / ``` -------------------------------- ### dminit Command Example Source: https://eco.dameng.com/document/dm/zh-cn/pm/create-configure.html This command initializes a database with specified parameters for path, page size, and user passwords. Ensure no spaces exist between parameters, the equals sign, and their values. ```bash dminit PATH=c:\dmdata PAGE_SIZE=16 SYSDBA_PWD=DMdba_123 SYSAUDITOR_PWD=DMauditor_123 ``` -------------------------------- ### Prepare Data for COLUMN Command Examples Source: https://eco.dameng.com/document/dm/zh-cn/pm/common-commands.html This snippet sets up a test table and inserts sample data required for demonstrating the COLUMN command's functionality. ```SQL SQL> DROP TABLE TEST; SQL> CREATE TABLE TEST(C1 VARCHAR(50)); SQL> INSERT INTO TEST VALUES('DAMENGSHUJUKU'); SQL> INSERT INTO TEST VALUES('A'); SQL> INSERT INTO TEST VALUES('B'); SQL> COMMIT; ``` -------------------------------- ### Create Table Space for Example Database Source: https://eco.dameng.com/document/dm/zh-cn/pm/example-description.html Use this SQL statement to create the table space for the BOOKSHOP example database if it was not installed automatically. This script is intended for use with the DAMENG database. ```sql Copy//创建示例库表空间 CREATE TABLESPACE BOOKSHOP DATAFILE 'BOOKSHOP.DBF' size 50; ``` -------------------------------- ### Create Simulated Block Device Example Source: https://eco.dameng.com/document/dm/zh-cn/pm/dmasm-introduce.html This example demonstrates how to create a simulated block device named DISK0.asm with a size of 100MB. ```bash CREATE EMPTYFILE '/OPT/DATA/ASMDISKS/DISK0.asm' SIZE 100 ``` -------------------------------- ### INSTRC Example 2 Source: https://eco.dameng.com/document/dm/zh-cn/pm/function.html Finds the first occurrence of '计算机' starting from the 1st byte in '我们的计算机'. ```sql SELECT INSTRC('我们的计算机', '计算机',1,1); ``` -------------------------------- ### Example SSL Configuration for Users Source: https://eco.dameng.com/document/dm/zh-cn/pm/embedded-sql.html An example configuration enabling SSL and setting up SSL parameters for SYSDBA and SYSSSO users. ```sql ENABLE_SSL=(1) SSL_CONFIG=((USER=(SYSDBA)SSL_PATH=(C:\dmdbms\bin\client_ssl\SYSDBA)SSL_PWD=(Dmsys_123))(USER=(SYSSSO)SSL_PATH=(C:\dmdbms\bin\client_ssl\SYSSSO)SSL_PWD=(Dmsys_123))) ``` -------------------------------- ### Get Array Size and Element Type using JDOM_T Source: https://eco.dameng.com/document/dm/zh-cn/pm/dbms_json-package.html This example shows how to get the number of elements in a JSON array using GET_SIZE and determine the JSON type of each element using GET_TYPE. ```PL/SQL DECLARE P_CLOB CLOB := '[1,"ABC",[2],{"A":1}]'; --构造一个JDOM_T类型元素DOM DOM JDOM_T := JDOM_T.PARSE(P_CLOB); N NUMBER; BEGIN --获取DOM中数组元素的个数 N := DOM.GET_SIZE; DBMS_OUTPUT.PUT_LINE('GET_SIZE:'||N); --依次打印DOM中每个数组元素的JSON类型 FOR I IN 1..N LOOP DBMS_OUTPUT.PUT_LINE(DOM.GET_TYPE(I-1)); END LOOP; END; / ``` -------------------------------- ### Prepare Data and Migrate Partition Table Source: https://eco.dameng.com/document/dm/zh-cn/pm/dpc-cluster-management-use.html Example demonstrating data preparation and partition table migration. It includes creating partition groups, a partition table, inserting data, and then performing a fast migration to a new partition group, followed by a standard migration back. ```SQL //Data preparation create partition group pg1 partition by hash(BIGINT) partitions 8 storage (on TS_1,TS_2); create partition group pg2 partition by hash(BIGINT) partitions 8 storage (on TS_2,TS_1); create table test1(c1 varchar(100),c2 float,c3 double, c4 int, c5 bigint , c6 int) using partition group pg1 by (c5); insert into test1 select level,level,level,level,level,level from dual connect by level < 10000; commit; //Migrate test1 table from current group (PG1) to PG2 quickly alter table test1 move to pg2 fast; //Migrate test1 table from current group (PG2) to PG1 alter table test1 move to pg1; ``` -------------------------------- ### Start SP Instance Source: https://eco.dameng.com/document/dm/zh-cn/pm/dpc-cluster-deploy.html Command to start a Service Provider (SP) instance. SPs provide external database services. ```bash dmserver e:\mpraft_data\sp1\DAMENG\dm.ini dpc_mode=SP ``` -------------------------------- ### INSTRC Example 1 Source: https://eco.dameng.com/document/dm/zh-cn/pm/function.html Finds the second occurrence of 'OR' starting from the 3rd byte in 'CORPORATE FLOOR'. ```sql SELECT INSTRC('CORPORATE FLOOR', 'OR', 3, 2) "Instring"; ``` -------------------------------- ### INSTRB Example 1 Source: https://eco.dameng.com/document/dm/zh-cn/pm/function.html Finds the second occurrence of 'OR' starting from the 3rd byte in 'CORPORATE FLOOR'. ```sql SELECT INSTRB('CORPORATE FLOOR', 'OR', 3, 2) "Instring"; ``` -------------------------------- ### Get Table DDL Statement (Result) Source: https://eco.dameng.com/document/dm/zh-cn/pm/dbms_metadata-package.html The resulting DDL statement for the table created in the previous example. ```SQL CopyCREATE TABLE "SYSDBA"."T1" ( "C1" CHAR(10) NOT NULL, "C2" CHAR(10), CONSTRAINT "PK" NOT CLUSTER PRIMARY KEY("C1")) STORAGE(ON "MAIN", CLUSTERBTR) ; ``` -------------------------------- ### dimp Example: Full Import Source: https://eco.dameng.com/document/dm/zh-cn/pm/dimp-logical%20import.html This example demonstrates how to fully import a logical backup using the FULL option. It specifies the username, password, IP address, port, input filename, log filename, and the directory where the import file is located. ```bash ./dimp USERID=SYSDBA/Dmsys_123@192.168.0.248:8888 FILE=db_str.dmp DIRECTORY=/mnt/data/dexp LOG=db_str.log FULL=Y ``` -------------------------------- ### Get Table DDL Statement Source: https://eco.dameng.com/document/dm/zh-cn/pm/dbms_metadata-package.html Example of creating a table and then retrieving its DDL statement using DBMS_METADATA.GET_DDL. ```SQL Copy//建表 CREATE TABLE "SYSDBA"."T1" ( "C1" CHAR(10) NOT NULL, "C2" CHAR(10), CONSTRAINT "PK" PRIMARY KEY("C1")) STORAGE(ON "MAIN", CLUSTERBTR); //获取对象的ddl语句 SELECT DBMS_METADATA.GET_DDL('TABLE','T1','SYSDBA'); ``` -------------------------------- ### Create Table and View Initial Execution Plan Source: https://eco.dameng.com/document/dm/zh-cn/pm/definition-statement.html Create a simple table and then use the EXPLAIN statement to view the execution plan for a COUNT(*) query. ```SQL CREATE TABLE test(c1 INT); EXPLAIN SELECT COUNT(*) FROM test; ``` -------------------------------- ### Enqueue Message and Trigger Callback Source: https://eco.dameng.com/document/dm/zh-cn/pm/dbms_aq-package.html This example enqueues a message of type 'MY_MSG_TYPE' to 'SSS.MY_QUEUE'. Upon successful commit, this action will trigger the registered callback procedure ('MY_CALLBACK') due to the subscription setup in the previous example. ```PL/SQL DECLARE EOP DBMS_AQ.ENQUEUE_OPTIONS_T; MSG MY_MSG_TYPE; MSGID RAW(16); BEGIN MSG := MY_MSG_TYPE(TO_CHAR(SYSTIMESTAMP, 'DD-MON-YYYY HH24:MI:SS.FF3')); DBMS_AQ.ENQUEUE( QUEUE_NAME => 'SSS.MY_QUEUE', ENQUEUE_OPTIONS => EOP, MESSAGE_PROPERTIES => NULL, PAYLOAD => MSG, MSGID => MSGID ); COMMIT; END; / ``` -------------------------------- ### 安装 dmDjango (源码) Source: https://eco.dameng.com/document/dm/zh-cn/pm/dmdjango-drive.html 使用 setup.py 脚本在 Windows 和 Linux 操作系统下编译并安装 dmDjango。 ```bash python setup.py install ``` -------------------------------- ### Set and Read Client, Module, and Action Information Source: https://eco.dameng.com/document/dm/zh-cn/pm/dbms_application_info-package.html This example demonstrates setting client information, module name, and action name using DBMS_APPLICATION_INFO procedures, then reading and displaying this information. Ensure system packages are created and server output is enabled before execution. ```PL/SQL DECLARE C_N VARCHAR2(100); M_N VARCHAR2(100); A_N VARCHAR2(100); BEGIN DBMS_APPLICATION_INFO.SET_CLIENT_INFO('MY CLIENT'); DBMS_APPLICATION_INFO.SET_MODULE('MODULE1', 'ACTION1'); DBMS_APPLICATION_INFO.SET_ACTION('ACTION2'); DBMS_APPLICATION_INFO.READ_CLIENT_INFO(C_N); DBMS_APPLICATION_INFO.READ_MODULE(M_N, A_N); DBMS_OUTPUT.PUT_LINE('CLIENT INFO IS:' || C_N); DBMS_OUTPUT.PUT_LINE('MODULE NAME IS:' || M_N); DBMS_OUTPUT.PUT_LINE('ACTION NAME IS:' || A_N); END; ``` -------------------------------- ### Set Null Parameter Example Source: https://eco.dameng.com/document/dm/zh-cn/pm/external-function.html Marks a parameter in the argument list as NULL. The parameter ID starts from 0. ```c void de_set_null( de_args *args, int arg_id ); ``` -------------------------------- ### Get Result Data Source: https://eco.dameng.com/document/dm/zh-cn/pm/php-rogramming-guide.html Retrieves data from a result set. Can specify the field by its index (starting from 1) or its name. ```php mixed dm_result (resource $result, mixed $field) ``` ```php SQL> SELECT * from t2; //查询结果如下: 行号 member_name c0 ---------- ----------- ----------- 1 小明 1 2 小红 2 $ret = dm_query("SELECT * from t2"); $result = dm_result($ret, 1);--第1列 $result = dm_result($ret, "c0");--c0列 //可以按下面方式遍历所有行 while(dm_fetch_row($ret)){ $result1 = dm_result($ret, "c0"); } ``` -------------------------------- ### Create Sample Table for Package Example Source: https://eco.dameng.com/document/dm/zh-cn/pm/common-commands.html This SQL code creates a 'Person' table and inserts sample data, which is a prerequisite for the package example. ```sql CREATE TABLE Person(Id INT IDENTITY, Name VARCHAR(100), City VARCHAR(100)); INSERT INTO Person(Name, City) VALUES('Tom','武汉'); INSERT INTO Person(Name, City) VALUES('Jack','北京'); INSERT INTO Person(Name, City) VALUES('Mary','上海'); ``` -------------------------------- ### Full and Incremental Backup Example Source: https://eco.dameng.com/document/dm/zh-cn/pm/backup-restore-combat.html Demonstrates performing a full table space backup followed by an incremental backup. ```SQL BACKUP TABLESPACE MAIN BACKUPSET 'ts_full_bak_01'; BACKUP TABLESPACE MAIN INCREMENT BACKUPSET 'ts_increment_bak_01'; ``` -------------------------------- ### Browsing Interface to Get Table Metadata Source: https://eco.dameng.com/document/dm/zh-cn/pm/dbms_metadata-package.html Example of using the browsing interface of DBMS_METADATA to retrieve the DDL for a table. ```SQL CopySELECT DBMS_METADATA.GET_DDL('TABLE','TIMECARDS','RESOURCES'); ``` -------------------------------- ### Example: Create SQL Sequence Audit Rule Source: https://eco.dameng.com/document/dm/zh-cn/pm/audit.html This example demonstrates the process of creating a SQL sequence audit rule named 'AUDIT_SQL1' by starting the rule, adding three SQL statements, and then ending the rule definition. ```SQL SP_AUDIT_SQLSEQ_START('AUDIT_SQL1'); SP_AUDIT_SQLSEQ_ADD('AUDIT_SQL1', 'SELECT NAME FROM TEST1;'); SP_AUDIT_SQLSEQ_ADD('AUDIT_SQL1', 'SELECT ID FROM TEST2;'); SP_AUDIT_SQLSEQ_ADD('AUDIT_SQL1', 'SELECT * FROM TEST3;'); SP_AUDIT_SQLSEQ_END('AUDIT_SQL1'); ``` -------------------------------- ### Create a HASH Partitioned Table with Tablespaces Source: https://eco.dameng.com/document/dm/zh-cn/pm/check-phrases.html Sets up tablespaces and then creates a HASH partitioned table with HASH subpartitions. This example demonstrates defining storage for partitions and subpartitions. ```SQL CopyCREATE TABLESPACE TS1 DATAFILE 'TS1.DBF' SIZE 128; CREATE TABLESPACE TS2 DATAFILE 'TS2.DBF' SIZE 128; CREATE TABLESPACE TS3 DATAFILE 'TS3.DBF' SIZE 128; CREATE TABLESPACE TS4 DATAFILE 'TS4.DBF' SIZE 128; DROP TABLE CP_TABLE_HASH CASCADE; CREATE TABLE CP_TABLE_HASH( C1 INT, C2 VARCHAR(256), C3 DATETIME, C4 BLOB ) PARTITION BY HASH (C1) SUBPARTITION BY HASH(C2) SUBPARTITION TEMPLATE (SUBPARTITION PAR1 STORAGE (ON MAIN), SUBPARTITION PAR2 STORAGE (ON TS1), SUBPARTITION PAR3 STORAGE (ON TS2), SUBPARTITION PAR4) (PARTITION PAR1 STORAGE (ON MAIN), PARTITION PAR2 STORAGE (ON TS1), PARTITION PAR3 STORAGE (ON TS2), PARTITION PAR4) STORAGE (ON TS4) ; INSERT INTO CP_TABLE_HASH (C1, C2, C3, C4) VALUES (1 ,'NAME1', '2023-12-26', ''), (2 ,'NAME2', '2022-12-26', ''), (3 ,'NAME3', '2023-1-15', ''), (4 ,'NAME4', '2022-5-1', ''), (5 ,'NAME5', '2023-3-15', ''), (6 ,'NAME6', '2023-11-11', ''), (7 ,'NAME7', '2021-9-23', ''), (8 ,'NAME8', '2023-7-8', ''), (9 ,'NAME9', '2023-12-26', ''), (10 ,'NAME10', '2022-12-26', ''), (11 ,'NAME11', '2023-1-15', ''), (12 ,'NAME12', '2022-5-1', ''), (13 ,'NAME13', '2023-3-15', ''), (14 ,'NAME14', '2023-11-11', ''), (15 ,'NAME15', '2021-9-23', ''), (16 ,'NAME16', '2023-7-8', ''); ``` -------------------------------- ### Set String Parameter Example Source: https://eco.dameng.com/document/dm/zh-cn/pm/external-function.html Sets the value of a string parameter in the argument list. The parameter ID starts from 0. ```c void de_set_str( de_args *args, int arg_id, char* ret ); ``` -------------------------------- ### Set Integer Parameter Example Source: https://eco.dameng.com/document/dm/zh-cn/pm/external-function.html Sets the value of an integer parameter in the argument list. The parameter ID starts from 0. ```c void de_set_int( de_args *args, int arg_id, int ret ); ``` -------------------------------- ### Start Primary Database Instance Source: https://eco.dameng.com/document/dm/zh-cn/pm/data-guard-construction.html Start the primary database instance using the 'mount' mode. It is crucial to start in Mount mode to prevent data inconsistency issues. ```bash ./dmserver /dm/data/DAMENG/dm.ini mount ``` -------------------------------- ### View dminit Help Information Source: https://eco.dameng.com/document/dm/zh-cn/pm/view-dminit-parameters.html Run './dminit help' to display the dminit version, license information, and a list of available parameters with their descriptions and default values. This is useful for understanding the capabilities and configuration options of dminit. ```bash ./dminit help ``` -------------------------------- ### Get Current Database Timezone Source: https://eco.dameng.com/document/dm/zh-cn/pm/function.html Retrieves the current timezone of the database, which is typically the timezone of the operating system where the database was installed. ```SQL SELECT DBTIMEZONE FROM DUAL; ``` -------------------------------- ### Get Help for dmserver Command Source: https://eco.dameng.com/document/dm/zh-cn/pm/start-shut-down.html Use the 'help' parameter with 'dmserver' to display usage information, parameter descriptions, and examples. ```bash dmserver help ``` -------------------------------- ### Get Monitor Co-exit Flag Source: https://eco.dameng.com/document/dm/zh-cn/pm/data-watch-appendix.html Retrieves the flag that indicates whether monitors should co-exit. This is relevant for multi-instance monitor setups. ```c DwExitAll dwmon_get_exit_all(); ``` -------------------------------- ### Explain Plan with Join Order and Method Hints Source: https://eco.dameng.com/document/dm/zh-cn/pm/sql-tuning.html This is the execution plan generated when using combined ORDER and USE_HASH hints. ```text 1 #NSET2: [2, 1, 208] 2 #PRJT2: [2, 1, 208]; exp_num(8), is_atom(FALSE); INFO_BITS(0); ...; spl_info(NULL) 3 #HASH2 INNER JOIN: [2, 1, 208]; KEY_NUM(1); KEY(T3.E1=T4.F1) KEY_NULL_EQU(0) 4 #HASH2 INNER JOIN: [1, 1, 156]; KEY_NUM(1); KEY(T2.D2=T3.E2) KEY_NULL_EQU(0) 5 #HASH2 INNER JOIN: [1, 1, 104]; KEY_NUM(1); KEY(T1.C1=T2.D1) KEY_NULL_EQU(0) 6 #CSCN2: [1, 1, 52]; INDEX33555506(T1); btr_scan(1); need_slct(0); prejudge_iescn(0) 7 #CSCN2: [1, 1, 52]; INDEX33555507(T2); btr_scan(1); need_slct(0); prejudge_iescn(0) 8 #CSCN2: [1, 1, 52]; INDEX33555508(T3); btr_scan(1); need_slct(0); prejudge_iescn(0) 9 #CSCN2: [1, 1, 52]; INDEX33555509(T4); btr_scan(1); need_slct(0); prejudge_iescn(0) Predicate Information (identified by operation id): --------------------------------------------------- 3 - access(T3.E1 = T4.F1) 4 - access(T2.D2 = T3.E2) 5 - access(T1.C1 = T2.D1) ``` -------------------------------- ### Set Double Parameter Example Source: https://eco.dameng.com/document/dm/zh-cn/pm/external-function.html Sets the value of a double-precision floating-point parameter in the argument list. The parameter ID starts from 0. ```c void de_set_double( de_args *args, int arg_id, double ret ); ``` -------------------------------- ### Create Table for Restore Example Source: https://eco.dameng.com/document/dm/zh-cn/pm/backup-restore-combat.html Creates a sample table named TAB_FOR_RES_01, which will be used for demonstrating the restore process. ```SQL CREATE TABLE TAB_FOR_RES_01(C1 INT); ``` -------------------------------- ### Online Archive Configuration Example Source: https://eco.dameng.com/document/dm/zh-cn/pm/backup-restore-combat.html Demonstrates the sequence of SQL commands to configure archive logging online. This includes setting the database to MOUNT, NORMAL, and ARCHIVELOG modes, adding local and remote archive logs, and finally opening the database. ```SQL //修改数据库为MOUNT状态NORMAL模式,并开启归档模式 ALTER DATABASE MOUNT; ALTER DATABASE NORMAL; ALTER DATABASE ARCHIVELOG; //配置本地归档 ALTER DATABASE ADD ARCHIVELOG 'DEST = /dmdata/dameng/arch_dsc0, TYPE = local, FILE_SIZE = 1024,SPACE_LIMIT = 2048,ARCH_FLUSH_BUF_SIZE=16,HANG_FLAG=1'; //配置远程归档(DMDSC环境下配置) ALTER DATABASE ADD ARCHIVELOG 'DEST = DSC1, TYPE = REMOTE, INCOMING_PATH = /dmdata/dameng/arch_dsc1'; //修改数据库为OPEN状态 ALTER DATABASE OPEN; ``` -------------------------------- ### Get Current Row Number Source: https://eco.dameng.com/document/dm/zh-cn/pm/dmpython-interface.html Indicates the current row number in the result set, starting from 0. Returns -1 if undetermined. ```python cursor.rownumber ``` -------------------------------- ### Start Monitor Daemon Source: https://eco.dameng.com/document/dm/zh-cn/pm/data-guard-construction.html Use this command to start the monitor daemon. For multi-instance configurations, start each monitor individually. Monitor configuration changes are not supported dynamically after startup. ```bash Copy./dmmonitor /dm/data/dmmonitor.ini ``` -------------------------------- ### dmamon with UNIX SOCKET Connection Source: https://eco.dameng.com/document/dm/zh-cn/pm/audit.html Example of starting dmamon using a UNIX SOCKET for communication, specifying the socket file path and user credentials. ```bash ./dmamon PATH=/home/dmamon.ini USERID=SYSAUDITOR/DMauditor_123@/home/test/foo.sock#{inet_type=UNIXSOCKET} ```