简单存储过程实例:P_GCELL_PEAK_ZTE

本文介绍了一个Oracle PL/SQL过程,用于批量处理指定日期的数据记录。该过程首先检查源表是否存在相关记录,如果存在,则进一步抽取每个基站ID在指定日期的最大忙时业务信道(TCH)流量和补充数据业务(SD)流量,并将这些数据汇总到临时表中。
CREATE OR REPLACE PROCEDURE P_GCELL_PEAK_ZTE(I_RECDATE IN VARCHAR) AS
V_EXIST INT;
V_RECDATE DATE := TO_DATE(I_RECDATE, 'YYYY-MM-DD');

MY_BREAK EXCEPTION;

BEGIN
SELECT COUNT(1)
INTO V_EXIST
FROM A_BASIC_CS_RADIO_H
WHERE COLLECTTIME BETWEEN V_RECDATE AND V_RECDATE + 23 / 24;
IF V_EXIST = 0 THEN
RAISE MY_BREAK;
ELSE
DBMS_OUTPUT.PUT_LINE('A_BASIC_CS_RADIO_H 记录:' || V_EXIST);
END IF;

EXECUTE IMMEDIATE 'TRUNCATE TABLE GCELL_PEAK_TEMPZTETCH';
INSERT INTO GCELL_PEAK_TEMPZTETCH
SELECT BSCID, SITEID, BTSID, COLLECTTIME, TRAFFIC_TCH
FROM (SELECT BSCID,
SITEID,
BTSID,
COLLECTTIME,
(C100030127 + C100030129) / 3600 TRAFFIC_TCH,
ROW_NUMBER() OVER(PARTITION BY BSCID, SITEID, BTSID ORDER BY(C100030127 + C100030129) DESC) RN
FROM A_BASIC_CS_RADIO_H
WHERE COLLECTTIME BETWEEN V_RECDATE AND V_RECDATE + 23 / 24)
WHERE RN = 1;
COMMIT;
SELECT COUNT(1) INTO V_EXIST FROM GCELL_PEAK_TEMPZTETCH;
DBMS_OUTPUT.PUT_LINE('GCELL_PEAK_TEMPZTETCH TCH忙时已经汇总:' || V_EXIST);

EXECUTE IMMEDIATE 'TRUNCATE TABLE GCELL_PEAK_TEMPZTESD';
INSERT INTO GCELL_PEAK_TEMPZTESD
SELECT BSCID, SITEID, BTSID, COLLECTTIME, TRAFFIC_SD
FROM (SELECT BSCID,
SITEID,
BTSID,
COLLECTTIME,
C100030124 / 3600 TRAFFIC_SD,
ROW_NUMBER() OVER(PARTITION BY BSCID, SITEID, BTSID ORDER BY C100030124 DESC) RN
FROM A_BASIC_CS_RADIO_H
WHERE COLLECTTIME BETWEEN V_RECDATE AND V_RECDATE + 23 / 24)
WHERE RN = 1;
COMMIT;
SELECT COUNT(1) INTO V_EXIST FROM GCELL_PEAK_TEMPZTESD;
DBMS_OUTPUT.PUT_LINE('GCELL_PEAK_TEMPZTESD SD忙时已经汇总:' || V_EXIST);

