検索
ホームページデータベースmysql チュートリアルOracle存储过程根据指定日期返回(N个)工作日的时间

一直都没写过Oracle的存储过程,今天突然来了一个需求:计算指定日期的前N个工作日或者后N个工作日日期(去除周末,法定节假日无

一直都没写过Oracle的存储过程,,今天突然来了一个需求:计算指定日期的前N个工作日或者后N个工作日日期(去除周末,法定节假日无法计算),然后研究了一下 Oracle的时间函数和循环方法。具体实现方法如下,也没啥难的,对数据库没研究过,也不知道下面的写法效率怎么样。

或者有没有更好的写法。o(︶︿︶)o 唉!

create or replace procedure proc_CalculationWorkDate
(
  plan_date in date,--登录日期
  flag in number,--1 往前日期,0往后日期
  date_number in number,--天数
  out_date out date--计算出的日期
)
is
  dayOfWeek number:=0;--星期的数字
  dates number:=date_number;--往前或者往后的天数(包含工作日的)初始化给他等于天数
  i int:=0;
  j int:=0;
begin
  if flag=1 then--计算往前日期
      while i        SELECT to_number(to_char(sysdate+i+j,'D')) into dayOfWeek  FROM DUAL;--返回星期代表的数值
        if dayOfWeek=1 or dayOfWeek=7 then --周六 周日
          dates:=dates+1;
          i:=i;
          j:=j+1;
        else
          i:=i+1;
        end if;
      end loop;
      select plan_date+dates into out_date from dual;
      --DBMS_OUTPUT.PUT_LINE(dates);
  end if;
  if flag=0 then --计算往后日期
      while i        SELECT to_number(to_char(sysdate-i-j,'D')) into dayOfWeek  FROM DUAL;
        if dayOfWeek=1 or dayOfWeek=7 then
          dates:=dates+1;
          i:=i;
          j:=j+1;
        else
          i:=i+1;
        end if;
      end loop;
      select plan_date-dates into out_date from dual;
      --DBMS_OUTPUT.PUT_LINE(dates);
  end if;
end;

本文永久更新链接地址

声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
MySQL:文字列データ型で使用可能な文字セットは何ですか?MySQL:文字列データ型で使用可能な文字セットは何ですか?May 10, 2025 am 12:07 AM

mysqloffersvariouscharactersetsetStringDatatypes:1)latin1forwesterneuropeanlanguages、2)utf8formultilingualsupport、3)utf8mb4f orextendedunicodeincludingemojis、4)ucs2forfixed-widthencoding、and5)asciiforbasiclatin.choososingtherightsetensuresdategrity

MySQL:ブロブのストリーミングはそれらを保存するよりも優れていますか?MySQL:ブロブのストリーミングはそれらを保存するよりも優れていますか?May 10, 2025 am 12:06 AM

ストリーミングブロブは、メモリの使用量を削減し、パフォーマンスを向上させるため、実際に直接ストレージよりも優れています。 1)ファイルを徐々に読み取り、処理することにより、データベースの膨満感とパフォーマンスの劣化は回避されます。 2)ストリーミングには、より複雑なコードロジックが必要であり、I/O操作の数が増加する場合があります。

MySQL文字列タイプ:ストレージ、パフォーマンス、ベストプラクティスMySQL文字列タイプ:ストレージ、パフォーマンス、ベストプラクティスMay 10, 2025 am 12:02 AM

mysqlstringTypesimpactStorageandperformanceAseasfollows:1)churisfixed-regents、whuscanbasterbutlessspace-efficient.2)varcharisvariaible、morespace-efficient-butpotentiallyslower.3)Textisforgergetext、storedoutext、

MySQL文字列タイプの理解:Varchar、Text、CharなどMySQL文字列タイプの理解:Varchar、Text、CharなどMay 10, 2025 am 12:02 AM

mysqlstringTypesincludevarchar、テキスト、char、列挙、およびセット。1)varcharisSatileforvariaible-lengthstringsuptoaspoecifedlimit.2)TextisidealforLargetExtStorageWithDeinLength.3)charispixed-consinterconsistentalikodes.4)

MySQLの文字列データ型は何ですか?MySQLの文字列データ型は何ですか?May 10, 2025 am 12:01 AM

mysqloffersvariousstringdatatypes:1)charfixed-lengthstrings、2)varcharforvariable-lengthtext、3)binaryandvartyforbinarydata、4)blobandtextforlargedata、and5)enumandsetforControlledinput.

新しいMySQLユーザーに権限を付与する方法新しいMySQLユーザーに権限を付与する方法May 09, 2025 am 12:16 AM

tograntpermissionstonewmysqlusers、フォローステープ:1)Accessmysqlasauserwithsufthiveerprivileges、2)createanewuser withthecreateusercommand、3)usethegrantcommandtospecifypermissionsionsionsionsionsionsionsionsionsionsionselect、挿入、挿入、挿入、更新、4)

MySQLにユーザーを追加する方法:ステップバイステップガイドMySQLにユーザーを追加する方法:ステップバイステップガイドMay 09, 2025 am 12:14 AM

toadduusersinmysqucrectivally andcurally、soflowthesteps:1)usethecreateuserstatementtoaddanewuser、指定するhostandastrongpassword.2)補助金を使用して、補助金を使用して、補助すること、

MySQL:複雑な権限を持つ新しいユーザーの追加MySQL:複雑な権限を持つ新しいユーザーの追加May 09, 2025 am 12:09 AM

toaddanewuserwithpermissionsinmysql、followthesesteps:1)createtheuserwithcreateuser'newuser '@' localhost'identifiedifiedifiedifiedby'pa ssword ';。2)grantreadacestoalltablesin'mydatabase'withgrantselectonmydatabase.to'newuser'@'localhost';。3)grantwriteaccessto '

See all articles

ホットAIツール

Undresser.AI Undress

Undresser.AI Undress

リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover

AI Clothes Remover

写真から衣服を削除するオンライン AI ツール。

Undress AI Tool

Undress AI Tool

脱衣画像を無料で

Clothoff.io

Clothoff.io

AI衣類リムーバー

Video Face Swap

Video Face Swap

完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

ホットツール

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Eclipse を SAP NetWeaver アプリケーション サーバーと統合します。

メモ帳++7.3.1

メモ帳++7.3.1

使いやすく無料のコードエディター

EditPlus 中国語クラック版

EditPlus 中国語クラック版

サイズが小さく、構文の強調表示、コード プロンプト機能はサポートされていません

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

このプロジェクトは osdn.net/projects/mingw に移行中です。引き続きそこでフォローしていただけます。 MinGW: GNU Compiler Collection (GCC) のネイティブ Windows ポートであり、ネイティブ Windows アプリケーションを構築するための自由に配布可能なインポート ライブラリとヘッダー ファイルであり、C99 機能をサポートする MSVC ランタイムの拡張機能が含まれています。すべての MinGW ソフトウェアは 64 ビット Windows プラットフォームで実行できます。

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

強力な PHP 統合開発環境