SQL*PLus - Một Số Câu Lệnh Hay Sử Dụng Trong Oracle Database
Có thể bạn quan tâm
Bài đăng Mới hơn Bài đăng Cũ hơn Trang chủ
2.Các câu lệnh hay dùng
@ Trần Văn Bình - Founder of Oracle DBA AZ #BossData #OraAz #OracleDBAAz #OracleTutorial #Quản_trị_cơ_sở_dữ_liệu_Oracle #OracleDBA #OracleDatabaseAdministration Labels: Admin, Công cụ Bài đăng Mới hơn Bài đăng Cũ hơn Trang chủ
Thứ Tư, 8 tháng 1, 2020
SQL*PLus - Một số câu lệnh hay sử dụng trong Oracle Database
1.Set môi trường cho SQL*Plus| col owner_name format a10 col table_name format a15 col cluster_name format a7 col partition_name format a9 col subpartition_name format a12 col head_rowid format a20 col <column_name> 999,999 col target format a25 | Định dạng dữ liệu kiểu string, 10 ký tự Định dạng dữ liệu cột kiểu number, VD: 123,456 |
| set linesize 200 | Mỗi dòng 200 ký tự |
| SQL> set pagesize 9999 | Định dạng cỡ của trang |
| Set timing on | Hiển thị thời gian chạy của câu lệnh |
| Kiểm tra version | $ sqlplus -v SQL*Plus: Release 11.2.0.4.0 Production |
| Xem hướng dẫn sử dụng | sqlplus -h |
| Đăng nhập vào hệ thống | Chọn 1 trong các cách sau đây: Chỉ gõ sqlplus, hệ thống sẽ yêu cầu nhập username và password: $ sqlplus SQL*Plus: Release 11.2.0.4.0 Production on Tue Jul 21 11:06:15 2015 Copyright (c) 1982, 2013, Oracle. All rights reserved. Enter user-name: sys as sysdba Enter password: Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options |
| Hoặc nhập trực tiếp username password trên dòng lệnh. Nếu chỉ nhập user thì hệ thống sẽ yêu cầu nhập password: $ sqlplus sys/oracle_4U as sysdba SQL*Plus: Release 11.2.0.4.0 Production on Tue Jul 21 11:09:03 2015 Copyright (c) 1982, 2013, Oracle. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options $ sqlplus hr SQL*Plus: Release 11.2.0.4.0 Production on Tue Jul 21 11:10:13 2015 Copyright (c) 1982, 2013, Oracle. All rights reserved. Enter password: Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options SQL> | |
| Nếu dùng /nolog (chú ý không có khoảng trắng), phải tự connect vào database bằng lệnh conn hoặc connect: $ sqlplus /nolog SQL*Plus: Release 11.2.0.4.0 Production on Tue Jul 21 11:21:20 2015 Copyright (c) 1982, 2013, Oracle. All rights reserved. SQL> conn hr/hr Connected. | |
| Khi đăng nhập, ta có thể thêm chuỗi kết nối để xác định chính xác database muốn đăng nhập vào. Chuỗi kết nối có thể là tnsname hoặc thông tin đầy đủ theo dạng easy connect. C:\>sqlplus hr/hr@testdb01 SQL*Plus: Release 11.2.0.4.0 Production on Tue Jul 21 11:25:23 2015 Copyright (c) 1982, 2013, Oracle. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options SQL> C:\>sqlplus hr/[email protected]:1521/testdb01 --Service NameC:\>sqlplus hr/[email protected]:1521:testdb01 --SID SQL*Plus: Release 11.2.0.4.0 Production on Tue Jul 21 13:53:03 2015 Copyright (c) 1982, 2013, Oracle. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options | |
| SQL*Plus có 1 số option, trong đó có option -silent, không hiển thị bất kỳ thông tin gì ngoài các câu lệnh sql gõ vào: $ sqlplus -s scoot/oracle select count(*) from user_tables; COUNT(*) ---------- 9 exit $ | |
| Chạy lệnh OS trong SQL*Plus | SQL>!ls -la SQL> host ls -la |
| Help SQL*Plus | SQL> help connect |
| Chạy lại câu lệnh SQL cuối cùng | SQL>/ |
| Chạy script | SQL>@test_script.sql Hoặc SQL> start test_script.sql |
| Chạy 1 câu lênh hoặc 1 script bất kỳ | SQSSQL> alter system set sga_target=20G; Check câu lệnh SQL chiếm nhiều thời gianSELECTparsing_schema_name username, sql_fulltext sql, optimizer_cost cost,executions, ROUND (elapsed_time / executions / 1000000,2) AS"avg_time/exc(s)" FROM gv$sqlarea WHEREoptimizer_cost > 100 AND last_load_time >= TRUNC (SYSDATE) AND executions > 1 AND elapsed_time / executions/1000000 > 1 AND parsing_schema_name NOTLIKE'%SYS%' ORDERBY optimizer_cost DESC |
| Ghi ra file: | · Ghi kết quả SQL ra file: set wrap off set linesize 200 set feedback off set pagesize 0 set verify off set trimspool on set termout off ALTER SESSION SET NLS_DATE_FORMAT = 'DD/MM/YYYY HH24:MI:SS'; spool /tmp/data.txt select cust||','||CHARGED||','||STA_DATETIME from table1 partition(data20131108) where call_type = 189 and CREDIT_CHARGED>0; spool off Exit Ghi ra file mới (chưa có file sẽ tự tạo ra) pool /export/home/oracle/binhtv_scripts/move_datafiles.sh select 'mv '||name||' '||replace(replace(replace(name,'/u02','/s04'),'/u03','/s05'),'/u04','/s05') from V$DATAFILE WHERE TS# in (select ts# from v$tablespace where name like '%&month') and name not like '/s0%' order by name desc; spool off Ghi append: spool move_datafiles.log append alter system set dg_broker_start=false sid='*'; alter database recover managed standby database cancel; shutdown immediate startup mount; !chmod +x move_datafiles.sh !./move_datafiles.sh @rename_datafiles.sql alter system set dg_broker_start=true sid='*'; alter database recover managed standby database using current logfile disconnect; spool off--Nếu Windows:spool "D:\test\test.txt" select a.ename from employee a inner join department b on ( a.dept_id = b.dept_id ) ; spool off |
| Lấy plan của câu lệnh | explain plan for select /*+ PARALLEL*/ * from testp; jaffar@PRIMEDB> select * from table(dbms_xplan.display) dual; PLAN_TABLE_OUTPUT --------------------------------------------------------------------------------------- -------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost | -------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 10 | 20 | 2 | | 1 | TABLE ACCESS FULL | TESTP | 10 | 20 | 2 | -------------------------------------------------------------------- Note: cpu costing is off |
| Mẫu script | SET termout OFF prompt prompt Using &gg_user as a GoldenGate schema name. prompt SELECT upper('&ddl_hist_table') || '_ALT' AS ddl_hist_table_alt FROM dual; -- set up the role DROP ROLE &gg_role; CREATE ROLE &gg_role; GRANT SELECT, DELETE ON "&gg_user"."&marker_table_name" TO &gg_role; GRANT SELECT, DELETE ON "&gg_user"."&ddl_hist_table" TO &gg_role; GRANT SELECT, DELETE ON "&gg_user"."&ddl_hist_table_alt" TO &gg_role; -- names of objects used for SHOW in GGSCI define ddl_dump_tables = 'GGS_DDL_OBJECTS' -- name of DDL dump objects tables define ddl_dump_columns = 'GGS_DDL_COLUMNS' -- name of DDL dump objects columns define ddl_dump_log_groups = 'GGS_DDL_LOG_GROUPS' -- name of DDL dump log groups define ddl_dump_partitions = 'GGS_DDL_PARTITIONS' -- name of DDL dump partitions define ddl_dump_primary_keys = 'GGS_DDL_PRIMARY_KEYS' -- name of DDL dump primary keys -- setup up security for above tables GRANT SELECT, INSERT, DELETE ON "&gg_user"."&ddl_dump_tables" TO &gg_role; GRANT SELECT, INSERT, DELETE ON "&gg_user"."&ddl_dump_columns" TO &gg_role; GRANT SELECT, INSERT, DELETE ON "&gg_user"."&ddl_dump_log_groups" TO &gg_role; GRANT SELECT, INSERT, DELETE ON "&gg_user"."&ddl_dump_partitions" TO &gg_role; GRANT SELECT, INSERT, DELETE ON "&gg_user"."&ddl_dump_primary_keys" TO &gg_role; -- the following will be ok only if sequences installed, but no matter if they are not GRANT EXECUTE ON "&gg_user".replicateSequence TO &gg_role; GRANT EXECUTE ON "&gg_user".updateSequence TO &gg_role; spool OFF SET verify ON SET termout ON prompt prompt Role setup script complete prompt prompt Grant this role to each user assigned to the Extract, GGSCI, and Manager processes, by using the following SQL command: prompt prompt GRANT &gg_role TO <loggedUser> prompt prompt where <loggedUser> is the user assigned to the GoldenGate processes. |
ĐỌC NHIỀU
-
Hướng dẫn cài đặt, sử dụng công cụ Oracle SQL Developer để làm việc với Oracle Database Oracle SQL Developer là phần mềm do chính hãng Oracle phát triển. Bạn có thể download phần mềm này từ đây hoặc từ link của Oracle tại đây...
-
HỌC ORACLE DATABASE CƠ BẢN TỪ A-Z - BÀI 2: CÁC THÀNH PHẦN KIẾN TRÚC ORACLE DATABASE A-Z Oracle server là một hệ thống quản trị cơ sở dữ liệu đối tượng-quan hệ cho phép quản lý thông tin một cách toàn diện. Oracle server bao gồm ...
-
Cài đặt Oracle Database 19c trên Oracle Linux 7 (OL7) bằng giao diện GUI hoặc bằng silent mode Bài viết này mô tả việc cài đặt Oracle Database 19c 64-bit trên Oracle Linux 7 (OL7) 64-bit bằng giao diện GUI hoặc bằng silent mode
-
Quản lý Quyền trong Oracle Database Mục đích: Quản lý Quyền trong Oracle Database
-
Hướng dẫn Download và cài đặt SecureCRT Giới thiệu phần mềm: VanDyke SecureCRT and SecureFX là một ứng dụng chuyển tập tin an toàn, linh hoạt với giao diện trực quan cung cấp tr...
Tìm kiếm
Lượt xem
Fanpage
BÀI VIẾT MỚI
Làm gì để không bị sa thải khi tái cơ cấu?
Luôn ghi nhớ câu này mỗi ngày: Làm gì để không bị sa thải khi tái cơ cấu? Ví dụ về quản trị CSDL:
YOUTUBE
Cộng đồng DBA Việt Nam
Join "DBA Việt Nam"Đọc nhiều
- Hướng dẫn cài đặt, sử dụng công cụ Oracle SQL Developer để làm việc với Oracle Database Oracle SQL Developer là phần mềm do chính hãng Oracle phát triển. Bạn có thể download phần mềm này từ đây hoặc từ link của Oracle tại đây...
- HỌC ORACLE DATABASE CƠ BẢN TỪ A-Z - BÀI 2: CÁC THÀNH PHẦN KIẾN TRÚC ORACLE DATABASE A-Z Oracle server là một hệ thống quản trị cơ sở dữ liệu đối tượng-quan hệ cho phép quản lý thông tin một cách toàn diện. Oracle server bao gồm ...
- Cài đặt Oracle Database 19c trên Oracle Linux 7 (OL7) bằng giao diện GUI hoặc bằng silent mode Bài viết này mô tả việc cài đặt Oracle Database 19c 64-bit trên Oracle Linux 7 (OL7) 64-bit bằng giao diện GUI hoặc bằng silent mode
- Quản lý Quyền trong Oracle Database Mục đích: Quản lý Quyền trong Oracle Database
- Hướng dẫn Download và cài đặt SecureCRT Giới thiệu phần mềm: VanDyke SecureCRT and SecureFX là một ứng dụng chuyển tập tin an toàn, linh hoạt với giao diện trực quan cung cấp tr...
- TOAD - Công cụ cho Oracle DBA TỐT NHẤT TOAD là công cụ cho Oracle DBA TỐT NHẤT với nhiều tính năng: - Quản trị trực quan các thành phần: Tablespace, Monitor, Tunning, tạo các ob...
- 🚀🚀🚀 KHÓA HỌC ONLINE COACHING "ORACLE DBA A-Z ENTERPRISE" (OAZ), HOTLINE 090.29.12.888 🚀🚀🚀 Trước đây ai có tiền là 'vua', nhưng bây giờ ' Data is King ', thực sự data (dữ liệu) được coi là "trái tim của doanh ...
- Oracle / PLSQL: Hàm SUBSTR Hướng dẫn này giải thích cách sử dụng hàm SUBSTR của Oracle P/SQL với cú pháp và ví dụ. Miêu tả Hàm SUBSTR của Oracle P/SQL cho phép bạn ...
- Hướng dẫn thi các chứng chỉ của Oracle Những người có chứng chỉ của Oracle hiện nay đã phổ biến hơn, mặc dù số lượng vẫn thấp hơn những chứng chỉ khác của CISCO hay MICROSOFT rất ...
- HỌC ORACLE DATABASE CƠ BẢN TỪ A-Z - BÀI 5: QUẢN TRỊ ORACLE DATABASE 5.1. PHÂN LOẠI USERS Oracle là một hệ quản trị cơ sở dữ liệu lớn, chạy trên môi trường mạng. Để vận hành hệ thống được tốt, có thể...
Blog
- ► 2025 (1004)
- ► 12 (2)
- ► 11 (54)
- ► 10 (159)
- ► 9 (435)
- ► 8 (162)
- ► 7 (51)
- ► 6 (3)
- ► 5 (23)
- ► 4 (2)
- ► 3 (56)
- ► 2 (38)
- ► 1 (19)
- ► 2024 (71)
- ► 12 (26)
- ► 11 (15)
- ► 9 (1)
- ► 8 (1)
- ► 6 (2)
- ► 5 (3)
- ► 4 (2)
- ► 3 (18)
- ► 1 (3)
- ► 2023 (715)
- ► 11 (2)
- ► 10 (26)
- ► 9 (9)
- ► 8 (48)
- ► 7 (499)
- ► 6 (52)
- ► 5 (6)
- ► 4 (14)
- ► 3 (18)
- ► 2 (21)
- ► 1 (20)
- ► 2022 (515)
- ► 12 (11)
- ► 11 (193)
- ► 10 (47)
- ► 9 (55)
- ► 8 (5)
- ► 7 (22)
- ► 6 (5)
- ► 5 (12)
- ► 4 (42)
- ► 3 (62)
- ► 2 (53)
- ► 1 (8)
- ► 2021 (353)
- ► 12 (3)
- ► 11 (22)
- ► 10 (23)
- ► 9 (48)
- ► 8 (28)
- ► 7 (17)
- ► 6 (18)
- ► 5 (40)
- ► 4 (28)
- ► 3 (22)
- ► 2 (26)
- ► 1 (78)
- ► 2019 (58)
- ► 12 (35)
- ► 11 (15)
- ► 10 (5)
- ► 6 (3)
- ► 2018 (42)
- ► 11 (2)
- ► 10 (1)
- ► 9 (11)
- ► 8 (27)
- ► 5 (1)
- ► 2017 (1)
- ► 4 (1)
Trần Văn Bình - Oracle Database Master
Từ khóa » Câu Lệnh Trong Sql Oracle
-
Hướng Dẫn Học SQL Cho Người Mới Bắt đầu Với Oracle
-
Tổng Hợp 30 Câu Truy Vấn Hữu ích Trong Oracle
-
Lệnh SELECT Trong Oracle
-
Các Câu Lệnh Command Oracle Database Thường Dùng - VinaSupport
-
Giao Trinh Oracle SQL Plsql Co Ban - SQL Và PL/SQL Cơ Bản MỤC ...
-
Quá Trình Xử Lý Câu Lệnh SQL Trong Oracle DB
-
Câu Lệnh Truy Vấn Oracle Docx - Tài Liệu - 123doc
-
SQL Và PL/SQL MỤC LỤC Phần Logic Trong Database
-
Tìm Các Câu Lệnh SQL Chạy Lâu, Chiếm IO, Chiếm Tài Nguyên Trong ...
-
Tối ưu-cau-lệnh-oracle-sql - SlideShare
-
45 Rất Hữu Ích Oracle Tóm Tắt Câu Lệnh Truy Vấn - MofunIT
-
Tổng Hợp Những Câu Lệnh SQL Cơ Bản - TopDev
-
Lệnh SELECT TOP Trong SQL
-
Toán Tử Trong SQL