EXCEPTION
WHEN MY_BREAK THEN
DBMS_OUTPUT.PUT_LINE('A_BASIC_CS_RADIO_H 没有记录');
END;
潮汐研究作为海洋科学的关键分支,融合了物理海洋学、地理信息系统及水利工程等多领域知识。TMD2.05.zip是一套基于MATLAB环境开发的潮汐专用分析工具集,为科研人员与工程实践者提供系统化的潮汐建模与计算支持。该工具箱通过模块化设计实现了两大核心功能: 在交互界面设计方面,工具箱构建了图形化操作环境,有效降低了非专业用户的操作门槛。通过预设参数输入模块(涵盖地理坐标、时间序列、测站数据等),用户可自主配置模型运行条件。界面集成数据加载、参数调整、可视化呈现及流程控制等标准化组件,将复杂的数值运算过程转化为可交互的操作流程。 在潮汐预测模块中,工具箱整合了谐波分解法与潮流要素解析法等数学模型。这些算法能够解构潮汐观测数据,识别关键影响要素(包括K1、O1、M2等核心分潮),并生成不同时间尺度的潮汐预报。基于这些模型,研究者可精准推算特定海域的潮位变化周期与振幅特征,为海洋工程建设、港湾规划设计及海洋生态研究提供定量依据。 该工具集在实践中的应用方向包括: - **潮汐动力解析**:通过多站点观测数据比对,揭示区域主导潮汐成分的时空分布规律 - **数值模型构建**:基于历史观测序列建立潮汐动力学模型,实现潮汐现象的数字化重构与预测 - **工程影响量化**:在海岸开发项目中评估人工构筑物对自然潮汐节律的扰动效应 - **极端事件模拟**:建立风暴潮与天文潮耦合模型,提升海洋灾害预警的时空精度 工具箱以"TMD"为主程序包,内含完整的函数库与示例脚本。用户部署后可通过MATLAB平台调用相关模块,参照技术文档完成全流程操作。这套工具集将专业计算能力与人性化操作界面有机结合,形成了从数据输入到成果输出的完整研究链条,显著提升了潮汐研究的工程适用性与科研效率。 资源来源于网络分享,仅用于学习交流使用,请勿用于商业,如有侵权请联系我删除!
def get_source_id(source): if source == 'digikey': source_id = 1 elif source == 'mouser': source_id = 2 elif source == 'siemens': source_id = 3 elif source == 'bom2buy': source_id = 4 elif source == 'datasheet5': source_id = 5 elif source == 'semiee': source_id = 6 elif source == 'youganw': source_id = 7 elif source == 'arrow': source_id = 8 elif source == 'utmel': source_id = 9 elif source == 'lcsc': source_id = 10 elif source == 'findic': source_id = 11 elif source == 'hqonline': source_id = 12 elif source == 'kynix': source_id = 13 elif source == 'newark': source_id = 14 elif source == 'rsonline_us': source_id = 15 elif source in ['avnet', 'avnet_other']: source_id = 16 elif source == 'avnet_us': source_id = 17 elif source == 'avnet_apac': source_id = 18 elif source == 'avnet_jp': source_id = 19 elif source == 'dbearings': source_id = 20 elif source == 'locateballbearings': source_id = 21 elif source == 'bearingwholesalelots': source_id = 22 elif source == 'bearingdepot': source_id = 23 elif source == 'mrosupply': source_id = 24 elif source == 'abf_store': source_id = 25 elif source == 'y-ic': source_id = 26 elif source == 'icminer': source_id = 27 elif source == 'digchip': source_id = 28 elif source == 'octopart': source_id = 29 elif source == 'element14': source_id = 30 elif source == 'futureelectronics': source_id = 31 elif source == 'utsource': source_id = 32 elif source == 'verical': source_id = 33 elif source == 'worldwayelec': source_id = 34 elif source == 'findchips': source_id = 35 elif source == 'grainger': source_id = 36 elif source == 'gordonelectricsupply': source_id = 37 elif source == 'nexinstrument': source_id = 38 elif source == 'rexelusa': source_id = 39 elif source == 'norgren': source_id = 40 elif source == 'instrumart': source_id = 41 elif source == 'directindustry': source_id = 42 elif source == 'automationdirect': source_id = 43 elif source == 'rockwellautomation': source_id = 44 elif source == 'penntoolco': source_id = 167 elif source == 'tools': source_id = 166 elif source == 'allindustrial': source_id = 165 elif source == 'secotools': source_id = 164 elif source == 'ferguson': source_id = 163 elif source == 'sandvik': source_id = 162 elif source == 'globalspec': source_id = 161 elif source == 'keyence': source_id = 160 elif source == 'automationcontrolandproject': source_id = 159 elif source == 'szlcsc': source_id = 158 elif source == 'tradeindia': source_id = 157 elif source == 'pbtech': source_id = 156 elif source == 'tecisoft': source_id = 155 elif source == 'industrystock': source_id = 154 elif source == 'startech-bd': source_id = 153 elif source == 'startech': source_id = 152 elif source == 'mtech-services': source_id = 151 elif source == 'platinum-international': source_id = 150 elif source == 'im-tek': source_id = 149 elif source == 'endress': source_id = 148 elif source == 'distrelec': source_id = 147 elif source == 'router-switch': source_id = 146 elif source == 'omadanetworks': source_id = 145 elif source == 'tektronix': source_id = 144 elif source == 'fluke': source_id = 143 elif source == 'ittbiw': source_id = 142 elif source == 'ittaerospace': source_id = 141 elif source == 'rutronik24': source_id = 140 elif source == 'beckhoff': source_id = 139 elif source == 'phoenixcontact': source_id = 138 elif source == 'omron': source_id = 137 elif source == 'made-in-china': source_id = 136 elif source == 'cdr': source_id = 135 elif source == 'zte': source_id = 134 elif source == 'huawei': source_id = 133 elif source == 'zoro': source_id = 132 elif source == '3m': source_id = 131 elif source == 'schmersal': source_id = 130 elif source == 'quicktimeonline': source_id = 129 elif source == 'thomasnet': source_id = 128 elif source == 'factory/ti': source_id = 127 elif source == 'factory/nxp': source_id = 126 elif source == 'factory/estore.st': source_id = 125 elif source == 'factory/infineon': source_id = 124 elif source == 'factory/microchip': source_id = 123 elif source == 'factory/analog': source_id = 122 elif source == 'factory/allsensors': source_id = 121 elif source == 'factory/aukcokr': source_id = 120 elif source == 'factory/bhfuse': source_id = 119 elif source == 'factory/schaeffler': source_id = 118 elif source == 'factory/nsk': source_id = 117 elif source == 'factory/smwiko_bearing': source_id = 116 elif source == 'factory/ntn-snr': source_id = 115 elif source == 'factory/skf': source_id = 114 elif source == 'factory/chipsea': source_id = 113 elif source == 'factory/pctransformer': source_id = 112 elif source == 'factory/minicircuits': source_id = 111 elif source == 'factory/sdicmicro': source_id = 110 elif source == 'factory/alder': source_id = 109 elif source == 'factory/antaira': source_id = 108 elif source == 'factory/apro_tw': source_id = 107 elif source == 'factory/aptchip': source_id = 106 elif source == 'factory/canopus_hk': source_id = 105 elif source == 'factory/cap-xx': source_id = 104 elif source == 'factory/ce_bridge': source_id = 103 elif source == 'factory/cldkj': source_id = 102 elif source == 'factory/cnbbj': source_id = 101 elif source == 'factory/cresemi': source_id = 100 elif source == 'factory/cschip': source_id = 99 elif source == 'factory/figaro': source_id = 98 elif source == 'factory/firstohm': source_id = 97 elif source == 'factory/gigadevice': source_id = 96 elif source == 'factory/gjsemi': source_id = 95 elif source == 'factory/hanrun': source_id = 94 elif source == 'factory/hdgcconn': source_id = 93 elif source == 'factory/hinodedenki': source_id = 92 elif source == 'factory/hisense': source_id = 91 elif source == 'factory/hlwdz': source_id = 90 elif source == 'factory/honor-ic': source_id = 89 elif source == 'factory/hyecap': source_id = 88 elif source == 'factory/ilshin': source_id = 87 elif source == 'factory/jbcapacitors': source_id = 86 elif source == 'factory/kimtigo': source_id = 85 elif source == 'factory/kodenshi': source_id = 84 elif source == 'factory/ktsemi': source_id = 83 elif source == 'factory/led': source_id = 82 elif source == 'factory/macromatic': source_id = 81 elif source == 'factory/megatron': source_id = 80 elif source == 'factory/mgpower': source_id = 79 elif source == 'factory/novatel': source_id = 78 elif source == 'factory/onewave': source_id = 77 elif source == 'factory/prolightopto': source_id = 76 elif source == 'factory/sanan_ic': source_id = 75 elif source == 'factory/samwinsemi': source_id = 74 elif source == 'factory/sepa_europe': source_id = 73 elif source == 'factory/siansemi': source_id = 72 elif source == 'factory/silicontra': source_id = 71 elif source == 'factory/slsemicon': source_id = 70 elif source == 'factory/sunitec-cn': source_id = 69 elif source == 'factory/supersemi': source_id = 68 elif source == 'factory/tonver': source_id = 67 elif source == 'factory/visystems': source_id = 66 elif source == 'factory/wcmagnetics': source_id = 65 elif source == 'factory/diodes': source_id = 64 elif source == 'factory/onsemi': source_id = 63 elif source == 'factory/panasonic_industry': source_id = 62 elif source == 'factory/qualcomm': source_id = 61 elif source == 'factory/silabs': source_id = 60 elif source == 'factory/renesas': source_id = 59 elif source == 'factory/tdk': source_id = 58 elif source == 'factory/te': source_id = 57 elif source == 'factory/vishay': source_id = 56 elif source == 'factory/littelfuse': source_id = 55 elif source == 'factory/molex': source_id = 54 elif source == 'factory/murata': source_id = 53 elif source == 'factory/nexperia': source_id = 52 elif source == 'factory/nvidia': source_id = 51 elif source == 'factory/honeywell': source_id = 50 elif source == 'factory/intel': source_id = 49 elif source == 'factory/kemet': source_id = 48 elif source == 'factory/kyocera': source_id = 47 elif source == 'factory/bourns': source_id = 46 elif source == 'factory/powertechcontrols': source_id = 45 else: source_id = 0 return source_id 将以上方法转化为key为source_id,value为source的字典
09-24
你可以将 `get_source_id` 函数中所有的映射关系反转,构建一个以 `source_id` 为键、`source` 为值的字典。以下是转换后的代码实现: ```python # 原函数逻辑转换为字典:key 是 source_id,value 是 source source_to_id = { 'digikey': 1, 'mouser': 2, 'siemens': 3, 'bom2buy': 4, 'datasheet5': 5, 'semiee': 6, 'youganw': 7, 'arrow': 8, 'utmel': 9, 'lcsc': 10, 'findic': 11, 'hqonline': 12, 'kynix': 13, 'newark': 14, 'rsonline_us': 15, 'avnet': 16, 'avnet_other': 16, 'avnet_us': 17, 'avnet_apac': 18, 'avnet_jp': 19, 'dbearings': 20, 'locateballbearings': 21, 'bearingwholesalelots': 22, 'bearingdepot': 23, 'mrosupply': 24, 'abf_store': 25, 'y-ic': 26, 'icminer': 27, 'digchip': 28, 'octopart': 29, 'element14': 30, 'futureelectronics': 31, 'utsource': 32, 'verical': 33, 'worldwayelec': 34, 'findchips': 35, 'grainger': 36, 'gordonelectricsupply': 37, 'nexinstrument': 38, 'rexelusa': 39, 'norgren': 40, 'instrumart': 41, 'directindustry': 42, 'automationdirect': 43, 'rockwellautomation': 44, 'penntoolco': 167, 'tools': 166, 'allindustrial': 165, 'secotools': 164, 'ferguson': 163, 'sandvik': 162, 'globalspec': 161, 'keyence': 160, 'automationcontrolandproject': 159, 'szlcsc': 158, 'tradeindia': 157, 'pbtech': 156, 'tecisoft': 155, 'industrystock': 154, 'startech-bd': 153, 'startech': 152, 'mtech-services': 151, 'platinum-international': 150, 'im-tek': 149, 'endress': 148, 'distrelec': 147, 'router-switch': 146, 'omadanetworks': 145, 'tektronix': 144, 'fluke': 143, 'ittbiw': 142, 'ittaerospace': 141, 'rutronik24': 140, 'beckhoff': 139, 'phoenixcontact': 138, 'omron': 137, 'made-in-china': 136, 'cdr': 135, 'zte': 134, 'huawei': 133, 'zoro': 132, '3m': 131, 'schmersal': 130, 'quicktimeonline': 129, 'thomasnet': 128, 'factory/ti': 127, 'factory/nxp': 126, 'factory/estore.st': 125, 'factory/infineon': 124, 'factory/microchip': 123, 'factory/analog': 122, 'factory/allsensors': 121, 'factory/aukcokr': 120, 'factory/bhfuse': 119, 'factory/schaeffler': 118, 'factory/nsk': 117, 'factory/smwiko_bearing': 116, 'factory/ntn-snr': 115, 'factory/skf': 114, 'factory/chipsea': 113, 'factory/pctransformer': 112, 'factory/minicircuits': 111, 'factory/sdicmicro': 110, 'factory/alder': 109, 'factory/antaira': 108, 'factory/apro_tw': 107, 'factory/aptchip': 106, 'factory/canopus_hk': 105, 'factory/cap-xx': 104, 'factory/ce_bridge': 103, 'factory/cldkj': 102, 'factory/cnbbj': 101, 'factory/cresemi': 100, 'factory/cschip': 99, 'factory/figaro': 98, 'factory/firstohm': 97, 'factory/gigadevice': 96, 'factory/gjsemi': 95, 'factory/hanrun': 94, 'factory/hdgcconn': 93, 'factory/hinodedenki': 92, 'factory/hisense': 91, 'factory/hlwdz': 90, 'factory/honor-ic': 89, 'factory/hyecap': 88, 'factory/ilshin': 87, 'factory/jbcapacitors': 86, 'factory/kimtigo': 85, 'factory/kodenshi': 84, 'factory/ktsemi': 83, 'factory/led': 82, 'factory/macromatic': 81, 'factory/megatron': 80, 'factory/mgpower': 79, 'factory/novatel': 78, 'factory/onewave': 77, 'factory/prolightopto': 76, 'factory/sanan_ic': 75, 'factory/samwinsemi': 74, 'factory/sepa_europe': 73, 'factory/siansemi': 72, 'factory/silicontra': 71, 'factory/slsemicon': 70, 'factory/sunitec-cn': 69, 'factory/supersemi': 68, 'factory/tonver': 67, 'factory/visystems': 66, 'factory/wcmagnetics': 65, 'factory/diodes': 64, 'factory/onsemi': 63, 'factory/panasonic_industry': 62, 'factory/qualcomm': 61, 'factory/silabs': 60, 'factory/renesas': 59, 'factory/tdk': 58, 'factory/te': 57, 'factory/vishay': 56, 'factory/littelfuse': 55, 'factory/molex': 54, 'factory/murata': 53, 'factory/nexperia': 52, 'factory/nvidia': 51, 'factory/honeywell': 50, 'factory/intel': 49, 'factory/kemet': 48, 'factory/kyocera': 47, 'factory/bourns': 46, 'factory/powertechcontrols': 45 } # 反转字典:source_id -> source id_to_source = {v: k for k, v in source_to_id.items()} # 处理特殊情况:'avnet', 'avnet_other' 都映射到 16,但只保留一个即可(比如保留 'avnet') # 如果你想明确指定某个 key 作为代表,可以手动覆盖: # 例如,我们选择保留 'avnet' 而不是 'avnet_other' # 上面的 dict comprehension 中会自动取最后一个,所以需要确保顺序 # 更稳妥的做法是先处理多对一的情况 id_to_source = {} for source, source_id in source_to_id.items(): # 如果该 source_id 还没被设置,则设置;或者你希望优先使用某个名称如 'avnet' 而非 'avnet_other' if source_id not in id_to_source: id_to_source[source_id] = source # 最终结果 print(id_to_source) ``` ### 解释: 1. **原函数** 是通过 `if-elif` 判断将 `source` 字符串映射为整数 `source_id`。 2. 我们首先创建了一个名为 `source_to_id` 的字典来保存原始映射。 3. 然后使用字典推导 `{v: k for k, v in source_to_id.items()}` 实现反转。 4. 注意:`'avnet'` 和 `'avnet_other'` 映射同一个 ID(16),因此在反转时只能保留一个。Python 字典推导按插入顺序覆盖,最后出现的会保留。为了可控性,我们采用遍历方式,仅保留第一个或根据业务选择主键。 5. 示例中使用“首次出现”策略避免冲突,也可以自定义优先级。 --- ### 最终生成的 `id_to_source` 示例片段: ```python { 1: 'digikey', 2: 'mouser', 3: 'siemens', ... 16: 'avnet', # 因为 'avnet' 在 'avnet_other' 前面 17: 'avnet_us', ... } ``` 如果你希望更清晰地控制多对一的情况(比如强制用 `'avnet'` 代表 ID=16),可以在构建前做规范化: ```python # 规范化 source 名称(可选) def normalize_source(source): if source.startswith('avnet'): return 'avnet' return source source_to_id_normalized = { normalize_source(k): v for k, v in source_to_id.items() } id_to_source = {v: k for k, v in source_to_id_normalized.items()} ``` 这样能统一多个变体。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值