Table of Contents
本篇文章讲解C语言调用mysql数据库的存储过程的方法
Home Database Mysql Tutorial C语言调用mysql的存储过程_MySQL

C语言调用mysql的存储过程_MySQL

Jun 01, 2016 pm 12:59 PM
language process

本篇文章讲解C语言调用mysql数据库的存储过程的方法

下面假设有一张sc表,保存学生选课记录,有课程号,学号,平时分,卷面分,总分。
建立数据库表过程:
create table class(
cno varchar(8) not null,
sno varchar(8) not null,
ordinary_score int,
last_score int,
all_score int
);

存储过程
由括号包围的参数列必须总是存在。如果没有参数,也该使用一个空参数列()。每个参数 默认都是一个IN参数。要指定为其它参数,可在参数名之前使用关键词IN(默认,可缺省) OUT或INOUT。
IN参数是只传入
OUT参数是只传出
INOUT参数是既传入又传入,即双向传递

指定参数为IN, OUT, 或INOUT 只对PROCEDURE是合法的。(FUNCTION参数总是被认为是IN参数)

建立存储过程,传入平时分x,卷面分y,平时分所占的比率pert,学号,课程号;建立过程如下

<code class="hljs oxygene">delimiter //
CREATE PROCEDURE cal_grade(x INT,y INT,out t int,pert float,s VARCHAR(8),c VARCHAR(8))
LABEL_PROC:
BEGIN


  IF ( x < 0 || x > 100 ) THEN
      SET t = -1;
      LEAVE LABEL_PROC;
  END IF;


  IF ( y < 0 || y > 100 ) THEN 
      SET t = -2;
      LEAVE LABEL_PROC;
  END IF;


  SET t = ROUND( x*pert + y*(1-pert) );

  UPDATE sc SET ordinary_score=x,last_score=y WHERE sno=s AND cno=c AND tno=tn;

END LABEL_PROC //

delimiter ;
</code>
Copy after login

<strong>C语言调用</strong>

<code class="hljs oxygene"><code class="hljs perl">#include <stdio.h>
#include "mysql.h"
int main()
{
    MYSQL *my_connection;
    MYSQL_RES *res_ptr;
    MYSQL_ROW sqlrow;

    char buf[100];

    my_connection = mysql_init (NULL);
    //下面连接的最后一个参数必须为CLIENT_MULTI_STATEMENTS,不然就会报错select error: PROCEDURE  *** can&rsquo;t return a result set in the given context
    my_connection = mysql_real_connect (my_connection, "localhost", "root", "root", "test", 0, NULL, CLIENT_MULTI_STATEMENTS);

    sprintf (buf, "call cal_grade(%d,%d,@t,%f,%s,%s)", 10, 10, 0.3, 123, 456);

    if ( mysql_query (my_connection, buf) )
        sprintf (stderr, mysql_error (my_connection));
    else
    {
        //获得返回参数@t,@t是传出参数
        mysql_query (my_connection, "select @t");
        res_ptr = mysql_store_result (my_connection);
        if (res_ptr)
        {
           sqlrow = mysql_fetch_row (res_ptr);

           if (!strcmp (sqlrow[0], "-1"))
               printf ("平时分不在范围之内\n");
           else if (!strcmp (sqlrow[0], "-2"))
               printf ("卷面分不在范围之内\n");
           else
               printf ("总分为:%s\n", sqlrow[0]);
        }
        mysql_free_result (res_ptr);
    }
    mysql_close (my_connection);

    return 0;
}</stdio.h></code></code>
Copy after login
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to Completely Remove Unwanted Display Languages ​​on Windows 11 How to Completely Remove Unwanted Display Languages ​​on Windows 11 Sep 24, 2023 pm 04:25 PM

Work on the same setup for too long or share your PC with others. You may have some language packs installed, which often create conflicts. So, it’s time to remove unwanted display languages ​​in Windows 11. Speaking of conflicts, when there are multiple language packs, inadvertently pressing Ctrl+Shift changes the keyboard layout. If not taken care of, this can be a hindrance to the task at hand. So, let’s jump right into the method! How to remove display language from Windows 11? 1. From Settings press + to open the Settings app, go to Time & Language from the navigation pane and click on Language & Region. WindowsI click the ellipsis next to the display language you want to remove and select Remove from the pop-up menu. Click "

3 Ways to Change Language on iPhone 3 Ways to Change Language on iPhone Feb 02, 2024 pm 04:12 PM

It's no secret that the iPhone is one of the most user-friendly electronic gadgets, and one of the reasons why is that it can be easily personalized to your liking. In Personalization, you can change the language to a different language than the one you selected when setting up your iPhone. If you're familiar with multiple languages, or your iPhone's language setting is wrong, you can change it as we explain below. How to Change the Language of iPhone [3 Methods] iOS allows users to freely switch the preferred language on iPhone to adapt to different needs. You can change the language of interaction with Siri to facilitate communication with the voice assistant. At the same time, when using the local keyboard, you can easily switch between multiple languages ​​to improve input efficiency.

