ITPub博客

首页 > 数据库 > Oracle > [20250511]建立完善s2h.sql脚本.txt

[20250511]建立完善s2h.sql脚本.txt

原创 Oracle 作者:lfree 时间:2024-05-18 21:14:55 0 删除 编辑

[20250511]建立完善s2h.sql脚本.txt

--//写过一个sql_id 计算hash_value的bash shell脚本,实际上oracle使用dbms_utility.SQLID_TO_SQLHASH就可以实现,

$ cat s2h.sql
-- Copyright 2023 lfree. All rights reserved.
-- Licensed under the Apache License, Version 2.0. See LICENSE.txt for terms and conditions.
----------------------------------------------------------------------------------------------
--
-- Name:        s2h.sql
-- Purpose:     display Sql_id of Hash_value
--
-- Author:      lfree
-- Usage:
--     @ s2h <sql_id>
--
-----------------------------------------------------------------------------------------------
column sql_id format a13
column hash_value format 9999999999

select '&1' sql_id,dbms_utility.SQLID_TO_SQLHASH('&1') hash_value FROM DUAL;

--//简单验证:
SCOTT@test01p> select count(*) from dept;
  COUNT(*)
----------
         4

SCOTT@test01p> @ hash
HASH_VALUE SQL_ID        CHILD_NUMBER KGL_BUCKET PLAN_HASH_VALUE HASH_HEX   SQL_EXEC_START      SQL_EXEC_ID
---------- ------------- ------------ ---------- --------------- ---------- ------------------- -----------
 761178024 1jrz3ucqpx9x8            0      42920      3051237957  2d5ea7a8  2024-05-18 21:10:09    16777223

SCOTT@test01p> @ s2h 1jrz3ucqpx9x8
SQL_ID        HASH_VALUE
------------- ----------
1jrz3ucqpx9x8  761178024

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/267265/viewspace-3015885/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
熟悉oracle相关技术,擅长sql优化,rman备份与恢复,熟悉linux shell编程。

注册时间:2008-01-03

  • 博文量
    4006
  • 访问量
    7969578