Adding comprehensive audio-visual capabilities to large language models, DAMO Academy opens source Video-LLaMA Adding comprehensive audio-visual capabilities to large language models, DAMO Academy opens source Video-LLaMA Jun 09, 2023 pm 09:28 PM

Video plays an increasingly important role in today's social media and Internet culture. Douyin, Kuaishou, Bilibili, etc. have become popular platforms for hundreds of millions of users. Users share their life moments, creative works, interesting moments and other content around videos to interact and communicate with others. Recently, large language models have demonstrated impressive capabilities. Can we equip large models with "eyes" and "ears" so that they can understand videos and interact with users? Starting from this problem, researchers from DAMO Academy proposed Video-LLaMA, a large model with comprehensive audio-visual capabilities. Video-LLaMA can perceive and understand the video and audio signals in the video, and can understand the instructions input by the user to complete a series of complex tasks based on audio and video,

How to set the language of Win10 computer to Chinese? How to set the language of Win10 computer to Chinese? Jan 05, 2024 pm 06:51 PM

Sometimes we just install the computer system and find that the system is in English. In this case, we need to change the computer language to Chinese. So how to change the computer language to Chinese in the win10 system? Now Give you specific operation methods. How to change the computer language in win10 to Chinese 1. Turn on the computer and click the start button in the lower left corner. 2. Click the settings option on the left. 3. Select "Time and Language" on the page that opens. 4. After opening, click "Language" on the left. 5. Here you can set the computer language you want.

What a noise! Does ChatGPT understand the language? PNAS: Let's first study what 'understanding” is What a noise! Does ChatGPT understand the language? PNAS: Let's first study what 'understanding” is Apr 07, 2023 pm 06:21 PM

Asking whether a machine can think about it is like asking whether a submarine can swim. ——Dijkstra Even before the release of ChatGPT, the industry had already smelled the changes brought about by large models. On October 14 last year, professors Melanie Mitchell and David C. Krakauer of the Santa Fe Institute published a review on arXiv, comprehensively investigating all aspects of "whether large-scale pre-trained language models can understand language." Relevant debates, the article describes the "pro" and "con" arguments, as well as the key issues in the broader intelligence science derived from these arguments. Paper link: https://arxiv.o

Exploring the boundaries of agents: AgentQuest, a modular benchmark framework for comprehensively measuring and improving the performance of large language model agents Exploring the boundaries of agents: AgentQuest, a modular benchmark framework for comprehensively measuring and improving the performance of large language model agents Apr 11, 2024 pm 08:52 PM

Based on the continuous optimization of large models, LLM agents - these powerful algorithmic entities have shown the potential to solve complex multi-step reasoning tasks. From natural language processing to deep learning, LLM agents are gradually becoming the focus of research and industry. They can not only understand and generate human language, but also formulate strategies, perform tasks in diverse environments, and even use API calls and coding to Build solutions. In this context, the introduction of the AgentQuest framework is a milestone. It not only provides a modular benchmarking platform for the evaluation and advancement of LLM agents, but also provides researchers with a Powerful tools to track and improve the performance of these agents at a more granular level

You can play Genshin Impact just by moving your mouth! Use AI to switch characters and attack enemies. Netizen: 'Ayaka, use Kamiri-ryu Frost Destruction' You can play Genshin Impact just by moving your mouth! Use AI to switch characters and attack enemies. Netizen: 'Ayaka, use Kamiri-ryu Frost Destruction' May 13, 2023 pm 07:52 PM

When it comes to domestic games that have become popular all over the world in the past two years, Genshin Impact definitely takes the cake. According to this year’s Q1 quarter mobile game revenue survey report released in May, “Genshin Impact” firmly won the first place among card-drawing mobile games with an absolute advantage of 567 million U.S. dollars. This also announced that “Genshin Impact” has been online in just 18 years. A few months later, total revenue from the mobile platform alone exceeded US$3 billion (approximately RM13 billion). Now, the last 2.8 island version before the opening of Xumi is long overdue. After a long draft period, there are finally new plots and areas to play. But I don’t know how many “Liver Emperors” there are. Now that the island has been fully explored, grass has begun to grow again. There are a total of 182 treasure chests + 1 Mora box (not included). There is no need to worry about the long grass period. The Genshin Impact area is never short of work. No, during the long grass

How to change the language display of vivox60pro vivox60pro system language setting method How to change the language display of vivox60pro vivox60pro system language setting method Mar 23, 2024 am 09:06 AM

1. Click [System Management] in the phone settings menu. 2. Click the [Language] option. 3. Select the system language you want to use.

See all articles